From e16bc5eca4dad52efbdf1367474f6d5bb41c3454 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 22 Sep 2018 08:47:02 -0700 Subject: [PATCH] more better block pos --- .../java/baritone/behavior/PathingBehavior.java | 3 ++- .../java/baritone/pathing/calc/AStarPathFinder.java | 1 - .../pathing/calc/AbstractNodeCostSearch.java | 2 +- .../java/baritone/pathing/movement/Movement.java | 8 ++++---- .../baritone/pathing/movement/MovementHelper.java | 13 ++++++++----- .../pathing/movement/movements/MovementAscend.java | 2 +- .../pathing/movement/movements/MovementDescend.java | 2 +- .../movement/movements/MovementDiagonal.java | 4 ++-- .../movement/movements/MovementDownward.java | 3 +-- .../pathing/movement/movements/MovementFall.java | 8 ++++---- .../pathing/movement/movements/MovementParkour.java | 7 ++++--- .../pathing/movement/movements/MovementPillar.java | 2 +- .../movement/movements/MovementTraverse.java | 2 +- .../java/baritone/utils/ExampleBaritoneControl.java | 6 ++++++ 14 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 98653b24..4a36ce73 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -35,6 +35,7 @@ import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.PathRenderer; import baritone.utils.interfaces.IGoalRenderPos; +import baritone.utils.pathing.BetterBlockPos; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; @@ -232,7 +233,7 @@ public final class PathingBehavior extends Behavior implements Helper { } public BlockPos pathStart() { - BlockPos feet = playerFeet(); + BetterBlockPos feet = playerFeet(); if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR) && MovementHelper.canWalkOn(feet.down().down())) { return feet.down(); } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index d9f3ba1a..8e5801df 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -240,7 +240,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST), new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST), new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST), - new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST), MovementParkour.generate(pos, EnumFacing.EAST, calcContext), diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index ee2d0e24..012c257c 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -55,7 +55,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { private volatile boolean isFinished; - protected volatile boolean cancelRequested; + protected boolean cancelRequested; /** * This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 3e0a2f62..4fbc17f0 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -48,12 +48,12 @@ public abstract class Movement implements Helper, MovementHelper { /** * The positions that need to be broken before this movement can ensue */ - protected final BlockPos[] positionsToBreak; + protected final BetterBlockPos[] positionsToBreak; /** * The position where we need to place a block before this movement can ensue */ - protected final BlockPos positionToPlace; + protected final BetterBlockPos positionToPlace; private boolean didBreakLastTick; @@ -65,14 +65,14 @@ public abstract class Movement implements Helper, MovementHelper { private Boolean calculatedWhileLoaded; - protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak, BlockPos toPlace) { + protected Movement(BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) { this.src = src; this.dest = dest; this.positionsToBreak = toBreak; this.positionToPlace = toPlace; } - protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) { + protected Movement(BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak) { this(src, dest, toBreak, null); } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 0ac4d7d8..421f3150 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -106,8 +106,9 @@ public interface MovementHelper extends ActionCosts, Helper { if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { return false; } + return block == Blocks.WATER || block == Blocks.FLOWING_WATER; } - return block.isPassable(mc.world, pos); + 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 } /** @@ -225,7 +226,7 @@ public interface MovementHelper extends ActionCosts, Helper { * * @return */ - static boolean canWalkOn(BlockPos pos, IBlockState state) { + static boolean canWalkOn(BetterBlockPos pos, IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR || block == Blocks.MAGMA) { return false; @@ -246,8 +247,10 @@ public interface MovementHelper extends ActionCosts, Helper { return true; } if (BlockStateInterface.isWater(block)) { - Block up = BlockStateInterface.get(pos.up()).getBlock(); - if (up instanceof BlockLilyPad) { + // 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 = BlockStateInterface.get(pos.x, pos.y + 1, pos.z).getBlock(); + if (up == Blocks.WATERLILY) { return true; } if (BlockStateInterface.isFlowing(state) || block == Blocks.FLOWING_WATER) { @@ -276,7 +279,7 @@ public interface MovementHelper extends ActionCosts, Helper { return false; } - static boolean canWalkOn(BlockPos pos) { + static boolean canWalkOn(BetterBlockPos pos) { return canWalkOn(pos, BlockStateInterface.get(pos)); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 6f666a71..745b8a89 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -44,7 +44,7 @@ public class MovementAscend extends Movement { private int ticksWithoutPlacement = 0; public MovementAscend(BetterBlockPos src, BetterBlockPos dest) { - super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down()); + super(src, dest, new BetterBlockPos[]{dest, src.up(2), dest.up()}, dest.down()); } @Override diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 27a3c96d..85f7f110 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -34,7 +34,7 @@ public class MovementDescend extends Movement { private int numTicks = 0; public MovementDescend(BetterBlockPos start, BetterBlockPos end) { - super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down()); + super(start, end, new BetterBlockPos[]{end.up(2), end.up(), end}, end.down()); } @Override diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 58ba2ae2..d092b66e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -48,7 +48,7 @@ public class MovementDiagonal extends Movement { } private MovementDiagonal(BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) { - super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); + super(start, end, new BetterBlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); } @Override @@ -60,7 +60,7 @@ public class MovementDiagonal extends Movement { if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) { return COST_INF; } - BlockPos destDown = dest.down(); + BetterBlockPos destDown = dest.down(); IBlockState destWalkOn = BlockStateInterface.get(destDown); if (!MovementHelper.canWalkOn(destDown, destWalkOn)) { return COST_INF; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index aa5df237..b265ddd7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -26,14 +26,13 @@ import baritone.utils.pathing.BetterBlockPos; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; public class MovementDownward extends Movement { private int numTicks = 0; public MovementDownward(BetterBlockPos start, BetterBlockPos end) { - super(start, end, new BlockPos[]{end}); + super(start, end, new BetterBlockPos[]{end}); } @Override diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 5e2556fe..a6a9e9f6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -157,14 +157,14 @@ public class MovementFall extends Movement { return state; } - private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) { - BlockPos[] toBreak; + private static BetterBlockPos[] buildPositionsToBreak(BetterBlockPos src, BetterBlockPos dest) { + BetterBlockPos[] toBreak; int diffX = src.getX() - dest.getX(); int diffZ = src.getZ() - dest.getZ(); int diffY = src.getY() - dest.getY(); - toBreak = new BlockPos[diffY + 2]; + toBreak = new BetterBlockPos[diffY + 2]; for (int i = 0; i < toBreak.length; i++) { - toBreak[i] = new BlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ); + toBreak[i] = new BetterBlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ); } return toBreak; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index d113fa0f..0093539f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -39,12 +39,13 @@ import java.util.Objects; public class MovementParkour extends Movement { private static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN_SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; + private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{}; private final EnumFacing direction; private final int dist; private MovementParkour(BetterBlockPos src, int dist, EnumFacing dir) { - super(src, src.offset(dir, dist), new BlockPos[]{}); + super(src, src.offset(dir, dist), EMPTY); this.direction = dir; this.dist = dist; super.override(costFromJumpDistance(dist)); @@ -59,7 +60,7 @@ public class MovementParkour extends Movement { if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || MovementHelper.isBottomSlab(standingOn)) { return null; } - BlockPos adjBlock = src.down().offset(dir); + BetterBlockPos adjBlock = src.down().offset(dir); IBlockState adj = BlockStateInterface.get(adjBlock); if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks return null; @@ -81,7 +82,7 @@ public class MovementParkour extends Movement { return null; } for (int i = 2; i <= (context.canSprint() ? 4 : 3); i++) { - BlockPos dest = src.offset(dir, i); + BetterBlockPos dest = src.offset(dir, i); // TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly? for (int y = 0; y < 4; y++) { if (!MovementHelper.fullyPassable(dest.up(y))) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index f87ff302..4cdc2f05 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -37,7 +37,7 @@ public class MovementPillar extends Movement { private int numTicks = 0; public MovementPillar(BetterBlockPos start, BetterBlockPos end) { - super(start, end, new BlockPos[]{start.up(2)}, start); + super(start, end, new BetterBlockPos[]{start.up(2)}, start); } @Override diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 05f73e58..a2d64377 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -46,7 +46,7 @@ public class MovementTraverse extends Movement { private boolean wasTheBridgeBlockAlwaysThere = true; public MovementTraverse(BetterBlockPos from, BetterBlockPos to) { - super(from, to, new BlockPos[]{to.up(), to}, to.down()); + super(from, to, new BetterBlockPos[]{to.up(), to}, to.down()); } @Override diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index a4fea03b..6cd2655a 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -213,6 +213,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("ok force canceled"); return; } + if (msg.equals("gc")) { + System.gc(); + event.cancel(); + logDirect("Called System.gc();"); + return; + } if (msg.equals("invert")) { Goal goal = PathingBehavior.INSTANCE.getGoal(); BlockPos runAwayFrom;