Awesome
This commit is contained in:
@@ -44,33 +44,27 @@ import net.minecraft.world.chunk.EmptyChunk;
|
||||
*/
|
||||
public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static boolean avoidBreaking(CalculationContext context, int x, int y, int z, IBlockState state) {
|
||||
static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||
Block b = state.getBlock();
|
||||
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
||||
|| b instanceof BlockSilverfish // obvious reasons
|
||||
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
||||
|| context.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side
|
||||
|| context.get(x + 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| context.get(x - 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| context.get(x, y, z + 1).getBlock() instanceof BlockLiquid
|
||||
|| context.get(x, y, z - 1).getBlock() instanceof BlockLiquid;
|
||||
|| bsi.get0(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side
|
||||
|| bsi.get0(x + 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| bsi.get0(x - 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| bsi.get0(x, y, z + 1).getBlock() instanceof BlockLiquid
|
||||
|| bsi.get0(x, y, z - 1).getBlock() instanceof BlockLiquid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I walk through this block? e.g. air, saplings, torches, etc
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
*/
|
||||
static boolean canWalkThrough(BetterBlockPos pos) {
|
||||
return canWalkThrough(new CalculationContext(Baritone.INSTANCE), pos.x, pos.y, pos.z, BlockStateInterface.get(pos));
|
||||
static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) {
|
||||
return canWalkThrough(new BlockStateInterface(ctx), pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
static boolean canWalkThrough(CalculationContext context, int x, int y, int z) {
|
||||
return canWalkThrough(context, x, y, z, context.get(x, y, z));
|
||||
static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z) {
|
||||
return canWalkThrough(bsi, x, y, z, bsi.get0(x, y, z));
|
||||
}
|
||||
|
||||
static boolean canWalkThrough(CalculationContext context, int x, int y, int z, IBlockState state) {
|
||||
static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.AIR) { // early return for most common case
|
||||
return true;
|
||||
@@ -111,7 +105,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (Baritone.settings().assumeWalkOnWater.get()) {
|
||||
return false;
|
||||
}
|
||||
IBlockState up = context.get(x, y + 1, z);
|
||||
IBlockState up = bsi.get0(x, y + 1, z);
|
||||
if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) {
|
||||
return false;
|
||||
}
|
||||
@@ -182,12 +176,12 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return state.getMaterial().isReplaceable();
|
||||
}
|
||||
|
||||
static boolean isDoorPassable(BlockPos doorPos, BlockPos playerPos) {
|
||||
static boolean isDoorPassable(IPlayerContext ctx, BlockPos doorPos, BlockPos playerPos) {
|
||||
if (playerPos.equals(doorPos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState state = BlockStateInterface.get(doorPos);
|
||||
IBlockState state = BlockStateInterface.get(ctx, doorPos);
|
||||
if (!(state.getBlock() instanceof BlockDoor)) {
|
||||
return true;
|
||||
}
|
||||
@@ -195,12 +189,12 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
|
||||
}
|
||||
|
||||
static boolean isGatePassable(BlockPos gatePos, BlockPos playerPos) {
|
||||
static boolean isGatePassable(IPlayerContext ctx, BlockPos gatePos, BlockPos playerPos) {
|
||||
if (playerPos.equals(gatePos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState state = BlockStateInterface.get(gatePos);
|
||||
IBlockState state = BlockStateInterface.get(ctx, gatePos);
|
||||
if (!(state.getBlock() instanceof BlockFenceGate)) {
|
||||
return true;
|
||||
}
|
||||
@@ -245,7 +239,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static boolean canWalkOn(CalculationContext context, int x, int y, int z, IBlockState state) {
|
||||
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
||||
// early return for most common case (air)
|
||||
@@ -267,7 +261,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (isWater(block)) {
|
||||
// since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()"
|
||||
// BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability
|
||||
Block up = context.get(x, y + 1, z).getBlock();
|
||||
Block up = bsi.get0(x, y + 1, z).getBlock();
|
||||
if (up == Blocks.WATERLILY) {
|
||||
return true;
|
||||
}
|
||||
@@ -294,24 +288,28 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return block instanceof BlockStairs;
|
||||
}
|
||||
|
||||
static boolean canWalkOn(BetterBlockPos pos, IBlockState state) {
|
||||
return canWalkOn(new CalculationContext(Baritone.INSTANCE), pos.x, pos.y, pos.z, state);
|
||||
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos, IBlockState state) {
|
||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state);
|
||||
}
|
||||
|
||||
static boolean canWalkOn(BetterBlockPos pos) {
|
||||
return canWalkOn(new CalculationContext(Baritone.INSTANCE), pos.x, pos.y, pos.z, BlockStateInterface.get(pos));
|
||||
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) {
|
||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
static boolean canWalkOn(CalculationContext context, int x, int y, int z) {
|
||||
return canWalkOn(context, x, y, z, context.get(x, y, z));
|
||||
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z) {
|
||||
return canWalkOn(bsi, x, y, z, bsi.get0(x, y, z));
|
||||
}
|
||||
|
||||
static boolean canPlaceAgainst(CalculationContext context, int x, int y, int z) {
|
||||
return canPlaceAgainst(context.get(x, y, z));
|
||||
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z) {
|
||||
return canPlaceAgainst(bsi.get0(x, y, z));
|
||||
}
|
||||
|
||||
static boolean canPlaceAgainst(BlockPos pos) {
|
||||
return canPlaceAgainst(BlockStateInterface.get(pos));
|
||||
static boolean canPlaceAgainst(BlockStateInterface bsi, BlockPos pos) {
|
||||
return canPlaceAgainst(bsi.get0(pos.getX(), pos.getY(), pos.getZ()));
|
||||
}
|
||||
|
||||
static boolean canPlaceAgainst(IPlayerContext ctx, BlockPos pos) {
|
||||
return canPlaceAgainst(new BlockStateInterface(ctx), pos);
|
||||
}
|
||||
|
||||
static boolean canPlaceAgainst(IBlockState state) {
|
||||
@@ -325,11 +323,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
||||
Block block = state.getBlock();
|
||||
if (!canWalkThrough(context, x, y, z, state)) {
|
||||
if (!canWalkThrough(context.bsi(), x, y, z, state)) {
|
||||
if (!context.canBreakAt(x, y, z)) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (avoidBreaking(context, x, y, z, state)) {
|
||||
if (avoidBreaking(context.bsi(), x, y, z, state)) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (block instanceof BlockLiquid) {
|
||||
@@ -440,11 +438,12 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
* Returns whether or not the block at the specified pos is
|
||||
* water, regardless of whether or not it is flowing.
|
||||
*
|
||||
* @param ctx The player context
|
||||
* @param bp The block pos
|
||||
* @return Whether or not the block is water
|
||||
*/
|
||||
static boolean isWater(BlockPos bp) {
|
||||
return isWater(BlockStateInterface.getBlock(bp));
|
||||
static boolean isWater(IPlayerContext ctx, BlockPos bp) {
|
||||
return isWater(BlockStateInterface.getBlock(ctx, bp));
|
||||
}
|
||||
|
||||
static boolean isLava(Block b) {
|
||||
@@ -454,11 +453,12 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
/**
|
||||
* Returns whether or not the specified pos has a liquid
|
||||
*
|
||||
* @param ctx The player context
|
||||
* @param p The pos
|
||||
* @return Whether or not the block is a liquid
|
||||
*/
|
||||
static boolean isLiquid(BlockPos p) {
|
||||
return BlockStateInterface.getBlock(p) instanceof BlockLiquid;
|
||||
static boolean isLiquid(IPlayerContext ctx, BlockPos p) {
|
||||
return BlockStateInterface.getBlock(ctx, p) instanceof BlockLiquid;
|
||||
}
|
||||
|
||||
static boolean isFlowing(IBlockState state) {
|
||||
|
||||
Reference in New Issue
Block a user