improve path safety
This commit is contained in:
@@ -40,7 +40,7 @@ import java.awt.*;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class PathingBehavior extends Behavior {
|
public final class PathingBehavior extends Behavior {
|
||||||
|
|
||||||
public static final PathingBehavior INSTANCE = new PathingBehavior();
|
public static final PathingBehavior INSTANCE = new PathingBehavior();
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
@Override
|
@Override
|
||||||
public void onTick(TickEvent event) {
|
public void onTick(TickEvent event) {
|
||||||
if (event.getType() == TickEvent.Type.OUT) {
|
if (event.getType() == TickEvent.Type.OUT) {
|
||||||
this.cancel();
|
softCancel(); // no player, so can't fix capabilities
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
@@ -191,11 +191,15 @@ public class PathingBehavior extends Behavior {
|
|||||||
return Optional.ofNullable(current).map(PathExecutor::getPath);
|
return Optional.ofNullable(current).map(PathExecutor::getPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
private void softCancel() {
|
||||||
current = null;
|
current = null;
|
||||||
next = null;
|
next = null;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel);
|
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
softCancel();
|
||||||
mc.playerController.setPlayerCapabilities(mc.player);
|
mc.playerController.setPlayerCapabilities(mc.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,33 +58,6 @@ public interface IPath extends Helper {
|
|||||||
return positions().size();
|
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) {
|
default Tuple<Double, BlockPos> closestPathPos(double x, double y, double z) {
|
||||||
double best = -1;
|
double best = -1;
|
||||||
BlockPos bestPos = null;
|
BlockPos bestPos = null;
|
||||||
@@ -146,7 +119,7 @@ public interface IPath extends Helper {
|
|||||||
}
|
}
|
||||||
double factor = Baritone.settings().pathCutoffFactor.get();
|
double factor = Baritone.settings().pathCutoffFactor.get();
|
||||||
int newLength = (int) (length() * factor);
|
int newLength = (int) (length() * factor);
|
||||||
//logDebug("Static cutoff " + length() + " to " + newLength);
|
logDebug("Static cutoff " + length() + " to " + newLength);
|
||||||
return new CutoffPath(this, newLength);
|
return new CutoffPath(this, newLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -291,6 +291,19 @@ public class PathExecutor implements Helper {
|
|||||||
}
|
}
|
||||||
Movement movement = path.movements().get(pathPosition);
|
Movement movement = path.movements().get(pathPosition);
|
||||||
if (movement instanceof MovementDescend && pathPosition < path.length() - 2) {
|
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);
|
Movement next = path.movements().get(pathPosition + 1);
|
||||||
if (next instanceof MovementDescend) {
|
if (next instanceof MovementDescend) {
|
||||||
if (next.getDirection().equals(movement.getDirection())) {
|
if (next.getDirection().equals(movement.getDirection())) {
|
||||||
|
Reference in New Issue
Block a user