From fd6120770969b43a1880f6eb55c4ee89d6c01074 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Thu, 28 Jan 2021 01:27:27 +0100 Subject: [PATCH] Fix heuristic(no args) returning wrong values --- src/api/java/baritone/api/pathing/goals/GoalNear.java | 8 +++++++- .../java/baritone/api/pathing/goals/GoalRunAway.java | 11 ++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalNear.java b/src/api/java/baritone/api/pathing/goals/GoalNear.java index 272636ac5..7f87e8b92 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalNear.java +++ b/src/api/java/baritone/api/pathing/goals/GoalNear.java @@ -71,7 +71,13 @@ public class GoalNear implements Goal, IGoalRenderPos { } } } - return Collections.max(maybeAlwaysInside); + double maxInside = Double.NEGATIVE_INFINITY; + for (double inside : maybeAlwaysInside) { + if (inside < minOutside) { + maxInside = Math.max(maxInside, inside); + } + } + return maxInside; } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java index 36797617e..b9c41aeaf 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java +++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java @@ -23,7 +23,6 @@ import net.minecraft.util.math.BlockPos; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.NoSuchElementException; /** * Useful for automated combat (retreating specifically) @@ -114,11 +113,13 @@ public class GoalRunAway implements Goal { } } } - try { - return Collections.max(maybeAlwaysInside); - } catch (NoSuchElementException e) { - return Double.NEGATIVE_INFINITY; + double maxInside = Double.NEGATIVE_INFINITY; + for (double inside : maybeAlwaysInside) { + if (inside < minOutside) { + maxInside = Math.max(maxInside, inside); + } } + return maxInside; } @Override