use of baritone.pathing.path.PathExecutor in project baritone by cabaletta.
the class PathingBehavior method findPathInNewThread.
/**
* In a new thread, pathfind to target blockpos
*
* @param start
* @param talkAboutIt
*/
private void findPathInNewThread(final BlockPos start, final boolean talkAboutIt, CalculationContext context) {
// actually, we can check this, muahaha
if (!Thread.holdsLock(pathCalcLock)) {
throw new IllegalStateException("Must be called with synchronization on pathCalcLock");
// why do it this way? it's already indented so much that putting the whole thing in a synchronized(pathCalcLock) was just too much lol
}
if (inProgress != null) {
// should have been checked by caller
throw new IllegalStateException("Already doing it");
}
if (!context.safeForThreadedUse) {
throw new IllegalStateException("Improper context thread safety level");
}
Goal goal = this.goal;
if (goal == null) {
// TODO should this be an exception too? definitely should be checked by caller
logDebug("no goal");
return;
}
long primaryTimeout;
long failureTimeout;
if (current == null) {
primaryTimeout = Baritone.settings().primaryTimeoutMS.value;
failureTimeout = Baritone.settings().failureTimeoutMS.value;
} else {
primaryTimeout = Baritone.settings().planAheadPrimaryTimeoutMS.value;
failureTimeout = Baritone.settings().planAheadFailureTimeoutMS.value;
}
AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context);
if (!Objects.equals(pathfinder.getGoal(), goal)) {
// will return the exact same object if simplification didn't happen
logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance");
}
inProgress = pathfinder;
Baritone.getExecutor().execute(() -> {
if (talkAboutIt) {
logDebug("Starting to search for path from " + start + " to " + goal);
}
PathCalculationResult calcResult = pathfinder.calculate(primaryTimeout, failureTimeout);
synchronized (pathPlanLock) {
Optional<PathExecutor> executor = calcResult.getPath().map(p -> new PathExecutor(PathingBehavior.this, p));
if (current == null) {
if (executor.isPresent()) {
if (executor.get().getPath().positions().contains(expectedSegmentStart)) {
queuePathEvent(PathEvent.CALC_FINISHED_NOW_EXECUTING);
current = executor.get();
resetEstimatedTicksToGoal(start);
} else {
logDebug("Warning: discarding orphan path segment with incorrect start");
}
} else {
if (calcResult.getType() != PathCalculationResult.Type.CANCELLATION && calcResult.getType() != PathCalculationResult.Type.EXCEPTION) {
// don't dispatch CALC_FAILED on cancellation
queuePathEvent(PathEvent.CALC_FAILED);
}
}
} else {
if (next == null) {
if (executor.isPresent()) {
if (executor.get().getPath().getSrc().equals(current.getPath().getDest())) {
queuePathEvent(PathEvent.NEXT_SEGMENT_CALC_FINISHED);
next = executor.get();
} else {
logDebug("Warning: discarding orphan next segment with incorrect start");
}
} else {
queuePathEvent(PathEvent.NEXT_CALC_FAILED);
}
} else {
// throw new IllegalStateException("I have no idea what to do with this path");
// no point in throwing an exception here, and it gets it stuck with inProgress being not null
logDirect("Warning: PathingBehaivor illegal state! Discarding invalid path!");
}
}
if (talkAboutIt && current != null && current.getPath() != null) {
if (goal.isInGoal(current.getPath().getDest())) {
logDebug("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
} else {
logDebug("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
}
}
synchronized (pathCalcLock) {
inProgress = null;
}
}
});
}
use of baritone.pathing.path.PathExecutor in project baritone by cabaletta.
the class BackfillProcess method partOfCurrentMovement.
private boolean partOfCurrentMovement(BlockPos pos) {
PathExecutor exec = baritone.getPathingBehavior().getCurrent();
if (exec == null || exec.finished() || exec.failed()) {
return false;
}
Movement movement = (Movement) exec.getPath().movements().get(exec.getPosition());
return Arrays.asList(movement.toBreakAll()).contains(pos);
}
use of baritone.pathing.path.PathExecutor in project baritone by cabaletta.
the class PathRenderer method render.
public static void render(RenderEvent event, PathingBehavior behavior) {
float partialTicks = event.getPartialTicks();
Goal goal = behavior.getGoal();
if (Helper.mc.currentScreen instanceof GuiClick) {
((GuiClick) Helper.mc.currentScreen).onRender();
}
int thisPlayerDimension = behavior.baritone.getPlayerContext().world().provider.getDimensionType().getId();
int currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().provider.getDimensionType().getId();
if (thisPlayerDimension != currentRenderViewDimension) {
// this is a path for a bot in a different dimension, don't render it
return;
}
Entity renderView = Helper.mc.getRenderViewEntity();
if (renderView.world != BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world()) {
System.out.println("I have no idea what's going on");
System.out.println("The primary baritone is in a different world than the render view entity");
System.out.println("Not rendering the path");
return;
}
if (goal != null && settings.renderGoal.value) {
drawDankLitGoalBox(renderView, goal, partialTicks, settings.colorGoalBox.value);
}
if (!settings.renderPath.value) {
return;
}
// this should prevent most race conditions?
PathExecutor current = behavior.getCurrent();
// like, now it's not possible for current!=null to be true, then suddenly false because of another thread
PathExecutor next = behavior.getNext();
if (current != null && settings.renderSelectionBoxes.value) {
drawManySelectionBoxes(renderView, current.toBreak(), settings.colorBlocksToBreak.value);
drawManySelectionBoxes(renderView, current.toPlace(), settings.colorBlocksToPlace.value);
drawManySelectionBoxes(renderView, current.toWalkInto(), settings.colorBlocksToWalkInto.value);
}
// Render the current path, if there is one
if (current != null && current.getPath() != null) {
int renderBegin = Math.max(current.getPosition() - 3, 0);
drawPath(current.getPath(), renderBegin, settings.colorCurrentPath.value, settings.fadePath.value, 10, 20);
}
if (next != null && next.getPath() != null) {
drawPath(next.getPath(), 0, settings.colorNextPath.value, settings.fadePath.value, 10, 20);
}
// If there is a path calculation currently running, render the path calculation process
behavior.getInProgress().ifPresent(currentlyRunning -> {
currentlyRunning.bestPathSoFar().ifPresent(p -> {
drawPath(p, 0, settings.colorBestPathSoFar.value, settings.fadePath.value, 10, 20);
});
currentlyRunning.pathToMostRecentNodeConsidered().ifPresent(mr -> {
drawPath(mr, 0, settings.colorMostRecentConsidered.value, settings.fadePath.value, 10, 20);
drawManySelectionBoxes(renderView, Collections.singletonList(mr.getDest()), settings.colorMostRecentConsidered.value);
});
});
}
use of baritone.pathing.path.PathExecutor in project Spark-Client by Spark-Client-Development.
the class BackfillProcess method partOfCurrentMovement.
private boolean partOfCurrentMovement(BlockPos pos) {
PathExecutor exec = baritone.getPathingBehavior().getCurrent();
if (exec == null || exec.finished() || exec.failed()) {
return false;
}
Movement movement = (Movement) exec.getPath().movements().get(exec.getPosition());
return Arrays.asList(movement.toBreakAll()).contains(pos);
}
use of baritone.pathing.path.PathExecutor in project Spark-Client by Spark-Client-Development.
the class PathRenderer method render.
public static void render(RenderEvent event, PathingBehavior behavior) {
float partialTicks = event.getPartialTicks();
Goal goal = behavior.getGoal();
if (Helper.mc.currentScreen instanceof GuiClick) {
((GuiClick) Helper.mc.currentScreen).onRender();
}
int thisPlayerDimension = behavior.baritone.getPlayerContext().world().provider.getDimensionType().getId();
int currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().provider.getDimensionType().getId();
if (thisPlayerDimension != currentRenderViewDimension) {
// this is a path for a bot in a different dimension, don't render it
return;
}
Entity renderView = Helper.mc.getRenderViewEntity();
if (renderView.world != BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world()) {
System.out.println("I have no idea what's going on");
System.out.println("The primary baritone is in a different world than the render view entity");
System.out.println("Not rendering the path");
return;
}
if (goal != null && settings.renderGoal.getValue()) {
drawDankLitGoalBox(renderView, goal, partialTicks, settings.colorGoalBox.getValue());
}
if (!settings.renderPath.getValue()) {
return;
}
// this should prevent most race conditions?
PathExecutor current = behavior.getCurrent();
// like, now it's not possible for current!=null to be true, then suddenly false because of another thread
PathExecutor next = behavior.getNext();
if (current != null && settings.renderSelectionBoxes.getValue()) {
drawManySelectionBoxes(renderView, current.toBreak(), settings.colorBlocksToBreak.getValue());
drawManySelectionBoxes(renderView, current.toPlace(), settings.colorBlocksToPlace.getValue());
drawManySelectionBoxes(renderView, current.toWalkInto(), settings.colorBlocksToWalkInto.getValue());
}
// Render the current path, if there is one
if (current != null && current.getPath() != null) {
int renderBegin = Math.max(current.getPosition() - 3, 0);
drawPath(current.getPath(), renderBegin, settings.colorCurrentPath.getValue(), settings.fadePath.getValue(), 10, 20);
}
if (next != null && next.getPath() != null) {
drawPath(next.getPath(), 0, settings.colorNextPath.getValue(), settings.fadePath.getValue(), 10, 20);
}
// If there is a path calculation currently running, render the path calculation process
behavior.getInProgress().ifPresent(currentlyRunning -> {
currentlyRunning.bestPathSoFar().ifPresent(p -> {
drawPath(p, 0, settings.colorBestPathSoFar.getValue(), settings.fadePath.getValue(), 10, 20);
});
currentlyRunning.pathToMostRecentNodeConsidered().ifPresent(mr -> {
drawPath(mr, 0, settings.colorMostRecentConsidered.getValue(), settings.fadePath.getValue(), 10, 20);
drawManySelectionBoxes(renderView, Collections.singletonList(mr.getDest()), settings.colorMostRecentConsidered.getValue());
});
});
}
Aggregations