From 6dd501a46bbba8710bd8bea524f6c2bf13987996 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 26 Aug 2018 08:19:14 -0700 Subject: [PATCH] add cost verification lookahead --- src/main/java/baritone/Settings.java | 7 +++++++ src/main/java/baritone/pathing/path/PathExecutor.java | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index a23401dc..9b918416 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -119,6 +119,13 @@ public class Settings { */ public Setting cutoffAtLoadBoundary = new Setting<>(true); + /** + * Stop 5 movements before anything that made the path COST_INF. + * For example, if lava has spread across the path, don't walk right up to it then recalculate, it might + * still be spreading lol + */ + public Setting costVerificationLookahead = new Setting<>(5); + /** * Static cutoff factor. 0.9 means cut off the last 10% of all paths, regardless of chunk load state */ diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 210544c4..75bebc8a 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -211,6 +211,15 @@ public class PathExecutor implements Helper { Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); return true; } + for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { + if (path.movements().get(pathPosition + 1).recalculateCost() >= ActionCosts.COST_INF) { + displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); + pathPosition = path.length() + 3; + failed = true; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + return true; + } + } if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; currentMovementInitialCostEstimate = currentCost; // do this only once, when the movement starts