move calculation context construction to main thread
This commit is contained in:
parent
19ecb1bbb3
commit
b9b33b5351
@ -32,6 +32,7 @@ import baritone.api.utils.interfaces.IGoalRenderPos;
|
|||||||
import baritone.pathing.calc.AStarPathFinder;
|
import baritone.pathing.calc.AStarPathFinder;
|
||||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
import baritone.pathing.calc.CutoffPath;
|
import baritone.pathing.calc.CutoffPath;
|
||||||
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
import baritone.utils.BlockBreakHelper;
|
import baritone.utils.BlockBreakHelper;
|
||||||
@ -325,12 +326,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
}
|
}
|
||||||
isPathCalcInProgress = true;
|
isPathCalcInProgress = true;
|
||||||
}
|
}
|
||||||
|
CalculationContext context = new CalculationContext(); // not safe to create on the other thread, it looks up a lot of stuff in minecraft
|
||||||
Baritone.INSTANCE.getExecutor().execute(() -> {
|
Baritone.INSTANCE.getExecutor().execute(() -> {
|
||||||
if (talkAboutIt) {
|
if (talkAboutIt) {
|
||||||
logDebug("Starting to search for path from " + start + " to " + goal);
|
logDebug("Starting to search for path from " + start + " to " + goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<IPath> path = findPath(start, previous);
|
Optional<IPath> path = findPath(start, previous, context);
|
||||||
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
|
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
|
||||||
path = path.map(p -> {
|
path = path.map(p -> {
|
||||||
IPath result = p.cutoffAtLoadedChunks();
|
IPath result = p.cutoffAtLoadedChunks();
|
||||||
@ -398,7 +400,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
* @param start
|
* @param start
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Optional<IPath> findPath(BlockPos start, Optional<IPath> previous) {
|
private Optional<IPath> findPath(BlockPos start, Optional<IPath> previous, CalculationContext context) {
|
||||||
Goal goal = this.goal;
|
Goal goal = this.goal;
|
||||||
if (goal == null) {
|
if (goal == null) {
|
||||||
logDebug("no goal");
|
logDebug("no goal");
|
||||||
@ -428,7 +430,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
favoredPositions = previous.map(IPath::positions).map(Collection::stream).map(x -> x.map(BetterBlockPos::longHash)).map(x -> x.collect(Collectors.toList())).map(HashSet::new); // <-- okay this is EPIC
|
favoredPositions = previous.map(IPath::positions).map(Collection::stream).map(x -> x.map(BetterBlockPos::longHash)).map(x -> x.collect(Collectors.toList())).map(HashSet::new); // <-- okay this is EPIC
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions);
|
IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions, context);
|
||||||
return pf.calculate(timeout);
|
return pf.calculate(timeout);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logDebug("Pathing exception: " + e);
|
logDebug("Pathing exception: " + e);
|
||||||
|
@ -41,10 +41,12 @@ import java.util.Optional;
|
|||||||
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||||
|
|
||||||
private final Optional<HashSet<Long>> favoredPositions;
|
private final Optional<HashSet<Long>> favoredPositions;
|
||||||
|
private final CalculationContext calcContext;
|
||||||
|
|
||||||
public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional<HashSet<Long>> favoredPositions) {
|
public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional<HashSet<Long>> favoredPositions, CalculationContext context) {
|
||||||
super(startX, startY, startZ, goal);
|
super(startX, startY, startZ, goal);
|
||||||
this.favoredPositions = favoredPositions;
|
this.favoredPositions = favoredPositions;
|
||||||
|
this.calcContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,7 +63,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
bestHeuristicSoFar[i] = startNode.estimatedCostToGoal;
|
bestHeuristicSoFar[i] = startNode.estimatedCostToGoal;
|
||||||
bestSoFar[i] = startNode;
|
bestSoFar[i] = startNode;
|
||||||
}
|
}
|
||||||
CalculationContext calcContext = new CalculationContext();
|
|
||||||
MutableMoveResult res = new MutableMoveResult();
|
MutableMoveResult res = new MutableMoveResult();
|
||||||
HashSet<Long> favored = favoredPositions.orElse(null);
|
HashSet<Long> favored = favoredPositions.orElse(null);
|
||||||
BetterWorldBorder worldBorder = new BetterWorldBorder(world().getWorldBorder());
|
BetterWorldBorder worldBorder = new BetterWorldBorder(world().getWorldBorder());
|
||||||
|
Loading…
Reference in New Issue
Block a user