From f75188b24d7f727155afac0bca91faea860b90fe Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 14:12:33 -0700 Subject: [PATCH] fix cost cache overwrite in path executor --- src/main/java/baritone/pathing/movement/Movement.java | 4 ++++ src/main/java/baritone/pathing/path/PathExecutor.java | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 44c9d5a3..715bfd68 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -100,6 +100,10 @@ public abstract class Movement implements Helper, MovementHelper { return getCost(null); } + public double calculateCostWithoutCaching() { + return calculateCost0(new CalculationContext()); + } + /** * Handles the execution of the latest Movement * State, and offers a Status to the calling class. diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index ce86b4d0..88ca6e30 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -219,9 +219,10 @@ public class PathExecutor implements Helper { Movement movement = path.movements().get(pathPosition); if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; - currentMovementInitialCostEstimate = movement.getCost(null); // do this only once, when the movement starts + // do this only once, when the movement starts, and deliberately get the cost as cached when this path was calculated, not the cost as it is right now + currentMovementInitialCostEstimate = movement.getCost(null); for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { - if (path.movements().get(pathPosition + i).recalculateCost() >= ActionCosts.COST_INF) { + if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF) { displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); pathPosition = path.length() + 3; failed = true;