only fail on movement cost increase if calced through cached, fixes #165
This commit is contained in:
parent
924cea342b
commit
e3830643f6
@ -83,6 +83,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
this.cancelRequested = false;
|
this.cancelRequested = false;
|
||||||
try {
|
try {
|
||||||
Optional<IPath> path = calculate0(timeout);
|
Optional<IPath> path = calculate0(timeout);
|
||||||
|
path.ifPresent(IPath::postprocess);
|
||||||
isFinished = true;
|
isFinished = true;
|
||||||
return path;
|
return path;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -54,6 +54,8 @@ class Path implements IPath {
|
|||||||
|
|
||||||
private final int numNodes;
|
private final int numNodes;
|
||||||
|
|
||||||
|
private volatile boolean verified;
|
||||||
|
|
||||||
Path(PathNode start, PathNode end, int numNodes) {
|
Path(PathNode start, PathNode end, int numNodes) {
|
||||||
this.start = start.pos;
|
this.start = start.pos;
|
||||||
this.end = end.pos;
|
this.end = end.pos;
|
||||||
@ -61,7 +63,6 @@ class Path implements IPath {
|
|||||||
this.path = new ArrayList<>();
|
this.path = new ArrayList<>();
|
||||||
this.movements = new ArrayList<>();
|
this.movements = new ArrayList<>();
|
||||||
assemblePath(start, end);
|
assemblePath(start, end);
|
||||||
sanityCheck();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,8 +117,22 @@ class Path implements IPath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postprocess() {
|
||||||
|
if (verified) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
verified = true;
|
||||||
|
// more post processing here
|
||||||
|
movements.forEach(Movement::checkLoadedChunk);
|
||||||
|
sanityCheck();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Movement> movements() {
|
public List<Movement> movements() {
|
||||||
|
if (!verified) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
return Collections.unmodifiableList(movements);
|
return Collections.unmodifiableList(movements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import baritone.utils.pathing.BetterBlockPos;
|
|||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -290,6 +291,16 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
return getDest().subtract(getSrc());
|
return getDest().subtract(getSrc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Boolean calculatedWhileLoaded;
|
||||||
|
|
||||||
|
public void checkLoadedChunk() {
|
||||||
|
calculatedWhileLoaded = !(world().getChunk(getDest()) instanceof EmptyChunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean calculatedWhileLoaded() {
|
||||||
|
return calculatedWhileLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
public List<BlockPos> toBreakCached = null;
|
public List<BlockPos> toBreakCached = null;
|
||||||
public List<BlockPos> toPlaceCached = null;
|
public List<BlockPos> toPlaceCached = null;
|
||||||
public List<BlockPos> toWalkIntoCached = null;
|
public List<BlockPos> toWalkIntoCached = null;
|
||||||
|
@ -49,6 +49,12 @@ public interface IPath extends Helper {
|
|||||||
*/
|
*/
|
||||||
List<BetterBlockPos> positions();
|
List<BetterBlockPos> positions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This path is actually going to be executed in the world. Do whatever additional processing is required.
|
||||||
|
* (as opposed to Path objects that are just constructed every frame for rendering)
|
||||||
|
*/
|
||||||
|
default void postprocess() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of positions in this path
|
* Number of positions in this path
|
||||||
*
|
*
|
||||||
|
@ -236,7 +236,7 @@ public class PathExecutor implements Helper {
|
|||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (currentCost - currentMovementInitialCostEstimate > Baritone.settings().maxCostIncrease.get()) {
|
if (!movement.calculatedWhileLoaded() && currentCost - currentMovementInitialCostEstimate > Baritone.settings().maxCostIncrease.get()) {
|
||||||
logDebug("Original cost " + currentMovementInitialCostEstimate + " current cost " + currentCost + ". Cancelling.");
|
logDebug("Original cost " + currentMovementInitialCostEstimate + " current cost " + currentCost + ". Cancelling.");
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
failed = true;
|
failed = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user