improve path safety

This commit is contained in:
Leijurv 2018-09-11 18:26:10 -07:00
parent 1bf34d42e2
commit acd9cecd66
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 21 additions and 31 deletions

View File

@ -40,7 +40,7 @@ import java.awt.*;
import java.util.Collections;
import java.util.Optional;
public class PathingBehavior extends Behavior {
public final class PathingBehavior extends Behavior {
public static final PathingBehavior INSTANCE = new PathingBehavior();
@ -66,7 +66,7 @@ public class PathingBehavior extends Behavior {
@Override
public void onTick(TickEvent event) {
if (event.getType() == TickEvent.Type.OUT) {
this.cancel();
softCancel(); // no player, so can't fix capabilities
return;
}
if (current == null) {
@ -191,11 +191,15 @@ public class PathingBehavior extends Behavior {
return Optional.ofNullable(current).map(PathExecutor::getPath);
}
public void cancel() {
private void softCancel() {
current = null;
next = null;
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel);
}
public void cancel() {
softCancel();
mc.playerController.setPlayerCapabilities(mc.player);
}

View File

@ -58,33 +58,6 @@ public interface IPath extends Helper {
return positions().size();
}
/**
* What's the next step
*
* @param currentPosition the current position
* @return
*/
default Movement subsequentMovement(BlockPos currentPosition) {
List<BetterBlockPos> pos = positions();
List<Movement> movements = movements();
for (int i = 0; i < pos.size(); i++) {
if (currentPosition.equals(pos.get(i))) {
return movements.get(i);
}
}
throw new UnsupportedOperationException(currentPosition + " not in path");
}
/**
* Determines whether or not a position is within this path.
*
* @param pos The position to check
* @return Whether or not the specified position is in this class
*/
default boolean isInPath(BlockPos pos) {
return positions().contains(pos);
}
default Tuple<Double, BlockPos> closestPathPos(double x, double y, double z) {
double best = -1;
BlockPos bestPos = null;
@ -146,7 +119,7 @@ public interface IPath extends Helper {
}
double factor = Baritone.settings().pathCutoffFactor.get();
int newLength = (int) (length() * factor);
//logDebug("Static cutoff " + length() + " to " + newLength);
logDebug("Static cutoff " + length() + " to " + newLength);
return new CutoffPath(this, newLength);
}
}

View File

@ -291,6 +291,19 @@ public class PathExecutor implements Helper {
}
Movement movement = path.movements().get(pathPosition);
if (movement instanceof MovementDescend && pathPosition < path.length() - 2) {
BlockPos descendStart = movement.getSrc();
BlockPos descendEnd = movement.getDest();
BlockPos into = descendEnd.subtract(descendStart.down()).add(descendEnd);
if (into.getY() != descendEnd.getY()) {
throw new IllegalStateException(); // sanity check
}
for (int i = 0; i <= 2; i++) {
if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(into.up(i)))) {
logDebug("Sprinting would be unsafe");
player().setSprinting(false);
return;
}
}
Movement next = path.movements().get(pathPosition + 1);
if (next instanceof MovementDescend) {
if (next.getDirection().equals(movement.getDirection())) {