This commit is contained in:
parent
810b92fbad
commit
41ffd4455d
@ -187,6 +187,14 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean safeToCancel() {
|
||||
return safeToCancel(currentState);
|
||||
}
|
||||
|
||||
protected boolean safeToCancel(MovementState currentState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return (currentState.getStatus() != MovementStatus.RUNNING
|
||||
&& currentState.getStatus() != MovementStatus.PREPPING
|
||||
|
@ -111,6 +111,11 @@ public class MovementFall extends Movement {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean safeToCancel(MovementState state) {
|
||||
return state.getStatus() != MovementStatus.RUNNING;
|
||||
}
|
||||
|
||||
private static BetterBlockPos[] buildPositionsToBreak(BetterBlockPos src, BetterBlockPos dest) {
|
||||
BetterBlockPos[] toBreak;
|
||||
int diffX = src.getX() - dest.getX();
|
||||
|
@ -221,12 +221,13 @@ public class PathExecutor implements Helper {
|
||||
System.out.println("Recalculating break and place took " + (end - start) + "ms");
|
||||
}
|
||||
Movement movement = path.movements().get(pathPosition);
|
||||
boolean canCancel = movement.safeToCancel();
|
||||
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
||||
costEstimateIndex = pathPosition;
|
||||
// do this only once, when the movement starts, and deliberately get the cost as cached when this path was calculated, not the cost as it is right now
|
||||
currentMovementOriginalCostEstimate = movement.getCost(null);
|
||||
for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) {
|
||||
if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF) {
|
||||
if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF && canCancel) {
|
||||
logDebug("Something has changed in the world and a future movement has become impossible. Cancelling.");
|
||||
cancel();
|
||||
return true;
|
||||
@ -234,12 +235,12 @@ public class PathExecutor implements Helper {
|
||||
}
|
||||
}
|
||||
double currentCost = movement.recalculateCost();
|
||||
if (currentCost >= ActionCosts.COST_INF) {
|
||||
if (currentCost >= ActionCosts.COST_INF && canCancel) {
|
||||
logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
|
||||
cancel();
|
||||
return true;
|
||||
}
|
||||
if (!movement.calculatedWhileLoaded() && currentCost - currentMovementOriginalCostEstimate > Baritone.settings().maxCostIncrease.get()) {
|
||||
if (!movement.calculatedWhileLoaded() && currentCost - currentMovementOriginalCostEstimate > Baritone.settings().maxCostIncrease.get() && canCancel) {
|
||||
logDebug("Original cost " + currentMovementOriginalCostEstimate + " current cost " + currentCost + ". Cancelling.");
|
||||
cancel();
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user