IPathingControlManager

This commit is contained in:
Leijurv 2018-11-18 21:41:42 -08:00
parent 4fb6c71174
commit 16e3fd9305
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 47 additions and 8 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<IBaritoneProcess> mostRecentInControl();
Optional<PathingCommand> mostRecentCommand();
}

View File

@ -20,6 +20,7 @@ package baritone.utils;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.event.events.TickEvent; import baritone.api.event.events.TickEvent;
import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.pathing.calc.IPathingControlManager;
import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.Goal;
import baritone.api.process.IBaritoneProcess; import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommand;
@ -27,13 +28,10 @@ import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor; import baritone.pathing.path.PathExecutor;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.Comparator; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class PathingControlManager { public class PathingControlManager implements IPathingControlManager {
private final Baritone baritone; private final Baritone baritone;
private final HashSet<IBaritoneProcess> processes; // unGh private final HashSet<IBaritoneProcess> processes; // unGh
private IBaritoneProcess inControlLastTick; private IBaritoneProcess inControlLastTick;
@ -54,12 +52,16 @@ public class PathingControlManager {
}); });
} }
@Override
public void registerProcess(IBaritoneProcess process) { public void registerProcess(IBaritoneProcess process) {
process.onLostControl(); // make sure it's reset process.onLostControl(); // make sure it's reset
processes.add(process); 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) { for (IBaritoneProcess proc : processes) {
proc.onLostControl(); 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 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() { @Override
return inControlThisTick; public Optional<IBaritoneProcess> mostRecentInControl() {
return Optional.ofNullable(inControlThisTick);
}
@Override
public Optional<PathingCommand> mostRecentCommand() {
return Optional.ofNullable(command);
} }
public void preTick() { public void preTick() {