Don't overshoot descends before using frostwalker
This commit is contained in:
parent
cf47573298
commit
78f1c45e13
@ -44,6 +44,7 @@ import java.util.Set;
|
||||
public class MovementDescend extends Movement {
|
||||
|
||||
private int numTicks = 0;
|
||||
public boolean forceSafeMode = false;
|
||||
|
||||
public MovementDescend(IBaritone baritone, BetterBlockPos start, BetterBlockPos end) {
|
||||
super(baritone, start, end, new BetterBlockPos[]{end.up(2), end.up(), end}, end.down());
|
||||
@ -53,6 +54,14 @@ public class MovementDescend extends Movement {
|
||||
public void reset() {
|
||||
super.reset();
|
||||
numTicks = 0;
|
||||
forceSafeMode = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by PathExecutor if needing safeMode can only be detected with knowledge about the next movement
|
||||
*/
|
||||
public void forceSafeMode() {
|
||||
forceSafeMode = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -252,6 +261,9 @@ public class MovementDescend extends Movement {
|
||||
}
|
||||
|
||||
public boolean safeMode() {
|
||||
if (forceSafeMode) {
|
||||
return true;
|
||||
}
|
||||
// (dest - src) + dest is offset 1 more in the same direction
|
||||
// so it's the block we'd need to worry about running into if we decide to sprint straight through this descend
|
||||
BlockPos into = dest.subtract(src.down()).add(dest);
|
||||
|
@ -380,13 +380,20 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
// however, descend and ascend don't request sprinting, because they don't know the context of what movement comes after it
|
||||
if (current instanceof MovementDescend) {
|
||||
|
||||
IMovement next = path.movements().get(pathPosition + 1);
|
||||
if (next instanceof MovementTraverse) {
|
||||
if (MovementHelper.canUseFrostWalker(ctx, next.getDest().down())) {
|
||||
// if we are going to continue straight onto the water with frostwalker feet.equals(dest) must hold, otherwise we don't want to waste time
|
||||
// Since MovementDescend can't know the direction of the next movement we have to tell it
|
||||
((MovementDescend) current).forceSafeMode(); // keep this out of onTick, even if that means a tick of delay before it has an effect
|
||||
}
|
||||
}
|
||||
if (((MovementDescend) current).safeMode() && !((MovementDescend) current).skipToAscend()) {
|
||||
logDebug("Sprinting would be unsafe");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathPosition < path.length() - 2) {
|
||||
IMovement next = path.movements().get(pathPosition + 1);
|
||||
if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) {
|
||||
// a descend then an ascend in the same direction
|
||||
pathPosition++;
|
||||
|
Loading…
Reference in New Issue
Block a user