only fail on movement cost increase if calced through cached, fixes #165

This commit is contained in:
Leijurv 2018-09-13 16:18:26 -07:00
parent 924cea342b
commit e3830643f6
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 35 additions and 2 deletions

View File

@ -83,6 +83,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
this.cancelRequested = false;
try {
Optional<IPath> path = calculate0(timeout);
path.ifPresent(IPath::postprocess);
isFinished = true;
return path;
} catch (Exception e) {

View File

@ -54,6 +54,8 @@ class Path implements IPath {
private final int numNodes;
private volatile boolean verified;
Path(PathNode start, PathNode end, int numNodes) {
this.start = start.pos;
this.end = end.pos;
@ -61,7 +63,6 @@ class Path implements IPath {
this.path = new ArrayList<>();
this.movements = new ArrayList<>();
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
public List<Movement> movements() {
if (!verified) {
throw new IllegalStateException();
}
return Collections.unmodifiableList(movements);
}

View File

@ -26,6 +26,7 @@ import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.chunk.EmptyChunk;
import java.util.ArrayList;
import java.util.Arrays;
@ -290,6 +291,16 @@ public abstract class Movement implements Helper, MovementHelper {
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> toPlaceCached = null;
public List<BlockPos> toWalkIntoCached = null;

View File

@ -49,6 +49,12 @@ public interface IPath extends Helper {
*/
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
*

View File

@ -236,7 +236,7 @@ public class PathExecutor implements Helper {
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
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.");
pathPosition = path.length() + 3;
failed = true;