optimized checks

This commit is contained in:
Leijurv 2018-09-22 09:17:28 -07:00
parent 15fa12fe08
commit c508fb2cb7
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 37 additions and 20 deletions

View File

@ -158,7 +158,7 @@ public abstract class Movement implements Helper, MovementHelper {
return true; return true;
} }
boolean somethingInTheWay = false; boolean somethingInTheWay = false;
for (BlockPos blockPos : positionsToBreak) { for (BetterBlockPos blockPos : positionsToBreak) {
if (!MovementHelper.canWalkThrough(blockPos)) { if (!MovementHelper.canWalkThrough(blockPos)) {
somethingInTheWay = true; somethingInTheWay = true;
Optional<Rotation> reachable = LookBehaviorUtils.reachable(blockPos); Optional<Rotation> reachable = LookBehaviorUtils.reachable(blockPos);
@ -309,7 +309,7 @@ public abstract class Movement implements Helper, MovementHelper {
return toBreakCached; return toBreakCached;
} }
List<BlockPos> result = new ArrayList<>(); List<BlockPos> result = new ArrayList<>();
for (BlockPos positionToBreak : positionsToBreak) { for (BetterBlockPos positionToBreak : positionsToBreak) {
if (!MovementHelper.canWalkThrough(positionToBreak)) { if (!MovementHelper.canWalkThrough(positionToBreak)) {
result.add(positionToBreak); result.add(positionToBreak);
} }

View File

@ -68,11 +68,15 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param pos * @param pos
* @return * @return
*/ */
static boolean canWalkThrough(BlockPos pos) { static boolean canWalkThrough(BetterBlockPos pos) {
return canWalkThrough(pos, BlockStateInterface.get(pos)); return canWalkThrough(pos.x, pos.y, pos.z, BlockStateInterface.get(pos));
} }
static boolean canWalkThrough(BlockPos pos, IBlockState state) { static boolean canWalkThrough(BetterBlockPos pos, IBlockState state) {
return canWalkThrough(pos.x, pos.y, pos.z, state);
}
static boolean canWalkThrough(int x, int y, int z, IBlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block == Blocks.AIR) { if (block == Blocks.AIR) {
return true; return true;
@ -86,14 +90,23 @@ public interface MovementHelper extends ActionCosts, Helper {
// be opened by just interacting. // be opened by just interacting.
return block != Blocks.IRON_DOOR; return block != Blocks.IRON_DOOR;
} }
if (block instanceof BlockSnow || block instanceof BlockTrapDoor) { boolean snow = block instanceof BlockSnow;
// we've already checked doors boolean trapdoor = block instanceof BlockTrapDoor;
// so the only remaining dynamic isPassables are snow, fence gate, and trapdoor if (snow || trapdoor) {
// we've already checked doors and fence gates
// so the only remaining dynamic isPassables are snow and trapdoor
// if they're cached as a top block, we don't know their metadata // if they're cached as a top block, we don't know their metadata
// default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible) // default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible)
if (mc.world.getChunk(pos) instanceof EmptyChunk) { if (mc.world.getChunk(x >> 4, z >> 4) instanceof EmptyChunk) {
return true; return true;
} }
if (snow) {
return state.getValue(BlockSnow.LAYERS) < 5; // see BlockSnow.isPassable
}
if (trapdoor) {
return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
}
throw new IllegalStateException();
} }
if (BlockStateInterface.isFlowing(state)) { if (BlockStateInterface.isFlowing(state)) {
return false; // Don't walk through flowing liquids return false; // Don't walk through flowing liquids
@ -102,13 +115,16 @@ public interface MovementHelper extends ActionCosts, Helper {
if (Baritone.settings().assumeWalkOnWater.get()) { if (Baritone.settings().assumeWalkOnWater.get()) {
return false; return false;
} }
IBlockState up = BlockStateInterface.get(pos.up()); IBlockState up = BlockStateInterface.get(x, y + 1, z);
if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) {
return false; return false;
} }
return block == Blocks.WATER || block == Blocks.FLOWING_WATER; return block == Blocks.WATER || block == Blocks.FLOWING_WATER;
} }
return block.isPassable(mc.world, pos); // only blocks that can get here and actually that use world and pos for this call are snow and trapdoor // every block that overrides isPassable with anything more complicated than a "return true;" or "return false;"
// has already been accounted for above
// therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null
return block.isPassable(null, null);
} }
/** /**
@ -118,10 +134,10 @@ public interface MovementHelper extends ActionCosts, Helper {
* @return * @return
*/ */
static boolean fullyPassable(BlockPos pos) { static boolean fullyPassable(BlockPos pos) {
return fullyPassable(pos, BlockStateInterface.get(pos)); return fullyPassable(BlockStateInterface.get(pos));
} }
static boolean fullyPassable(BlockPos pos, IBlockState state) { static boolean fullyPassable(IBlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block == Blocks.AIR) { if (block == Blocks.AIR) {
return true; return true;
@ -140,7 +156,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|| block instanceof BlockEndPortal) { || block instanceof BlockEndPortal) {
return false; return false;
} }
return block.isPassable(mc.world, pos); // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
return block.isPassable(null, null);
} }
static boolean isReplacable(BlockPos pos, IBlockState state) { static boolean isReplacable(BlockPos pos, IBlockState state) {
@ -289,12 +306,12 @@ public interface MovementHelper extends ActionCosts, Helper {
return state.isBlockNormalCube(); return state.isBlockNormalCube();
} }
static double getMiningDurationTicks(CalculationContext context, BlockPos position, boolean includeFalling) { static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, boolean includeFalling) {
IBlockState state = BlockStateInterface.get(position); IBlockState state = BlockStateInterface.get(position);
return getMiningDurationTicks(context, position, state, includeFalling); return getMiningDurationTicks(context, position, state, includeFalling);
} }
static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state, boolean includeFalling) { static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, IBlockState state, boolean includeFalling) {
Block block = state.getBlock(); Block block = state.getBlock();
if (!canWalkThrough(position, state)) { if (!canWalkThrough(position, state)) {
if (!context.allowBreak()) { if (!context.allowBreak()) {
@ -311,7 +328,7 @@ public interface MovementHelper extends ActionCosts, Helper {
double result = m / strVsBlock; double result = m / strVsBlock;
if (includeFalling) { if (includeFalling) {
BlockPos up = position.up(); BetterBlockPos up = position.up();
IBlockState above = BlockStateInterface.get(up); IBlockState above = BlockStateInterface.get(up);
if (above.getBlock() instanceof BlockFalling) { if (above.getBlock() instanceof BlockFalling) {
result += getMiningDurationTicks(context, up, above, true); result += getMiningDurationTicks(context, up, above, true);

View File

@ -202,9 +202,9 @@ public class MovementAscend extends Movement {
} }
private boolean headBonkClear() { private boolean headBonkClear() {
BlockPos startUp = src.up(2); BetterBlockPos startUp = src.up(2);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
BlockPos check = startUp.offset(EnumFacing.byHorizontalIndex(i)); BetterBlockPos check = startUp.offset(EnumFacing.byHorizontalIndex(i));
if (!MovementHelper.canWalkThrough(check)) { if (!MovementHelper.canWalkThrough(check)) {
// We might bonk our head // We might bonk our head
return false; return false;

View File

@ -69,7 +69,7 @@ public class MovementPillar extends Movement {
return COST_INF; return COST_INF;
} }
} }
BlockPos toBreakPos = src.up(2); BetterBlockPos toBreakPos = src.up(2);
IBlockState toBreak = BlockStateInterface.get(toBreakPos); IBlockState toBreak = BlockStateInterface.get(toBreakPos);
Block toBreakBlock = toBreak.getBlock(); Block toBreakBlock = toBreak.getBlock();
if (toBreakBlock instanceof BlockFenceGate) { if (toBreakBlock instanceof BlockFenceGate) {