diff --git a/src/api/java/baritone/api/pathing/goals/Goal.java b/src/api/java/baritone/api/pathing/goals/Goal.java index acee68db8..7d8f42220 100644 --- a/src/api/java/baritone/api/pathing/goals/Goal.java +++ b/src/api/java/baritone/api/pathing/goals/Goal.java @@ -54,4 +54,18 @@ public interface Goal { default double heuristic(BlockPos pos) { return heuristic(pos.getX(), pos.getY(), pos.getZ()); } + + /** + * Returns the heuristic at the goal. + * i.e. {@code heuristic() == heuristic(x,y,z)} + * when {@code isInGoal(x,y,z) == true} + * This is needed by {@code PathingBehavior#estimatedTicksToGoal} because + * some Goals actually do not have a heuristic of 0 when that condition is met + * + * @return The estimate number of ticks to satisfy the goal when the goal + * is already satisfied + */ + default double heuristic() { + return 0; + } } diff --git a/src/api/java/baritone/api/pathing/goals/GoalInverted.java b/src/api/java/baritone/api/pathing/goals/GoalInverted.java index 197369241..354e2ce39 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalInverted.java +++ b/src/api/java/baritone/api/pathing/goals/GoalInverted.java @@ -45,6 +45,11 @@ public class GoalInverted implements Goal { return -origin.heuristic(x, y, z); } + @Override + public double heuristic() { + return Double.NEGATIVE_INFINITY; + } + @Override public String toString() { return String.format("GoalInverted{%s}", origin.toString()); diff --git a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java index b48a029ad..e93f47ac0 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java +++ b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java @@ -64,6 +64,11 @@ public class GoalStrictDirection implements Goal { return heuristic; } + @Override + public double heuristic() { + return Double.NEGATIVE_INFINITY; + } + @Override public String toString() { return String.format( diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 5cc9520c7..5f69aabe7 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -387,7 +387,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, if (current == start) {//can't check above because current and start can be equal even if currentPos and startPosition are not return Optional.empty(); } - double eta = Math.abs(current) * ticksElapsedSoFar / Math.abs(start - current); + double eta = Math.abs(current - goal.heuristic()) * ticksElapsedSoFar / Math.abs(start - current); return Optional.of(eta); }