1
0
mirror of https://github.com/cabaletta/baritone synced 2024-12-26 00:42:26 +00:00

better encapsulation of currentlyRunning

This commit is contained in:
Leijurv 2018-09-19 14:39:57 -07:00
parent ef55d86913
commit 2375f1a408
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 3 additions and 7 deletions

View File

@ -72,7 +72,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
}
CalculationContext calcContext = new CalculationContext();
HashSet<BetterBlockPos> favored = favoredPositions.orElse(null);
currentlyRunning = this;
CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
BlockStateInterface.clearCachedChunk();
@ -103,7 +102,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
BetterBlockPos currentNodePos = currentNode.pos;
numNodes++;
if (goal.isInGoal(currentNodePos)) {
currentlyRunning = null;
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
return Optional.of(new Path(startNode, currentNode, numNodes, goal));
}
@ -177,7 +175,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
}
}
if (cancelRequested) {
currentlyRunning = null;
return Optional.empty();
}
System.out.println(numMovementsConsidered + " movements considered");
@ -200,13 +197,11 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
System.out.println("But I'm going to do it anyway, because yolo");
}
System.out.println("Path goes for " + Math.sqrt(dist) + " blocks");
currentlyRunning = null;
return Optional.of(new Path(startNode, bestSoFar[i], numNodes, goal));
}
}
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
logDebug("No path found =(");
currentlyRunning = null;
return Optional.empty();
}

View File

@ -36,7 +36,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
/**
* The currently running search task
*/
protected static AbstractNodeCostSearch currentlyRunning = null;
private static AbstractNodeCostSearch currentlyRunning = null;
protected final BetterBlockPos start;
@ -55,7 +55,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
private volatile boolean isFinished;
protected boolean cancelRequested;
protected volatile boolean cancelRequested;
/**
* This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so
@ -85,6 +85,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
}
this.cancelRequested = false;
try {
currentlyRunning = this;
Optional<IPath> path = calculate0(timeout);
path.ifPresent(IPath::postprocess);
isFinished = true;