From 41ffd4455dce9e63b3fc697df3204ece01fe9145 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 1 Oct 2018 14:50:20 -0700 Subject: [PATCH] don't cancel for any reason while doing a water bucket fall, fixes #98, fixes #123 --- src/main/java/baritone/pathing/movement/Movement.java | 8 ++++++++ .../baritone/pathing/movement/movements/MovementFall.java | 5 +++++ src/main/java/baritone/pathing/path/PathExecutor.java | 7 ++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 21341fa4..b952e547 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -187,6 +187,14 @@ public abstract class Movement implements Helper, MovementHelper { return true; } + public boolean safeToCancel() { + return safeToCancel(currentState); + } + + protected boolean safeToCancel(MovementState currentState) { + return false; + } + public boolean isFinished() { return (currentState.getStatus() != MovementStatus.RUNNING && currentState.getStatus() != MovementStatus.PREPPING diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 0f165f6f..1cfd451f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -111,6 +111,11 @@ public class MovementFall extends Movement { return state; } + @Override + public boolean safeToCancel(MovementState state) { + return state.getStatus() != MovementStatus.RUNNING; + } + private static BetterBlockPos[] buildPositionsToBreak(BetterBlockPos src, BetterBlockPos dest) { BetterBlockPos[] toBreak; int diffX = src.getX() - dest.getX(); diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 8852e279..8dcdb159 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -221,12 +221,13 @@ public class PathExecutor implements Helper { System.out.println("Recalculating break and place took " + (end - start) + "ms"); } Movement movement = path.movements().get(pathPosition); + boolean canCancel = movement.safeToCancel(); if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; // 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 currentMovementOriginalCostEstimate = movement.getCost(null); for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { - if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF) { + if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF && canCancel) { logDebug("Something has changed in the world and a future movement has become impossible. Cancelling."); cancel(); return true; @@ -234,12 +235,12 @@ public class PathExecutor implements Helper { } } double currentCost = movement.recalculateCost(); - if (currentCost >= ActionCosts.COST_INF) { + if (currentCost >= ActionCosts.COST_INF && canCancel) { logDebug("Something has changed in the world and this movement has become impossible. Cancelling."); cancel(); return true; } - if (!movement.calculatedWhileLoaded() && currentCost - currentMovementOriginalCostEstimate > Baritone.settings().maxCostIncrease.get()) { + if (!movement.calculatedWhileLoaded() && currentCost - currentMovementOriginalCostEstimate > Baritone.settings().maxCostIncrease.get() && canCancel) { logDebug("Original cost " + currentMovementOriginalCostEstimate + " current cost " + currentCost + ". Cancelling."); cancel(); return true;