diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index bfab655e..c2a618b9 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -144,6 +144,12 @@ public class Settings { */ public Setting cutoffAtLoadBoundary = new Setting<>(false); + /** + * If a movement's cost increases by more than this amount between calculation and execution (due to changes + * in the environment / world), cancel and recalculate + */ + public Setting maxCostIncrease = new Setting<>(10D); + /** * 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 diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index e59d9aa7..93e12e09 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -236,6 +236,13 @@ public class PathExecutor implements Helper { Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); return true; } + if (currentCost - currentMovementInitialCostEstimate > Baritone.settings().maxCostIncrease.get()) { + logDebug("Original cost " + currentMovementInitialCostEstimate + " current cost " + currentCost + ". Cancelling."); + pathPosition = path.length() + 3; + failed = true; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + return true; + } player().capabilities.allowFlying = false; MovementState.MovementStatus movementStatus = movement.update(); if (movementStatus == UNREACHABLE || movementStatus == FAILED) {