From 16e3fd93051484aa0ac1c2eff46ca1638d31a326 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 18 Nov 2018 21:41:42 -0800 Subject: [PATCH] IPathingControlManager --- .../pathing/calc/IPathingControlManager.java | 31 +++++++++++++++++++ .../baritone/utils/PathingControlManager.java | 24 +++++++++----- 2 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/api/java/baritone/api/pathing/calc/IPathingControlManager.java diff --git a/src/api/java/baritone/api/pathing/calc/IPathingControlManager.java b/src/api/java/baritone/api/pathing/calc/IPathingControlManager.java new file mode 100644 index 00000000..ffaa18b8 --- /dev/null +++ b/src/api/java/baritone/api/pathing/calc/IPathingControlManager.java @@ -0,0 +1,31 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.pathing.calc; + +import baritone.api.process.IBaritoneProcess; +import baritone.api.process.PathingCommand; + +import java.util.Optional; + +public interface IPathingControlManager { + void registerProcess(IBaritoneProcess process); + + Optional mostRecentInControl(); + + Optional mostRecentCommand(); +} diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index fa58a069..f5fff546 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.api.event.events.TickEvent; import baritone.api.event.listener.AbstractGameEventListener; +import baritone.api.pathing.calc.IPathingControlManager; import baritone.api.pathing.goals.Goal; import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; @@ -27,13 +28,10 @@ import baritone.behavior.PathingBehavior; import baritone.pathing.path.PathExecutor; import net.minecraft.util.math.BlockPos; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; -public class PathingControlManager { +public class PathingControlManager implements IPathingControlManager { private final Baritone baritone; private final HashSet processes; // unGh private IBaritoneProcess inControlLastTick; @@ -54,12 +52,16 @@ public class PathingControlManager { }); } + @Override public void registerProcess(IBaritoneProcess process) { process.onLostControl(); // make sure it's reset processes.add(process); } - public void cancelEverything() { + public void cancelEverything() { // called by PathingBehavior on TickEvent Type OUT + inControlLastTick = null; + inControlThisTick = null; + command = null; for (IBaritoneProcess proc : processes) { proc.onLostControl(); if (proc.isActive() && !proc.isTemporary()) { // it's okay for a temporary thing (like combat pause) to maintain control even if you say to cancel @@ -69,8 +71,14 @@ public class PathingControlManager { } } - public IBaritoneProcess inControlThisTick() { - return inControlThisTick; + @Override + public Optional mostRecentInControl() { + return Optional.ofNullable(inControlThisTick); + } + + @Override + public Optional mostRecentCommand() { + return Optional.ofNullable(command); } public void preTick() {