diff --git a/src/api/java/baritone/api/utils/IPlayerContext.java b/src/api/java/baritone/api/utils/IPlayerContext.java index b886c063a..470e1378c 100644 --- a/src/api/java/baritone/api/utils/IPlayerContext.java +++ b/src/api/java/baritone/api/utils/IPlayerContext.java @@ -17,6 +17,7 @@ package baritone.api.utils; +import baritone.api.cache.IWorldData; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.util.math.Vec3d; @@ -34,6 +35,8 @@ public interface IPlayerContext { World world(); + IWorldData worldData(); + BetterBlockPos playerFeet(); default Vec3d playerFeetAsVec() { diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index f5ea8a32d..2fa085ae7 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -120,7 +120,7 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior, H @Override public void onBlockInteract(BlockInteractEvent event) { - if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(event.getPos()) instanceof BlockBed) { + if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BlockBed) { baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos())); } } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 1d2533adf..7cba8d587 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -339,7 +339,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, */ public BlockPos pathStart() { BetterBlockPos feet = ctx.playerFeet(); - if (!MovementHelper.canWalkOn(feet.down())) { + if (!MovementHelper.canWalkOn(ctx, feet.down())) { if (ctx.player().onGround) { double playerX = ctx.player().posX; double playerZ = ctx.player().posZ; @@ -358,7 +358,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, // can't possibly be sneaking off of this one, we're too far away continue; } - if (MovementHelper.canWalkOn(possibleSupport.down()) && MovementHelper.canWalkThrough(possibleSupport) && MovementHelper.canWalkThrough(possibleSupport.up())) { + if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) { // this is plausible logDebug("Faking path start assuming player is standing off the edge of a block"); return possibleSupport; @@ -368,7 +368,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } else { // !onGround // we're in the middle of a jump - if (MovementHelper.canWalkOn(feet.down().down())) { + if (MovementHelper.canWalkOn(ctx, feet.down().down())) { logDebug("Faking path start assuming player is midair and falling"); return feet.down(); } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index e379d27be..2a6b88006 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -115,7 +115,7 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { public MovementStatus update() { ctx.player().capabilities.isFlying = false; currentState = updateState(currentState); - if (MovementHelper.isLiquid(ctx.playerFeet())) { + if (MovementHelper.isLiquid(ctx, ctx.playerFeet())) { currentState.setInput(Input.JUMP, true); } if (ctx.player().isEntityInsideOpaqueBlock()) { @@ -150,11 +150,11 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { } boolean somethingInTheWay = false; for (BetterBlockPos blockPos : positionsToBreak) { - if (!MovementHelper.canWalkThrough(blockPos) && !(BlockStateInterface.getBlock(blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try + if (!MovementHelper.canWalkThrough(ctx, blockPos) && !(BlockStateInterface.getBlock(ctx, blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try somethingInTheWay = true; Optional reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance()); if (reachable.isPresent()) { - MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(blockPos)); + MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos)); state.setTarget(new MovementState.MovementTarget(reachable.get(), true)); if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), blockPos)) { state.setInput(Input.CLICK_LEFT, true); @@ -254,7 +254,7 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { } List result = new ArrayList<>(); for (BetterBlockPos positionToBreak : positionsToBreak) { - if (!MovementHelper.canWalkThrough(positionToBreak)) { + if (!MovementHelper.canWalkThrough(ctx, positionToBreak)) { result.add(positionToBreak); } } @@ -268,7 +268,7 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { return toPlaceCached; } List result = new ArrayList<>(); - if (positionToPlace != null && !MovementHelper.canWalkOn(positionToPlace)) { + if (positionToPlace != null && !MovementHelper.canWalkOn(ctx, positionToPlace)) { result.add(positionToPlace); } toPlaceCached = result; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index c27de97a7..a715ff9f4 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -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) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 37897b539..5321e22e6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -72,7 +72,7 @@ public class MovementAscend extends Movement { return COST_INF;// the only thing we can ascend onto from a bottom slab is another bottom slab } boolean hasToPlace = false; - if (!MovementHelper.canWalkOn(context, destX, y, destZ, toPlace)) { + if (!MovementHelper.canWalkOn(context.bsi(), destX, y, destZ, toPlace)) { if (!context.canPlaceThrowawayAt(destX, y, destZ)) { return COST_INF; } @@ -88,7 +88,7 @@ public class MovementAscend extends Movement { if (againstX == x && againstZ == z) { continue; } - if (MovementHelper.canPlaceAgainst(context, againstX, y, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y, againstZ)) { hasToPlace = true; break; } @@ -98,7 +98,7 @@ public class MovementAscend extends Movement { } } IBlockState srcUp2 = null; - if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context, x, y + 1, z) || !((srcUp2 = context.get(x, y + 2, z)).getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us + if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi(), x, y + 1, z) || !((srcUp2 = context.get(x, y + 2, z)).getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us // HOWEVER, we assume that we're standing in the start position // that means that src and src.up(1) are both air // maybe they aren't now, but they will be by the time this starts @@ -166,14 +166,14 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.SUCCESS); } - IBlockState jumpingOnto = BlockStateInterface.get(positionToPlace); - if (!MovementHelper.canWalkOn(positionToPlace, jumpingOnto)) { + IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace); + if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) { for (int i = 0; i < 4; i++) { BlockPos anAgainst = positionToPlace.offset(HORIZONTALS[i]); if (anAgainst.equals(src)) { continue; } - if (MovementHelper.canPlaceAgainst(anAgainst)) { + if (MovementHelper.canPlaceAgainst(ctx, anAgainst)) { if (!MovementHelper.throwaway(ctx, true)) {//get ready to place a throwaway block return state.setStatus(MovementStatus.UNREACHABLE); } @@ -205,7 +205,7 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(ctx, state, dest); - if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(src.down()))) { + if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) { return state; // don't jump while walking from a non double slab into a bottom slab } @@ -236,7 +236,7 @@ public class MovementAscend extends Movement { BetterBlockPos startUp = src.up(2); for (int i = 0; i < 4; i++) { BetterBlockPos check = startUp.offset(EnumFacing.byHorizontalIndex(i)); - if (!MovementHelper.canWalkThrough(check)) { + if (!MovementHelper.canWalkThrough(ctx, check)) { // We might bonk our head return false; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 22e8dbeef..05c140e4f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -89,7 +89,7 @@ public class MovementDescend extends Movement { //C, D, etc determine the length of the fall IBlockState below = context.get(destX, y - 2, destZ); - if (!MovementHelper.canWalkOn(context, destX, y - 2, destZ, below)) { + if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 2, destZ, below)) { dynamicFallCost(context, x, y, z, destX, destZ, totalCost, below, res); return; } @@ -118,7 +118,7 @@ public class MovementDescend extends Movement { // and potentially replace the water we're going to fall into return; } - if (!MovementHelper.canWalkThrough(context, destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) { + if (!MovementHelper.canWalkThrough(context.bsi(), destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) { return; } for (int fallHeight = 3; true; fallHeight++) { @@ -146,10 +146,10 @@ public class MovementDescend extends Movement { if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) { return; } - if (MovementHelper.canWalkThrough(context, destX, newY, destZ, ontoBlock)) { + if (MovementHelper.canWalkThrough(context.bsi(), destX, newY, destZ, ontoBlock)) { continue; } - if (!MovementHelper.canWalkOn(context, destX, newY, destZ, ontoBlock)) { + if (!MovementHelper.canWalkOn(context.bsi(), destX, newY, destZ, ontoBlock)) { return; } if (MovementHelper.isBottomSlab(ontoBlock)) { @@ -183,7 +183,7 @@ public class MovementDescend extends Movement { } BlockPos playerFeet = ctx.playerFeet(); - if (playerFeet.equals(dest) && (MovementHelper.isLiquid(dest) || ctx.player().posY - playerFeet.getY() < 0.094)) { // lilypads + if (playerFeet.equals(dest) && (MovementHelper.isLiquid(ctx, dest) || ctx.player().posY - playerFeet.getY() < 0.094)) { // lilypads // Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately return state.setStatus(MovementStatus.SUCCESS); /* else { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 832bc00ad..4a098380f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -62,11 +62,11 @@ public class MovementDiagonal extends Movement { return COST_INF; } IBlockState destInto = context.get(destX, y, destZ); - if (!MovementHelper.canWalkThrough(context, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context, destX, y + 1, destZ)) { + if (!MovementHelper.canWalkThrough(context.bsi(), destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi(), destX, y + 1, destZ)) { return COST_INF; } IBlockState destWalkOn = context.get(destX, y - 1, destZ); - if (!MovementHelper.canWalkOn(context, destX, y - 1, destZ, destWalkOn)) { + if (!MovementHelper.canWalkOn(context.bsi(), destX, y - 1, destZ, destWalkOn)) { return COST_INF; } double multiplier = WALK_ONE_BLOCK_COST; @@ -145,7 +145,7 @@ public class MovementDiagonal extends Movement { state.setStatus(MovementStatus.SUCCESS); return state; } - if (!MovementHelper.isLiquid(ctx.playerFeet())) { + if (!MovementHelper.isLiquid(ctx, ctx.playerFeet())) { state.setInput(Input.SPRINT, true); } MovementHelper.moveTowards(ctx, state, dest); @@ -164,7 +164,7 @@ public class MovementDiagonal extends Movement { } List result = new ArrayList<>(); for (int i = 4; i < 6; i++) { - if (!MovementHelper.canWalkThrough(positionsToBreak[i])) { + if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) { result.add(positionsToBreak[i]); } } @@ -179,7 +179,7 @@ public class MovementDiagonal extends Movement { } List result = new ArrayList<>(); for (int i = 0; i < 4; i++) { - if (!MovementHelper.canWalkThrough(positionsToBreak[i])) { + if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) { result.add(positionsToBreak[i]); } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 49ca589e5..f18fc538f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -48,7 +48,7 @@ public class MovementDownward extends Movement { } public static double cost(CalculationContext context, int x, int y, int z) { - if (!MovementHelper.canWalkOn(context, x, y - 2, z)) { + if (!MovementHelper.canWalkOn(context.bsi(), x, y - 2, z)) { return COST_INF; } IBlockState d = context.get(x, y - 1, z); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index dc63e84ab..22e048f42 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -66,7 +66,7 @@ public class MovementFall extends Movement { BlockPos playerFeet = ctx.playerFeet(); Rotation targetRotation = null; - if (!MovementHelper.isWater(dest) && src.getY() - dest.getY() > Baritone.settings().maxFallHeightNoWater.get() && !playerFeet.equals(dest)) { + if (!MovementHelper.isWater(ctx, dest) && src.getY() - dest.getY() > Baritone.settings().maxFallHeightNoWater.get() && !playerFeet.equals(dest)) { if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().provider.isNether()) { return state.setStatus(MovementStatus.UNREACHABLE); } @@ -87,8 +87,8 @@ public class MovementFall extends Movement { } else { state.setTarget(new MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest)), false)); } - if (playerFeet.equals(dest) && (ctx.player().posY - playerFeet.getY() < 0.094 || MovementHelper.isWater(dest))) { // 0.094 because lilypads - if (MovementHelper.isWater(dest)) { + if (playerFeet.equals(dest) && (ctx.player().posY - playerFeet.getY() < 0.094 || MovementHelper.isWater(ctx, dest))) { // 0.094 because lilypads + if (MovementHelper.isWater(ctx, dest)) { if (InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) { ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY); if (ctx.player().motionY >= 0) { @@ -139,7 +139,7 @@ public class MovementFall extends Movement { // only break if one of the first three needs to be broken // specifically ignore the last one which might be water for (int i = 0; i < 4 && i < positionsToBreak.length; i++) { - if (!MovementHelper.canWalkThrough(positionsToBreak[i])) { + if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) { return super.prepared(state); } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 7d31ff5c0..d67e09299 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -78,20 +78,20 @@ public class MovementParkour extends Movement { if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks return; } - if (MovementHelper.canWalkOn(context,x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) + if (MovementHelper.canWalkOn(context.bsi(), x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) return; } - if (!MovementHelper.fullyPassable(context,x + xDiff, y, z + zDiff)) { + if (!MovementHelper.fullyPassable(context, x + xDiff, y, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(context,x + xDiff, y + 1, z + zDiff)) { + if (!MovementHelper.fullyPassable(context, x + xDiff, y + 1, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(context,x + xDiff, y + 2, z + zDiff)) { + if (!MovementHelper.fullyPassable(context, x + xDiff, y + 2, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(context,x, y + 2, z)) { + if (!MovementHelper.fullyPassable(context, x, y + 2, z)) { return; } int maxJump; @@ -107,11 +107,11 @@ public class MovementParkour extends Movement { for (int i = 2; i <= maxJump; i++) { // TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly? for (int y2 = 0; y2 < 4; y2++) { - if (!MovementHelper.fullyPassable(context,x + xDiff * i, y + y2, z + zDiff * i)) { + if (!MovementHelper.fullyPassable(context, x + xDiff * i, y + y2, z + zDiff * i)) { return; } } - if (MovementHelper.canWalkOn(context,x + xDiff * i, y - 1, z + zDiff * i)) { + if (MovementHelper.canWalkOn(context.bsi(), x + xDiff * i, y - 1, z + zDiff * i)) { res.x = x + xDiff * i; res.y = y; res.z = z + zDiff * i; @@ -144,7 +144,7 @@ public class MovementParkour extends Movement { if (againstX == x + xDiff * 3 && againstZ == z + zDiff * 3) { // we can't turn around that fast continue; } - if (MovementHelper.canPlaceAgainst(context,againstX, y - 1, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y - 1, againstZ)) { res.x = destX; res.y = y; res.z = destZ; @@ -201,7 +201,7 @@ public class MovementParkour extends Movement { } MovementHelper.moveTowards(ctx, state, dest); if (ctx.playerFeet().equals(dest)) { - Block d = BlockStateInterface.getBlock(dest); + Block d = BlockStateInterface.getBlock(ctx, dest); if (d == Blocks.VINE || d == Blocks.LADDER) { // it physically hurt me to add support for parkour jumping onto a vine // but i did it anyway @@ -213,14 +213,14 @@ public class MovementParkour extends Movement { } else if (!ctx.playerFeet().equals(src)) { if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - ctx.playerFeet().getY() > 0.0001) { - if (!MovementHelper.canWalkOn(dest.down()) && !ctx.player().onGround) { + if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround) { BlockPos positionToPlace = dest.down(); for (int i = 0; i < 5; i++) { BlockPos against1 = positionToPlace.offset(HORIZONTAL_AND_DOWN[i]); if (against1.up().equals(src.offset(direction, 3))) { // we can't turn around that fast continue; } - if (MovementHelper.canPlaceAgainst(against1)) { + if (MovementHelper.canPlaceAgainst(ctx, against1)) { if (!MovementHelper.throwaway(ctx, true)) {//get ready to place a throwaway block return state.setStatus(MovementStatus.UNREACHABLE); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 9339ad1a6..b2f254678 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -143,8 +143,8 @@ public class MovementPillar extends Movement { return state; } - IBlockState fromDown = BlockStateInterface.get(src); - if (MovementHelper.isWater(fromDown.getBlock()) && MovementHelper.isWater(dest)) { + IBlockState fromDown = BlockStateInterface.get(ctx, src); + if (MovementHelper.isWater(fromDown.getBlock()) && MovementHelper.isWater(ctx, dest)) { // stay centered while swimming up a water column state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest)), false)); Vec3d destCenter = VecUtils.getBlockPosCenter(dest); @@ -165,7 +165,7 @@ public class MovementPillar extends Movement { state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().rotationYaw, rotation.getPitch()), true)); } - boolean blockIsThere = MovementHelper.canWalkOn(src) || ladder; + boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder; if (ladder) { BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite()); if (against == null) { @@ -176,7 +176,7 @@ public class MovementPillar extends Movement { if (ctx.playerFeet().equals(against.up()) || ctx.playerFeet().equals(dest)) { return state.setStatus(MovementStatus.SUCCESS); } - if (MovementHelper.isBottomSlab(BlockStateInterface.get(src.down()))) { + if (MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) { state.setInput(Input.JUMP, true); } /* @@ -214,7 +214,7 @@ public class MovementPillar extends Movement { if (!blockIsThere) { - Block fr = BlockStateInterface.get(src).getBlock(); + Block fr = BlockStateInterface.get(ctx, src).getBlock(); if (!(fr instanceof BlockAir || fr.isReplaceable(ctx.world(), src))) { state.setInput(Input.CLICK_LEFT, true); blockIsThere = false; @@ -235,12 +235,12 @@ public class MovementPillar extends Movement { @Override protected boolean prepared(MovementState state) { if (ctx.playerFeet().equals(src) || ctx.playerFeet().equals(src.down())) { - Block block = BlockStateInterface.getBlock(src.down()); + Block block = BlockStateInterface.getBlock(ctx, src.down()); if (block == Blocks.LADDER || block == Blocks.VINE) { state.setInput(Input.SNEAK, true); } } - if (MovementHelper.isWater(dest.up())) { + if (MovementHelper.isWater(ctx, dest.up())) { return true; } return super.prepared(state); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 282513530..ef7a90698 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -64,7 +64,7 @@ public class MovementTraverse extends Movement { IBlockState pb1 = context.get(destX, y, destZ); IBlockState destOn = context.get(destX, y - 1, destZ); Block srcDown = context.getBlock(x, y - 1, z); - if (MovementHelper.canWalkOn(context, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge + if (MovementHelper.canWalkOn(context.bsi(), destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; boolean water = false; if (MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock())) { @@ -122,7 +122,7 @@ public class MovementTraverse extends Movement { if (againstX == x && againstZ == z) { continue; } - if (MovementHelper.canPlaceAgainst(context, againstX, y - 1, againstZ)) { + if (MovementHelper.canPlaceAgainst(context.bsi(), againstX, y - 1, againstZ)) { return WC + context.placeBlockCost() + hardness1 + hardness2; } } @@ -153,10 +153,10 @@ public class MovementTraverse extends Movement { return state; } // and if it's fine to walk into the blocks in front - if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(positionsToBreak[0]).getBlock())) { + if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[0]).getBlock())) { return state; } - if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(positionsToBreak[1]).getBlock())) { + if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[1]).getBlock())) { return state; } // and we aren't already pressed up against the block @@ -177,17 +177,17 @@ public class MovementTraverse extends Movement { //sneak may have been set to true in the PREPPING state while mining an adjacent block state.setInput(Input.SNEAK, false); - Block fd = BlockStateInterface.get(src.down()).getBlock(); + Block fd = BlockStateInterface.get(ctx, src.down()).getBlock(); boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine; - IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]); - IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]); + IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]); + IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]); boolean door = pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor; if (door) { boolean isDoorActuallyBlockingUs = false; - if (pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(src, dest)) { + if (pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, src, dest)) { isDoorActuallyBlockingUs = true; - } else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(dest, src)) { + } else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, dest, src)) { isDoorActuallyBlockingUs = true; } if (isDoorActuallyBlockingUs && !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) { @@ -198,9 +198,9 @@ public class MovementTraverse extends Movement { if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) { BlockPos blocked = null; - if (!MovementHelper.isGatePassable(positionsToBreak[0], src.up())) { + if (!MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up())) { blocked = positionsToBreak[0]; - } else if (!MovementHelper.isGatePassable(positionsToBreak[1], src)) { + } else if (!MovementHelper.isGatePassable(ctx, positionsToBreak[1], src)) { blocked = positionsToBreak[1]; } @@ -210,7 +210,7 @@ public class MovementTraverse extends Movement { } } - boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder; + boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder; BlockPos whereAmI = ctx.playerFeet(); if (whereAmI.getY() != dest.getY() && !ladder) { logDebug("Wrong Y coordinate"); @@ -224,10 +224,10 @@ public class MovementTraverse extends Movement { if (ctx.playerFeet().equals(dest)) { return state.setStatus(MovementStatus.SUCCESS); } - if (wasTheBridgeBlockAlwaysThere && !MovementHelper.isLiquid(ctx.playerFeet())) { + if (wasTheBridgeBlockAlwaysThere && !MovementHelper.isLiquid(ctx, ctx.playerFeet())) { state.setInput(Input.SPRINT, true); } - Block destDown = BlockStateInterface.get(dest.down()).getBlock(); + Block destDown = BlockStateInterface.get(ctx, dest.down()).getBlock(); if (whereAmI.getY() != dest.getY() && ladder && (destDown instanceof BlockVine || destDown instanceof BlockLadder)) { new MovementPillar(baritone, dest.down(), dest).updateState(state); // i'm sorry return state; @@ -242,7 +242,7 @@ public class MovementTraverse extends Movement { continue; } against1 = against1.down(); - if (MovementHelper.canPlaceAgainst(against1)) { + if (MovementHelper.canPlaceAgainst(ctx, against1)) { if (!MovementHelper.throwaway(ctx, true)) { // get ready to place a throwaway block logDebug("bb pls get me some blocks. dirt or cobble"); return state.setStatus(MovementStatus.UNREACHABLE); @@ -250,7 +250,7 @@ public class MovementTraverse extends Movement { if (!Baritone.settings().assumeSafeWalk.get()) { state.setInput(Input.SNEAK, true); } - Block standingOn = BlockStateInterface.get(ctx.playerFeet().down()).getBlock(); + Block standingOn = BlockStateInterface.get(ctx, ctx.playerFeet().down()).getBlock(); if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().posX), Math.abs(dest.getZ() + 0.5 - ctx.player().posZ)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon @@ -318,13 +318,13 @@ public class MovementTraverse extends Movement { // if we're in the process of breaking blocks before walking forwards // or if this isn't a sneak place (the block is already there) // then it's safe to cancel this - return state.getStatus() != MovementStatus.RUNNING || MovementHelper.canWalkOn(dest.down()); + return state.getStatus() != MovementStatus.RUNNING || MovementHelper.canWalkOn(ctx, dest.down()); } @Override protected boolean prepared(MovementState state) { if (ctx.playerFeet().equals(src) || ctx.playerFeet().equals(src.down())) { - Block block = BlockStateInterface.getBlock(src.down()); + Block block = BlockStateInterface.getBlock(ctx, src.down()); if (block == Blocks.LADDER || block == Blocks.VINE) { state.setInput(Input.SNEAK, true); } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 1950ebcd7..fadc2f21a 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -110,7 +110,7 @@ public class PathExecutor implements IPathExecutor, Helper { } //System.out.println("Should be at " + whereShouldIBe + " actually am at " + whereAmI); - if (!Blocks.AIR.equals(BlockStateInterface.getBlock(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip + if (!Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks if (whereAmI.equals(path.positions().get(i))) { logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i); @@ -303,11 +303,11 @@ public class PathExecutor implements IPathExecutor, Helper { if (!ctx.player().onGround) { return false; } - if (!MovementHelper.canWalkOn(ctx.playerFeet().down())) { + if (!MovementHelper.canWalkOn(ctx, ctx.playerFeet().down())) { // we're in some kind of sketchy situation, maybe parkouring return false; } - if (!MovementHelper.canWalkThrough(ctx.playerFeet()) || !MovementHelper.canWalkThrough(ctx.playerFeet().up())) { + if (!MovementHelper.canWalkThrough(ctx, ctx.playerFeet()) || !MovementHelper.canWalkThrough(ctx, ctx.playerFeet().up())) { // suffocating? return false; } @@ -384,7 +384,7 @@ public class PathExecutor implements IPathExecutor, Helper { BlockPos into = current.getDest().subtract(current.getSrc().down()).add(current.getDest()); for (int y = 0; y <= 2; y++) { // we could hit any of the three blocks - if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(into.up(y)))) { + if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(ctx, into.up(y)))) { logDebug("Sprinting would be unsafe"); ctx.player().setSprinting(false); return; @@ -402,7 +402,7 @@ public class PathExecutor implements IPathExecutor, Helper { logDebug("Skipping descend to straight ascend"); return; } - if (canSprintInto(current, next)) { + if (canSprintInto(ctx, current, next)) { if (ctx.playerFeet().equals(current.getDest())) { pathPosition++; onChangeInPathPosition(); @@ -430,11 +430,11 @@ public class PathExecutor implements IPathExecutor, Helper { ctx.player().setSprinting(false); } - private static boolean canSprintInto(IMovement current, IMovement next) { + private static boolean canSprintInto(IPlayerContext ctx, IMovement current, IMovement next) { if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { return true; } - if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(next.getDest().down())) { + if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(ctx, next.getDest().down())) { return true; } return next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.get(); diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 0a02a248e..5eefe6a92 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -97,6 +97,6 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } private void rescan(List known) { - knownLocations = MineProcess.searchWorld(baritone, Collections.singletonList(gettingTo), 64, known); + knownLocations = MineProcess.searchWorld(ctx, Collections.singletonList(gettingTo), 64, known); } } \ No newline at end of file diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 0aae73be3..60b36ea15 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -18,7 +18,6 @@ package baritone.process; import baritone.Baritone; -import baritone.api.IBaritone; import baritone.api.pathing.goals.*; import baritone.api.process.IMineProcess; import baritone.api.process.PathingCommand; @@ -27,13 +26,10 @@ import baritone.api.utils.IPlayerContext; import baritone.api.utils.RotationUtils; import baritone.cache.CachedChunk; import baritone.cache.ChunkPacker; -import baritone.cache.WorldProvider; import baritone.cache.WorldScanner; -import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; @@ -92,7 +88,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain List curr = new ArrayList<>(knownOreLocations); - baritone.getExecutor().execute(() -> rescan(curr)); + Baritone.getExecutor().execute(() -> rescan(curr)); } if (Baritone.settings().legitMine.get()) { addNearby(); @@ -120,9 +116,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro private Goal updateGoal() { List locs = knownOreLocations; if (!locs.isEmpty()) { - List locs2 = prune(baritone, new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT); + List locs2 = prune(ctx, new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT); // can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final - Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new)); + Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(ctx, loc, locs2)).toArray(Goal[]::new)); knownOreLocations = locs2; return goal; } @@ -162,7 +158,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro if (Baritone.settings().legitMine.get()) { return; } - List locs = searchWorld(baritone, mining, ORE_LOCATIONS_COUNT, already); + List locs = searchWorld(ctx, mining, ORE_LOCATIONS_COUNT, already); locs.addAll(droppedItemsScan(mining, ctx.world())); if (locs.isEmpty()) { logDebug("No locations for " + mining + " known, cancelling"); @@ -172,26 +168,15 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro knownOreLocations = locs; } - private static Goal coalesce(BlockPos loc, List locs) { + private static Goal coalesce(IPlayerContext ctx, BlockPos loc, List locs) { if (!Baritone.settings().forceInternalMining.get()) { return new GoalTwoBlocks(loc); } - boolean upwardGoal = locs.contains(loc.up()) || (Baritone.settings().internalMiningAirException.get() && BlockStateInterface.getBlock(loc.up()) == Blocks.AIR); - boolean downwardGoal = locs.contains(loc.down()) || (Baritone.settings().internalMiningAirException.get() && BlockStateInterface.getBlock(loc.up()) == Blocks.AIR); - if (upwardGoal) { - if (downwardGoal) { - return new GoalTwoBlocks(loc); - } else { - return new GoalBlock(loc); - } - } else { - if (downwardGoal) { - return new GoalBlock(loc.down()); - } else { - return new GoalTwoBlocks(loc); - } - } + // Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of) + boolean upwardGoal = locs.contains(loc.up()) || (Baritone.settings().internalMiningAirException.get() && BlockStateInterface.getBlock(ctx, loc.up()) == Blocks.AIR); + boolean downwardGoal = locs.contains(loc.down()) || (Baritone.settings().internalMiningAirException.get() && BlockStateInterface.getBlock(ctx, loc.down()) == Blocks.AIR); + return upwardGoal == downwardGoal ? new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : new GoalBlock(loc.down()); } public static List droppedItemsScan(List mining, World world) { @@ -220,15 +205,13 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro /*public static List searchWorld(List mining, int max, World world) { }*/ - public static List searchWorld(IBaritone baritone, List mining, int max, List alreadyKnown) { - IPlayerContext ctx = baritone.getPlayerContext(); - + public static List searchWorld(IPlayerContext ctx, List mining, int max, List alreadyKnown) { List locs = new ArrayList<>(); List uninteresting = new ArrayList<>(); //long b = System.currentTimeMillis(); for (Block m : mining) { if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) { - locs.addAll(baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 1)); + locs.addAll(ctx.worldData().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 1)); } else { uninteresting.add(m); } @@ -243,7 +226,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro //System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms"); } locs.addAll(alreadyKnown); - return prune(baritone, locs, mining, max); + return prune(ctx, locs, mining, max); } public void addNearby() { @@ -254,29 +237,28 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) { for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) { BlockPos pos = new BlockPos(x, y, z); - // crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught - if (mining.contains(BlockStateInterface.getBlock(pos)) && RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()).isPresent()) { + // crucial to only add blocks we can see because otherwise this + // is an x-ray and it'll get caught + if (mining.contains(BlockStateInterface.getBlock(ctx, pos)) && RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()).isPresent()) { knownOreLocations.add(pos); } } } } - knownOreLocations = prune(baritone, knownOreLocations, mining, ORE_LOCATIONS_COUNT); + knownOreLocations = prune(ctx, knownOreLocations, mining, ORE_LOCATIONS_COUNT); } - public static List prune(IBaritone baritone, List locs2, List mining, int max) { - IPlayerContext ctx = baritone.getPlayerContext(); - + public static List prune(IPlayerContext ctx, List locs2, List mining, int max) { List dropped = droppedItemsScan(mining, ctx.world()); List locs = locs2 .stream() .distinct() // remove any that are within loaded chunks that aren't actually what we want - .filter(pos -> ctx.world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock()) || dropped.contains(pos)) + .filter(pos -> ctx.world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.getBlock(ctx, pos)) || dropped.contains(pos)) // remove any that are implausible to mine (encased in bedrock, or touching lava) - .filter(pos -> MineProcess.plausibleToBreak(baritone, pos)) + .filter(pos -> MineProcess.plausibleToBreak(ctx, pos)) .sorted(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)) .collect(Collectors.toList()); @@ -287,12 +269,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return locs; } - public static boolean plausibleToBreak(IBaritone baritone, BlockPos pos) { - if (MovementHelper.avoidBreaking(new CalculationContext(baritone), pos.getX(), pos.getY(), pos.getZ(), BlockStateInterface.get(pos))) { + public static boolean plausibleToBreak(IPlayerContext ctx, BlockPos pos) { + if (MovementHelper.avoidBreaking(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ(), BlockStateInterface.get(ctx, pos))) { return false; } // bedrock above and below makes it implausible, otherwise we're good - return !(BlockStateInterface.getBlock(pos.up()) == Blocks.BEDROCK && BlockStateInterface.getBlock(pos.down()) == Blocks.BEDROCK); + return !(BlockStateInterface.getBlock(ctx, pos.up()) == Blocks.BEDROCK && BlockStateInterface.getBlock(ctx, pos.down()) == Blocks.BEDROCK); } @Override diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 9f9d3d8d0..e4e79867a 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -18,6 +18,8 @@ package baritone.utils; import baritone.Baritone; +import baritone.api.IBaritone; +import baritone.api.utils.IPlayerContext; import baritone.cache.CachedRegion; import baritone.cache.WorldData; import baritone.pathing.movement.CalculationContext; @@ -43,22 +45,26 @@ public class BlockStateInterface implements Helper { private static final IBlockState AIR = Blocks.AIR.getDefaultState(); + public BlockStateInterface(IPlayerContext ctx) { + this(ctx.world(), (WorldData) ctx.worldData()); + } + public BlockStateInterface(World world, WorldData worldData) { this.worldData = worldData; this.world = world; } - public static Block getBlock(BlockPos pos) { // won't be called from the pathing thread because the pathing thread doesn't make a single blockpos pog - return get(pos).getBlock(); + public static Block getBlock(IPlayerContext ctx, BlockPos pos) { // won't be called from the pathing thread because the pathing thread doesn't make a single blockpos pog + return get(ctx, pos).getBlock(); } - public static IBlockState get(BlockPos pos) { - return new CalculationContext(Baritone.INSTANCE).get(pos); // immense iq + public static IBlockState get(IPlayerContext ctx, BlockPos pos) { + return new BlockStateInterface(ctx).get0(pos.getX(), pos.getY(), pos.getZ()); // immense iq // can't just do world().get because that doesn't work for out of bounds // and toBreak and stuff fails when the movement is instantiated out of load range but it's not able to BlockStateInterface.get what it's going to walk on } - public IBlockState get0(int x, int y, int z) { + public IBlockState get0(int x, int y, int z) { // Mickey resigned // Invalid vertical position if (y < 0 || y >= 256) { diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 790b2375b..18e2f740f 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -303,7 +303,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { LinkedList locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4); logDirect("Have " + locs.size() + " locations"); for (BlockPos pos : locs) { - Block actually = BlockStateInterface.get(pos).getBlock(); + Block actually = BlockStateInterface.get(ctx, pos).getBlock(); if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) { System.out.println("Was looking for " + blockType + " but actually found " + actually + " " + ChunkPacker.blockToString(actually)); } diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index bf73149e3..61783bd1a 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -206,7 +206,7 @@ public final class PathRenderer implements Helper { double renderPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; double renderPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; positions.forEach(pos -> { - IBlockState state = BlockStateInterface.get(pos); + IBlockState state = BlockStateInterface.get(Baritone.INSTANCE.getPlayerContext(), pos); AxisAlignedBB toDraw; if (state.getBlock().equals(Blocks.AIR)) { toDraw = Blocks.DIRT.getDefaultState().getSelectedBoundingBox(Minecraft.getMinecraft().world, pos); diff --git a/src/main/java/baritone/utils/player/LocalPlayerContext.java b/src/main/java/baritone/utils/player/LocalPlayerContext.java index ea81f0ed8..c95689bf9 100644 --- a/src/main/java/baritone/utils/player/LocalPlayerContext.java +++ b/src/main/java/baritone/utils/player/LocalPlayerContext.java @@ -17,6 +17,8 @@ package baritone.utils.player; +import baritone.Baritone; +import baritone.api.cache.IWorldData; import baritone.api.utils.IPlayerContext; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; @@ -51,4 +53,9 @@ public final class LocalPlayerContext extends AbstractPlayerContext { public World world() { return mc.world; } + + @Override + public IWorldData worldData() { + return Baritone.INSTANCE.getWorldProvider().getCurrentWorld(); + } }