Fix failed path cancellation

This commit is contained in:
Howard Stark
2018-08-05 22:08:23 -04:00
parent 586024b57e
commit b96ee346f9
5 changed files with 52 additions and 2 deletions

View File

@@ -168,6 +168,12 @@ public abstract class Movement implements Helper, MovementHelper {
state.setStatus(MovementStatus.SUCCESS);
}
public void cancel() {
currentState.inputState.replaceAll((input, forced) -> false);
currentState.inputState.forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
currentState.setStatus(MovementStatus.CANCELED);
}
/**
* Calculate latest movement state.
* Gets called once a tick.

View File

@@ -73,6 +73,6 @@ public class MovementState {
}
public enum MovementStatus {
PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED, FINISHING;
PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED, CANCELED;
}
}

View File

@@ -78,7 +78,7 @@ public class MovementAscend extends Movement {
state.setStatus(MovementStatus.SUCCESS);
return state;
}
state.setTarget(new MovementState.MovementTarget(Optional.empty(), Optional.of(Utils.calcRotationFromVec3d(new Vec3d(player().posX, player().posY + 1.62, player().posZ), Utils.calcCenterFromCoords(positionsToBreak[0], world())))));
state.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
return state;

View File

@@ -135,6 +135,7 @@ public class PathExecutor extends Behavior {
ticksOnCurrent++;
if (ticksOnCurrent > movement.recalculateCost() + 100) {
System.out.println("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + movement.getCost(null) + "). Cancelling.");
movement.cancel();
pathPosition = path.length() + 3;
failed = true;
return;