From 04d210bd8bd6279dfe0fd8cec2b4687aba147f5d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 3 Oct 2018 07:43:45 -0700 Subject: [PATCH] no need to calculate the hash on contstruction anymore --- .../baritone/behavior/PathingBehavior.java | 22 ++++++++++--------- .../utils/pathing/BetterBlockPos.java | 11 +++++----- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 9c09533f..f10a15cd 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -352,7 +352,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } else { timeout = Baritone.settings().planAheadTimeoutMS.get(); } - Optional> favoredPositions = previous.map(IPath::positions).map(Collection::stream).map(x -> x.map(y -> y.hashCode)).map(x -> x.collect(Collectors.toList())).map(HashSet::new); // <-- okay this is EPIC + Optional> favoredPositions = previous.map(IPath::positions).map(Collection::stream).map(x -> x.map(BetterBlockPos::longHash)).map(x -> x.collect(Collectors.toList())).map(HashSet::new); // <-- okay this is EPIC try { IPathFinder pf = new AStarPathFinder(start, goal, favoredPositions); return pf.calculate(timeout); @@ -367,15 +367,17 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, if (!Baritone.settings().cancelOnGoalInvalidation.get()) { return; } - if (current == null || goal == null) { - return; - } - Goal intended = current.getPath().getGoal(); - BlockPos end = current.getPath().getDest(); - if (intended.isInGoal(end) && !goal.isInGoal(end)) { - // this path used to end in the goal - // but the goal has changed, so there's no reason to continue... - cancel(); + synchronized (pathPlanLock) { + if (current == null || goal == null) { + return; + } + Goal intended = current.getPath().getGoal(); + BlockPos end = current.getPath().getDest(); + if (intended.isInGoal(end) && !goal.isInGoal(end)) { + // this path used to end in the goal + // but the goal has changed, so there's no reason to continue... + cancel(); + } } } diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 7aed17c6..e81319db 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -36,14 +36,12 @@ public final class BetterBlockPos extends BlockPos { public final int x; public final int y; public final int z; - public final long hashCode; public BetterBlockPos(int x, int y, int z) { super(x, y, z); this.x = x; this.y = y; this.z = z; - this.hashCode = AbstractNodeCostSearch.posHash(x, y, z); } public BetterBlockPos(double x, double y, double z) { @@ -56,7 +54,11 @@ public final class BetterBlockPos extends BlockPos { @Override public int hashCode() { - return (int) hashCode; + return (int) AbstractNodeCostSearch.posHash(x, y, z); + } + + public static long longHash(BetterBlockPos pos) { + return AbstractNodeCostSearch.posHash(pos.x, pos.y, pos.z); } @Override @@ -66,9 +68,6 @@ public final class BetterBlockPos extends BlockPos { } if (o instanceof BetterBlockPos) { BetterBlockPos oth = (BetterBlockPos) o; - if (oth.hashCode != hashCode) { - return false; - } return oth.x == x && oth.y == y && oth.z == z; } // during path execution, like "if (whereShouldIBe.equals(whereAmI)) {"