diff --git a/src/main/java/baritone/bot/event/listener/IGameEventListener.java b/src/main/java/baritone/bot/event/listener/IGameEventListener.java index f72bebfe7..d418519d0 100644 --- a/src/main/java/baritone/bot/event/listener/IGameEventListener.java +++ b/src/main/java/baritone/bot/event/listener/IGameEventListener.java @@ -113,4 +113,6 @@ public interface IGameEventListener { * @see NetworkManager#dispatchPacket(Packet, GenericFutureListener[]) */ void onReceivePacket(PacketEvent event); + + } diff --git a/src/main/java/baritone/bot/pathing/calc/PathNode.java b/src/main/java/baritone/bot/pathing/calc/PathNode.java index f9130b4b6..1b872972d 100644 --- a/src/main/java/baritone/bot/pathing/calc/PathNode.java +++ b/src/main/java/baritone/bot/pathing/calc/PathNode.java @@ -21,8 +21,6 @@ import baritone.bot.pathing.goals.Goal; import baritone.bot.pathing.movement.Movement; import net.minecraft.util.math.BlockPos; -import java.util.Objects; - /** * A node in the path, containing the cost and steps to get to it. * @@ -80,6 +78,8 @@ public class PathNode { */ public int heapPosition; + public final int hashCode; + public PathNode(BlockPos pos, Goal goal) { this.pos = pos; this.previous = null; @@ -88,6 +88,7 @@ public class PathNode { this.estimatedCostToGoal = goal.heuristic(pos); this.previousMovement = null; this.isOpen = false; + this.hashCode = calcHashCode(); } /** @@ -97,12 +98,25 @@ public class PathNode { */ @Override public int hashCode() { + throw new IllegalStateException(); + } + + private final int calcHashCode() { + /* + * This is the hashcode implementation of Vec3i, the superclass of BlockPos + * + * public int hashCode() { + * return (this.getY() + this.getZ() * 31) * 31 + this.getX(); + * } + * + * That is terrible and has tons of collisions and makes the HashMap terribly inefficient. + * + * That's why we grab out the X, Y, Z and calculate our own hashcode + */ int hash = 3241; hash = 3457689 * hash + this.pos.getX(); hash = 8734625 * hash + this.pos.getY(); hash = 2873465 * hash + this.pos.getZ(); - // Don't call goal.hashCode(). this calls objects hashcode to verify that the actual goal objects are == identical, which is important for node caching - hash = 3241543 * hash + Objects.hashCode(this.goal); return hash; } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java index 578a89b6f..2b25a191a 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java @@ -66,42 +66,41 @@ public class MovementDescend extends Movement { case WAITING: state.setStatus(MovementStatus.RUNNING); case RUNNING: - BlockPos playerFeet = playerFeet(); - - if (playerFeet.equals(dest)) { - if (BlockStateInterface.isLiquid(dest) || player().posY - playerFeet.getY() < 0.01) { - // 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 - state.setStatus(MovementStatus.SUCCESS); - return state; - } else { - System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY())); - } - } - double diffX = player().posX - (dest.getX() + 0.5); - double diffZ = player().posZ - (dest.getZ() + 0.5); - double ab = Math.sqrt(diffX * diffX + diffZ * diffZ); - double x = player().posX - (src.getX() + 0.5); - double z = player().posZ - (src.getZ() + 0.5); - double fromStart = Math.sqrt(x * x + z * z); - if (!playerFeet.equals(dest) || ab > 0.25) { - BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ()); - double diffX2 = player().posX - (fakeDest.getX() + 0.5); - double diffZ2 = player().posZ - (fakeDest.getZ() + 0.5); - double d = Math.sqrt(diffX2 * diffX2 + diffZ2 * diffZ2); - if (numTicks++ < 20) { - MovementHelper.moveTowards(state, fakeDest); - if (fromStart > 1.25) { - state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false); - state.setInput(InputOverrideHandler.Input.MOVE_BACK, true); - } - } else { - MovementHelper.moveTowards(state, dest); - } - } - return state; + break; default: return state; } + BlockPos playerFeet = playerFeet(); + if (playerFeet.equals(dest)) { + if (BlockStateInterface.isLiquid(dest) || player().posY - playerFeet.getY() < 0.01) { + // 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 + state.setStatus(MovementStatus.SUCCESS); + return state; + } else { + System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY())); + } + } + double diffX = player().posX - (dest.getX() + 0.5); + double diffZ = player().posZ - (dest.getZ() + 0.5); + double ab = Math.sqrt(diffX * diffX + diffZ * diffZ); + double x = player().posX - (src.getX() + 0.5); + double z = player().posZ - (src.getZ() + 0.5); + double fromStart = Math.sqrt(x * x + z * z); + if (!playerFeet.equals(dest) || ab > 0.25) { + BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ()); + double diffX2 = player().posX - (fakeDest.getX() + 0.5); + double diffZ2 = player().posZ - (fakeDest.getZ() + 0.5); + double d = Math.sqrt(diffX2 * diffX2 + diffZ2 * diffZ2); + if (numTicks++ < 20) { + MovementHelper.moveTowards(state, fakeDest); + if (fromStart > 1.25) { + state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, false); + state.setInput(InputOverrideHandler.Input.MOVE_BACK, true); + } + } else { + MovementHelper.moveTowards(state, dest); + } + } + return state; } - } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java index 89ad7ce81..bc68e2bcf 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java @@ -59,21 +59,22 @@ public class MovementDownward extends Movement { return state; case WAITING: case RUNNING: - if (playerFeet().equals(dest)) { - state.setStatus(MovementState.MovementStatus.SUCCESS); - return state; - } - double diffX = player().posX - (dest.getX() + 0.5); - double diffZ = player().posZ - (dest.getZ() + 0.5); - double ab = Math.sqrt(diffX * diffX + diffZ * diffZ); - - if (numTicks++ < 10 && ab < 0.2) { - return state; - } - MovementHelper.moveTowards(state, positionsToBreak[0]); - return state; + break; default: return state; } + if (playerFeet().equals(dest)) { + state.setStatus(MovementState.MovementStatus.SUCCESS); + return state; + } + double diffX = player().posX - (dest.getX() + 0.5); + double diffZ = player().posZ - (dest.getZ() + 0.5); + double ab = Math.sqrt(diffX * diffX + diffZ * diffZ); + + if (numTicks++ < 10 && ab < 0.2) { + return state; + } + MovementHelper.moveTowards(state, positionsToBreak[0]); + return state; } } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java index 9fa07143a..592440ff7 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java @@ -74,44 +74,45 @@ public class MovementFall extends Movement { case WAITING: state.setStatus(MovementStatus.RUNNING); case RUNNING: - BlockPos playerFeet = playerFeet(); - Optional targetRotation = Optional.empty(); - if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3 && !playerFeet.equals(dest)) { - if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { // TODO check if water bucket is on hotbar or main inventory - state.setStatus(MovementStatus.UNREACHABLE); - return state; - } - if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) { - player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER); - targetRotation = LookBehaviorUtils.reachable(dest.down()); - } - } - if (targetRotation.isPresent()) { - state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true) - .setTarget(new MovementTarget(targetRotation.get())); - } else { - state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)))); - } - if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 - || BlockStateInterface.isWater(dest))) { - if (BlockStateInterface.isWater(dest) && player().inventory.hasItemStack(STACK_BUCKET_EMPTY)) { - player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY); - if (player().motionY >= 0) { - return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); - } else { - return state; - } - } - return state.setStatus(MovementStatus.SUCCESS); - } - Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder) - if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) { - state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); - } - return state; + break; default: return state; } + BlockPos playerFeet = playerFeet(); + Optional targetRotation = Optional.empty(); + if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3 && !playerFeet.equals(dest)) { + if (!player().inventory.hasItemStack(STACK_BUCKET_WATER) || world().provider.isNether()) { // TODO check if water bucket is on hotbar or main inventory + state.setStatus(MovementStatus.UNREACHABLE); + return state; + } + if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) { + player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER); + targetRotation = LookBehaviorUtils.reachable(dest.down()); + } + } + if (targetRotation.isPresent()) { + state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true) + .setTarget(new MovementTarget(targetRotation.get())); + } else { + state.setTarget(new MovementTarget(Utils.calcRotationFromVec3d(playerHead(), Utils.getBlockPosCenter(dest)))); + } + if (playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 + || BlockStateInterface.isWater(dest))) { + if (BlockStateInterface.isWater(dest) && player().inventory.hasItemStack(STACK_BUCKET_EMPTY)) { + player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_EMPTY); + if (player().motionY >= 0) { + return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); + } else { + return state; + } + } + return state.setStatus(MovementStatus.SUCCESS); + } + Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder) + if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) { + state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); + } + return state; } private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {