From ae1e229619704b76f29931615621bcd86089a86b Mon Sep 17 00:00:00 2001 From: babbaj Date: Wed, 9 Jan 2019 05:39:37 -0500 Subject: [PATCH] fix garbage code --- .../baritone/utils/PathingControlManager.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index f28655e6..32788433 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -26,10 +26,10 @@ import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; import baritone.behavior.PathingBehavior; import baritone.pathing.path.PathExecutor; +import java.util.stream.Stream; import net.minecraft.util.math.BlockPos; import java.util.*; -import java.util.stream.Collectors; public class PathingControlManager implements IPathingControlManager { private final Baritone baritone; @@ -170,30 +170,30 @@ public class PathingControlManager implements IPathingControlManager { public PathingCommand doTheStuff() { - List inContention = processes.stream().filter(IBaritoneProcess::isActive).sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed()).collect(Collectors.toList()); - boolean found = false; - boolean cancelOthers = false; - PathingCommand exec = null; - for (IBaritoneProcess proc : inContention) { - if (found) { - if (cancelOthers) { - proc.onLostControl(); + Stream inContention = processes.stream() + .filter(IBaritoneProcess::isActive) + .sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed()); + + + Iterator iterator = inContention.iterator(); + while(iterator.hasNext()) { + IBaritoneProcess proc = iterator.next(); + + PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); + if (exec == null) { + if (proc.isActive()) { + throw new IllegalStateException(proc.displayName() + " returned null PathingCommand"); } + proc.onLostControl(); } else { - exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel()); - if (exec == null) { - if (proc.isActive()) { - throw new IllegalStateException(proc.displayName()); - } - proc.onLostControl(); - continue; - } - //System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName()); inControlThisTick = proc; - found = true; - cancelOthers = !proc.isTemporary(); + if (!proc.isTemporary()) { + iterator.forEachRemaining(IBaritoneProcess::onLostControl); + } + + return exec; } } - return exec; + return null; } }