remove that toxic cloud
This commit is contained in:
		| @@ -71,7 +71,7 @@ public interface IPathingBehavior extends IBehavior { | |||||||
|     /** |     /** | ||||||
|      * @return The current path finder being executed |      * @return The current path finder being executed | ||||||
|      */ |      */ | ||||||
|     Optional<IPathFinder> getPathFinder(); |     Optional<? extends IPathFinder> getInProgress(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @return The current path executor |      * @return The current path executor | ||||||
|   | |||||||
| @@ -24,7 +24,6 @@ import baritone.api.event.events.PlayerUpdateEvent; | |||||||
| import baritone.api.event.events.RenderEvent; | import baritone.api.event.events.RenderEvent; | ||||||
| import baritone.api.event.events.TickEvent; | import baritone.api.event.events.TickEvent; | ||||||
| import baritone.api.pathing.calc.IPath; | import baritone.api.pathing.calc.IPath; | ||||||
| import baritone.api.pathing.calc.IPathFinder; |  | ||||||
| import baritone.api.pathing.goals.Goal; | import baritone.api.pathing.goals.Goal; | ||||||
| import baritone.api.pathing.goals.GoalXZ; | import baritone.api.pathing.goals.GoalXZ; | ||||||
| import baritone.api.utils.BetterBlockPos; | import baritone.api.utils.BetterBlockPos; | ||||||
| @@ -57,7 +56,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|     private boolean cancelRequested; |     private boolean cancelRequested; | ||||||
|     private boolean calcFailedLastTick; |     private boolean calcFailedLastTick; | ||||||
|  |  | ||||||
|     private volatile boolean isPathCalcInProgress; |     private volatile AbstractNodeCostSearch inProgress; | ||||||
|     private final Object pathCalcLock = new Object(); |     private final Object pathCalcLock = new Object(); | ||||||
|  |  | ||||||
|     private final Object pathPlanLock = new Object(); |     private final Object pathPlanLock = new Object(); | ||||||
| @@ -141,7 +140,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|                 } |                 } | ||||||
|                 // at this point, current just ended, but we aren't in the goal and have no plan for the future |                 // at this point, current just ended, but we aren't in the goal and have no plan for the future | ||||||
|                 synchronized (pathCalcLock) { |                 synchronized (pathCalcLock) { | ||||||
|                     if (isPathCalcInProgress) { |                     if (inProgress != null) { | ||||||
|                         queuePathEvent(PathEvent.PATH_FINISHED_NEXT_STILL_CALCULATING); |                         queuePathEvent(PathEvent.PATH_FINISHED_NEXT_STILL_CALCULATING); | ||||||
|                         // if we aren't calculating right now |                         // if we aren't calculating right now | ||||||
|                         return; |                         return; | ||||||
| @@ -166,7 +165,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|                 next = null; |                 next = null; | ||||||
|             } |             } | ||||||
|             synchronized (pathCalcLock) { |             synchronized (pathCalcLock) { | ||||||
|                 if (isPathCalcInProgress) { |                 if (inProgress != null) { | ||||||
|                     // if we aren't calculating right now |                     // if we aren't calculating right now | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
| @@ -238,8 +237,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public Optional<IPathFinder> getPathFinder() { |     public Optional<AbstractNodeCostSearch> getInProgress() { | ||||||
|         return Optional.ofNullable(AbstractNodeCostSearch.currentlyRunning()); |         return Optional.ofNullable(inProgress); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -284,7 +283,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|         current = null; |         current = null; | ||||||
|         next = null; |         next = null; | ||||||
|         cancelRequested = true; |         cancelRequested = true; | ||||||
|         AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel); |         getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours | ||||||
|         // do everything BUT clear keys |         // do everything BUT clear keys | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -294,14 +293,14 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|         current = null; |         current = null; | ||||||
|         next = null; |         next = null; | ||||||
|         baritone.getInputOverrideHandler().clearAllKeys(); |         baritone.getInputOverrideHandler().clearAllKeys(); | ||||||
|         AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel); |         getInProgress().ifPresent(AbstractNodeCostSearch::cancel); | ||||||
|         baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock(); |         baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void forceCancel() { // NOT exposed on public api |     public void forceCancel() { // NOT exposed on public api | ||||||
|         cancelEverything(); |         cancelEverything(); | ||||||
|         secretInternalSegmentCancel(); |         secretInternalSegmentCancel(); | ||||||
|         isPathCalcInProgress = false; |         inProgress = null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -321,7 +320,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|                 return false; |                 return false; | ||||||
|             } |             } | ||||||
|             synchronized (pathCalcLock) { |             synchronized (pathCalcLock) { | ||||||
|                 if (isPathCalcInProgress) { |                 if (inProgress != null) { | ||||||
|                     return false; |                     return false; | ||||||
|                 } |                 } | ||||||
|                 queuePathEvent(PathEvent.CALC_STARTED); |                 queuePathEvent(PathEvent.CALC_STARTED); | ||||||
| @@ -383,19 +382,35 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|      * @param talkAboutIt |      * @param talkAboutIt | ||||||
|      */ |      */ | ||||||
|     private void findPathInNewThread(final BlockPos start, final boolean talkAboutIt, final Optional<IPath> previous) { |     private void findPathInNewThread(final BlockPos start, final boolean talkAboutIt, final Optional<IPath> previous) { | ||||||
|         synchronized (pathCalcLock) { |         // this must be called with synchronization on pathCalcLock! | ||||||
|             if (isPathCalcInProgress) { |         // actually, we can check this, muahaha | ||||||
|                 throw new IllegalStateException("Already doing it"); |         if (!Thread.holdsLock(pathCalcLock)) { | ||||||
|             } |             throw new IllegalStateException("Must be called with synchronization on pathCalcLock"); | ||||||
|             isPathCalcInProgress = true; |             // 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) { | ||||||
|  |             throw new IllegalStateException("Already doing it"); // should have been checked by caller | ||||||
|  |         } | ||||||
|  |         Goal goal = this.goal; | ||||||
|  |         if (goal == null) { | ||||||
|  |             logDebug("no goal"); // TODO should this be an exception too? definitely should be checked by caller | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         long timeout; | ||||||
|  |         if (current == null) { | ||||||
|  |             timeout = Baritone.settings().pathTimeoutMS.<Long>get(); | ||||||
|  |         } else { | ||||||
|  |             timeout = Baritone.settings().planAheadTimeoutMS.<Long>get(); | ||||||
|         } |         } | ||||||
|         CalculationContext context = new CalculationContext(baritone); // not safe to create on the other thread, it looks up a lot of stuff in minecraft |         CalculationContext context = new CalculationContext(baritone); // not safe to create on the other thread, it looks up a lot of stuff in minecraft | ||||||
|  |         AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, previous, context); | ||||||
|  |         inProgress = pathfinder; | ||||||
|         Baritone.getExecutor().execute(() -> { |         Baritone.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); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             PathCalculationResult calcResult = findPath(start, previous, context); |             PathCalculationResult calcResult = pathfinder.calculate(timeout); | ||||||
|             Optional<IPath> path = calcResult.path; |             Optional<IPath> path = calcResult.path; | ||||||
|             if (Baritone.settings().cutoffAtLoadBoundary.get()) { |             if (Baritone.settings().cutoffAtLoadBoundary.get()) { | ||||||
|                 path = path.map(p -> { |                 path = path.map(p -> { | ||||||
| @@ -453,51 +468,28 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 synchronized (pathCalcLock) { |                 synchronized (pathCalcLock) { | ||||||
|                     isPathCalcInProgress = false; |                     inProgress = null; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     private AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, Optional<IPath> previous, CalculationContext context) { | ||||||
|      * Actually do the pathing |         Goal transformed = goal; | ||||||
|      * |  | ||||||
|      * @param start |  | ||||||
|      * @return |  | ||||||
|      */ |  | ||||||
|     private PathCalculationResult findPath(BlockPos start, Optional<IPath> previous, CalculationContext context) { |  | ||||||
|         Goal goal = this.goal; |  | ||||||
|         if (goal == null) { |  | ||||||
|             logDebug("no goal"); |  | ||||||
|             return new PathCalculationResult(PathCalculationResult.Type.CANCELLATION, Optional.empty()); |  | ||||||
|         } |  | ||||||
|         if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos) { |         if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos) { | ||||||
|             BlockPos pos = ((IGoalRenderPos) goal).getGoalPos(); |             BlockPos pos = ((IGoalRenderPos) goal).getGoalPos(); | ||||||
|             if (context.world().getChunk(pos) instanceof EmptyChunk) { |             if (context.world().getChunk(pos) instanceof EmptyChunk) { | ||||||
|                 logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); |                 logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); | ||||||
|                 goal = new GoalXZ(pos.getX(), pos.getZ()); |                 transformed = new GoalXZ(pos.getX(), pos.getZ()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         long timeout; |  | ||||||
|         if (current == null) { |  | ||||||
|             timeout = Baritone.settings().pathTimeoutMS.<Long>get(); |  | ||||||
|         } else { |  | ||||||
|             timeout = Baritone.settings().planAheadTimeoutMS.<Long>get(); |  | ||||||
|         } |  | ||||||
|         Optional<HashSet<Long>> favoredPositions; |         Optional<HashSet<Long>> favoredPositions; | ||||||
|         if (Baritone.settings().backtrackCostFavoringCoefficient.get() == 1D) { |         if (Baritone.settings().backtrackCostFavoringCoefficient.get() == 1D) { | ||||||
|             favoredPositions = Optional.empty(); |             favoredPositions = Optional.empty(); | ||||||
|         } else { |         } else { | ||||||
|             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 { |         return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context); | ||||||
|             IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions, context); |  | ||||||
|             return pf.calculate(timeout); |  | ||||||
|         } catch (Exception e) { |  | ||||||
|             logDebug("Pathing exception: " + e); |  | ||||||
|             e.printStackTrace(); |  | ||||||
|             return new PathCalculationResult(PathCalculationResult.Type.EXCEPTION, Optional.empty()); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ import baritone.api.pathing.calc.IPathFinder; | |||||||
| import baritone.api.pathing.goals.Goal; | import baritone.api.pathing.goals.Goal; | ||||||
| import baritone.api.utils.PathCalculationResult; | import baritone.api.utils.PathCalculationResult; | ||||||
| import baritone.pathing.movement.CalculationContext; | import baritone.pathing.movement.CalculationContext; | ||||||
|  | import baritone.utils.Helper; | ||||||
| import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; | ||||||
|  |  | ||||||
| import java.util.Optional; | import java.util.Optional; | ||||||
| @@ -107,6 +108,10 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { | |||||||
|             } else { |             } else { | ||||||
|                 return new PathCalculationResult(PathCalculationResult.Type.SUCCESS_SEGMENT, path); |                 return new PathCalculationResult(PathCalculationResult.Type.SUCCESS_SEGMENT, path); | ||||||
|             } |             } | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             Helper.HELPER.logDebug("Pathing exception: " + e); | ||||||
|  |             e.printStackTrace(); | ||||||
|  |             return new PathCalculationResult(PathCalculationResult.Type.EXCEPTION, Optional.empty()); | ||||||
|         } finally { |         } finally { | ||||||
|             // this is run regardless of what exception may or may not be raised by calculate0 |             // this is run regardless of what exception may or may not be raised by calculate0 | ||||||
|             currentlyRunning = null; |             currentlyRunning = null; | ||||||
| @@ -218,12 +223,4 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { | |||||||
|     public final Goal getGoal() { |     public final Goal getGoal() { | ||||||
|         return goal; |         return goal; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Optional<AbstractNodeCostSearch> getCurrentlyRunning() { |  | ||||||
|         return Optional.ofNullable(currentlyRunning); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static AbstractNodeCostSearch currentlyRunning() { |  | ||||||
|         return currentlyRunning; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -295,7 +295,7 @@ public class PathExecutor implements IPathExecutor, Helper { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private boolean shouldPause() { |     private boolean shouldPause() { | ||||||
|         Optional<AbstractNodeCostSearch> current = AbstractNodeCostSearch.getCurrentlyRunning(); |         Optional<AbstractNodeCostSearch> current = behavior.getInProgress(); | ||||||
|         if (!current.isPresent()) { |         if (!current.isPresent()) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -28,7 +28,6 @@ import baritone.api.pathing.goals.GoalXZ; | |||||||
| import baritone.api.utils.BetterBlockPos; | import baritone.api.utils.BetterBlockPos; | ||||||
| import baritone.api.utils.interfaces.IGoalRenderPos; | import baritone.api.utils.interfaces.IGoalRenderPos; | ||||||
| import baritone.behavior.PathingBehavior; | import baritone.behavior.PathingBehavior; | ||||||
| import baritone.pathing.calc.AbstractNodeCostSearch; |  | ||||||
| import baritone.pathing.path.PathExecutor; | import baritone.pathing.path.PathExecutor; | ||||||
| import net.minecraft.block.state.IBlockState; | import net.minecraft.block.state.IBlockState; | ||||||
| import net.minecraft.client.renderer.BufferBuilder; | import net.minecraft.client.renderer.BufferBuilder; | ||||||
| @@ -113,7 +112,7 @@ public final class PathRenderer implements Helper { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // If there is a path calculation currently running, render the path calculation process |         // If there is a path calculation currently running, render the path calculation process | ||||||
|         AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(currentlyRunning -> { |         behavior.getInProgress().ifPresent(currentlyRunning -> { | ||||||
|             currentlyRunning.bestPathSoFar().ifPresent(p -> { |             currentlyRunning.bestPathSoFar().ifPresent(p -> { | ||||||
|                 drawPath(p, 0, renderView, partialTicks, Baritone.settings().colorBestPathSoFar.get(), Baritone.settings().fadePath.get(), 10, 20); |                 drawPath(p, 0, renderView, partialTicks, Baritone.settings().colorBestPathSoFar.get(), Baritone.settings().fadePath.get(), 10, 20); | ||||||
|             }); |             }); | ||||||
|   | |||||||
| @@ -24,7 +24,6 @@ import baritone.api.pathing.goals.Goal; | |||||||
| import baritone.api.process.IBaritoneProcess; | import baritone.api.process.IBaritoneProcess; | ||||||
| import baritone.api.process.PathingCommand; | import baritone.api.process.PathingCommand; | ||||||
| import baritone.behavior.PathingBehavior; | import baritone.behavior.PathingBehavior; | ||||||
| import baritone.pathing.calc.AbstractNodeCostSearch; |  | ||||||
| import baritone.pathing.path.PathExecutor; | import baritone.pathing.path.PathExecutor; | ||||||
| import net.minecraft.util.math.BlockPos; | import net.minecraft.util.math.BlockPos; | ||||||
|  |  | ||||||
| @@ -90,12 +89,12 @@ public class PathingControlManager { | |||||||
|                 p.cancelSegmentIfSafe(); |                 p.cancelSegmentIfSafe(); | ||||||
|                 break; |                 break; | ||||||
|             case FORCE_REVALIDATE_GOAL_AND_PATH: |             case FORCE_REVALIDATE_GOAL_AND_PATH: | ||||||
|                 if (!p.isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) { |                 if (!p.isPathing() && !p.getInProgress().isPresent()) { | ||||||
|                     p.secretInternalSetGoalAndPath(command.goal); |                     p.secretInternalSetGoalAndPath(command.goal); | ||||||
|                 } |                 } | ||||||
|                 break; |                 break; | ||||||
|             case REVALIDATE_GOAL_AND_PATH: |             case REVALIDATE_GOAL_AND_PATH: | ||||||
|                 if (!p.isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) { |                 if (!p.isPathing() && !p.getInProgress().isPresent()) { | ||||||
|                     p.secretInternalSetGoalAndPath(command.goal); |                     p.secretInternalSetGoalAndPath(command.goal); | ||||||
|                 } |                 } | ||||||
|                 break; |                 break; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user