From 57b2e360ca43cfc1639faf085032621594c9959b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 4 Feb 2019 13:27:35 -0800 Subject: [PATCH] dont include current movement cost while deciding when to plan ahead --- .../baritone/api/behavior/IPathingBehavior.java | 15 ++++++++++++++- .../java/baritone/behavior/PathingBehavior.java | 4 +++- .../java/baritone/pathing/path/PathExecutor.java | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/behavior/IPathingBehavior.java b/src/api/java/baritone/api/behavior/IPathingBehavior.java index d28195ae..64be71d5 100644 --- a/src/api/java/baritone/api/behavior/IPathingBehavior.java +++ b/src/api/java/baritone/api/behavior/IPathingBehavior.java @@ -38,11 +38,24 @@ public interface IPathingBehavior extends IBehavior { * @return The estimated remaining ticks in the current segment. */ default Optional ticksRemainingInSegment() { + return ticksRemainingInSegment(true); + } + + /** + * Returns the estimated remaining ticks in the current pathing + * segment. Given that the return type is an optional, {@link Optional#empty()} + * will be returned in the case that there is no current segment being pathed. + * + * @param includeCurrentMovement whether or not to include the entirety of the cost of the currently executing movement in the total + * @return The estimated remaining ticks in the current segment. + */ + default Optional ticksRemainingInSegment(boolean includeCurrentMovement) { IPathExecutor current = getCurrent(); if (current == null) { return Optional.empty(); } - return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition())); + int start = includeCurrentMovement ? current.getPosition() : current.getPosition() + 1; + return Optional.of(current.getPath().ticksRemainingFrom(start)); } /** diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index ea752082..8339625d 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -193,8 +193,10 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, // and this path doesn't get us all the way there return; } - if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) { + if (ticksRemainingInSegment(false).get() < Baritone.settings().planningTickLookAhead.get()) { // and this path has 7.5 seconds or less left + // don't include the current movement so a very long last movement (e.g. descend) doesn't trip it up + // if we actually included current, it wouldn't start planning ahead until the last movement was done, if the last movement took more than 7.5 seconds on its own logDebug("Path almost over. Planning ahead..."); queuePathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED); findPathInNewThread(current.getPath().getDest(), false); diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 8ad0db59..1b59f8e3 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -249,6 +249,8 @@ public class PathExecutor implements IPathExecutor, Helper { return true; } if (!movement.calculatedWhileLoaded() && currentCost - currentMovementOriginalCostEstimate > Baritone.settings().maxCostIncrease.get() && canCancel) { + // don't do this if the movement was calculated while loaded + // that means that this isn't a cache error, it's just part of the path interfering with a later part logDebug("Original cost " + currentMovementOriginalCostEstimate + " current cost " + currentCost + ". Cancelling."); cancel(); return true;