cleanup
This commit is contained in:
@@ -54,6 +54,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
|
||||
private boolean safeToCancel;
|
||||
private boolean pauseRequestedLastTick;
|
||||
private boolean calcFailedLastTick;
|
||||
|
||||
private volatile boolean isPathCalcInProgress;
|
||||
private final Object pathCalcLock = new Object();
|
||||
@@ -75,6 +76,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
private void dispatchEvents() {
|
||||
ArrayList<PathEvent> curr = new ArrayList<>();
|
||||
toDispatch.drainTo(curr);
|
||||
calcFailedLastTick = curr.contains(PathEvent.CALC_FAILED);
|
||||
for (PathEvent event : curr) {
|
||||
Baritone.INSTANCE.getGameEventHandler().onPathEvent(event);
|
||||
}
|
||||
@@ -257,6 +259,10 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
baritone.getPathingControlManager().cancelEverything();
|
||||
}
|
||||
|
||||
public boolean calcFailedLastTick() { // NOT exposed on public api
|
||||
return calcFailedLastTick;
|
||||
}
|
||||
|
||||
// just cancel the current path
|
||||
public void secretInternalSegmentCancel() {
|
||||
queuePathEvent(PathEvent.CANCELED);
|
||||
|
||||
@@ -22,7 +22,6 @@ import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.process.ICustomGoalProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -35,7 +34,6 @@ import java.util.Objects;
|
||||
public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
|
||||
private Goal goal;
|
||||
private State state;
|
||||
private int ticksExecuting;
|
||||
|
||||
public CustomGoalProcess(Baritone baritone) {
|
||||
super(baritone, 3);
|
||||
@@ -69,7 +67,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick() {
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
switch (state) {
|
||||
case GOAL_SET:
|
||||
if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), goal)) {
|
||||
@@ -79,12 +77,14 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
||||
case PATH_REQUESTED:
|
||||
PathingCommand ret = new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||
state = State.EXECUTING;
|
||||
ticksExecuting = 0;
|
||||
return ret;
|
||||
case EXECUTING:
|
||||
if (ticksExecuting++ > 2 && !baritone.getPathingBehavior().isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) {
|
||||
if (calcFailed) {
|
||||
onLostControl();
|
||||
}
|
||||
if (goal.isInGoal(playerFeet())) {
|
||||
onLostControl(); // we're there xd
|
||||
}
|
||||
return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
@@ -95,7 +95,6 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
||||
public void onLostControl() {
|
||||
state = State.NONE;
|
||||
goal = null;
|
||||
ticksExecuting = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick() {
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
// lol this is trashy but it works
|
||||
BlockPos pos;
|
||||
if (Baritone.settings().followOffsetDistance.get() == 0) {
|
||||
|
||||
@@ -32,10 +32,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess {
|
||||
Block gettingTo;
|
||||
List<BlockPos> knownLocations;
|
||||
private Block gettingTo;
|
||||
private List<BlockPos> knownLocations;
|
||||
|
||||
int tickCount = 0;
|
||||
private int tickCount = 0;
|
||||
|
||||
public GetToBlockProcess(Baritone baritone) {
|
||||
super(baritone, 2);
|
||||
@@ -53,14 +53,23 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick() {
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
if (knownLocations == null) {
|
||||
rescan();
|
||||
}
|
||||
if (knownLocations.isEmpty()) {
|
||||
logDirect("No known locations of " + gettingTo);
|
||||
onLostControl();
|
||||
return null;
|
||||
logDirect("No known locations of " + gettingTo + ", canceling GetToBlock");
|
||||
if (isSafeToCancel) {
|
||||
onLostControl();
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
if (calcFailed) {
|
||||
logDirect("Unable to find any path to " + gettingTo + ", canceling GetToBlock");
|
||||
if (isSafeToCancel) {
|
||||
onLostControl();
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
|
||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick() {
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
if (desiredQuantity > 0) {
|
||||
Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), new Random(), 0);
|
||||
int curr = player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum();
|
||||
@@ -77,6 +77,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (calcFailed) {
|
||||
logDirect("Unable to find any path to " + mining + ", canceling Mine");
|
||||
cancel();
|
||||
return null;
|
||||
}
|
||||
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
|
||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
||||
baritone.getExecutor().execute(this::rescan);
|
||||
|
||||
@@ -100,7 +100,6 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
public boolean runCommand(String msg0) {
|
||||
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
||||
PathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||
PathingControlManager pathControl = baritone.getPathingControlManager();
|
||||
CustomGoalProcess CGPgrey = baritone.getCustomGoalProcess();
|
||||
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
||||
for (Settings.Setting<Boolean> setting : toggleable) {
|
||||
|
||||
@@ -33,6 +33,8 @@ import java.util.stream.Collectors;
|
||||
public class PathingControlManager {
|
||||
private final Baritone baritone;
|
||||
private final HashSet<IBaritoneProcess> processes; // unGh
|
||||
private IBaritoneProcess inControlLastTick;
|
||||
private IBaritoneProcess inControlThisTick;
|
||||
|
||||
public PathingControlManager(Baritone baritone) {
|
||||
this.baritone = baritone;
|
||||
@@ -54,7 +56,12 @@ public class PathingControlManager {
|
||||
}
|
||||
}
|
||||
|
||||
public IBaritoneProcess inControlThisTick() {
|
||||
return inControlThisTick;
|
||||
}
|
||||
|
||||
public void doTheThingWithTheStuff() {
|
||||
inControlLastTick = inControlThisTick;
|
||||
PathingCommand cmd = doTheStuff();
|
||||
if (cmd == null) {
|
||||
return;
|
||||
@@ -119,7 +126,7 @@ public class PathingControlManager {
|
||||
proc.onLostControl();
|
||||
}
|
||||
} else {
|
||||
exec = proc.onTick();
|
||||
exec = proc.onTick(proc == inControlLastTick && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
|
||||
if (exec == null) {
|
||||
if (proc.isActive()) {
|
||||
throw new IllegalStateException(proc.displayName());
|
||||
@@ -128,6 +135,7 @@ public class PathingControlManager {
|
||||
continue;
|
||||
}
|
||||
System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName());
|
||||
inControlThisTick = proc;
|
||||
found = true;
|
||||
cancelOthers = !proc.isTemporary();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user