MCPcopy Create free account
hub / github.com/cabaletta/baritone / PathExecutor

Class PathExecutor

src/main/java/baritone/pathing/path/PathExecutor.java:48–671  ·  view source on GitHub ↗

Behavior to execute a precomputed path @author leijurv

Source from the content-addressed store, hash-verified

46 * @author leijurv
47 */
48public class PathExecutor implements IPathExecutor, Helper {
49
50 private static final double MAX_MAX_DIST_FROM_PATH = 3;
51 private static final double MAX_DIST_FROM_PATH = 2;
52
53 /**
54 * Default value is equal to 10 seconds. It's find to decrease it, but it must be at least 5.5s (110 ticks).
55 * For more information, see issue #102.
56 *
57 * @see <a href="https://github.com/cabaletta/baritone/issues/102">Issue #102</a>
58 * @see <a href="https://i.imgur.com/5s5GLnI.png">Anime</a>
59 */
60 private static final double MAX_TICKS_AWAY = 200;
61
62 private final IPath path;
63 private int pathPosition;
64 private int ticksAway;
65 private int ticksOnCurrent;
66 private Double currentMovementOriginalCostEstimate;
67 private Integer costEstimateIndex;
68 private boolean failed;
69 private boolean recalcBP = true;
70 private HashSet<BlockPos> toBreak = new HashSet<>();
71 private HashSet<BlockPos> toPlace = new HashSet<>();
72 private HashSet<BlockPos> toWalkInto = new HashSet<>();
73
74 private final PathingBehavior behavior;
75 private final IPlayerContext ctx;
76
77 private boolean sprintNextTick;
78
79 public PathExecutor(PathingBehavior behavior, IPath path) {
80 this.behavior = behavior;
81 this.ctx = behavior.ctx;
82 this.path = path;
83 this.pathPosition = 0;
84 }
85
86 /**
87 * Tick this executor
88 *
89 * @return True if a movement just finished (and the player is therefore in a "stable" state, like,
90 * not sneaking out over lava), false otherwise
91 */
92 public boolean onTick() {
93 if (pathPosition == path.length() - 1) {
94 pathPosition++;
95 }
96 if (pathPosition >= path.length()) {
97 return true; // stop bugging me, I'm done
98 }
99 Movement movement = (Movement) path.movements().get(pathPosition);
100 BetterBlockPos whereAmI = ctx.playerFeet();
101 if (!movement.getValidPositions().contains(whereAmI)) {
102 for (int i = 0; i < pathPosition && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
103 if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
104 int previousPos = pathPosition;
105 pathPosition = i;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected