Class AbstractPathJob
java.lang.Object
com.minecolonies.core.entity.pathfinding.pathjobs.AbstractPathJob
- Direct Known Subclasses:
PathJobCanSee,PathJobEscapeWater,PathJobFindTree,PathJobFindWater,PathJobMoveAwayFromLocation,PathJobMoveCloseToXNearY,PathJobMoveToLocation,PathJobMoveTowards,PathJobPathway,PathJobRaiderPathing,PathJobRandomPos,PathJobWalkRandomEdge
public abstract class AbstractPathJob
extends Object
implements Callable<net.minecraft.world.level.pathfinder.Path>, IPathJob
Abstract class for Jobs that run in the multithreaded path finder.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CachingBlockLookupCached block lookupprotected booleanDebug settingsprotected @Nullable net.minecraft.world.entity.MobThe entity this job belongs to, can be noneintAdditional nodes that get explored when reaching the target, useful when the destination is an area or not in a great spot.protected doubleHeuristic modifierstatic final intMaximium amount of nodes exploredprotected intMaximum nodes we can visit.protected final PathResultThe result of the path calculation.protected final @NotNull net.minecraft.core.BlockPosStart position to path from.protected net.minecraft.core.BlockPos.MutableBlockPosMutable pos used ot retrieve world info directlyprotected intprotected final @NotNull net.minecraft.world.level.LevelReaderThe pathing cache. -
Constructor Summary
ConstructorsModifierConstructorDescriptionAbstractPathJob(net.minecraft.world.level.Level world, @NotNull net.minecraft.core.BlockPos start, int range, PathResult result, @Nullable net.minecraft.world.entity.Mob entity) AbstractPathJob constructor.AbstractPathJob(net.minecraft.world.level.Level world, @NotNull net.minecraft.core.BlockPos start, @NotNull net.minecraft.core.BlockPos end, PathResult result, @Nullable net.minecraft.world.entity.Mob entity) AbstractPathJob constructor.protectedAbstractPathJob(net.minecraft.world.level.Level actualWorld, net.minecraft.world.level.LevelReader chunkCache, @NotNull net.minecraft.core.BlockPos start, int range, PathResult result, @Nullable net.minecraft.world.entity.Mob entity) Internal constructor, for secondary pathjobs within another one -
Method Summary
Modifier and TypeMethodDescriptionfinal net.minecraft.world.level.pathfinder.Pathcall()Callable method for initiating asynchronous task.protected doublecomputeCost(MNode parent, int dX, int dY, int dZ, boolean isSwimming, boolean onPath, boolean isDiving, boolean onRails, boolean railsExit, boolean swimStart, boolean ladder, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.block.state.BlockState below, int x, int y, int z) Compute the cost (immediate 'g' value) of moving from the parent space to the new space.protected abstract doublecomputeHeuristic(int x, int y, int z) Compute the heuristic cost ('h' value) of a given position x,y,z.protected final voidexploreInDirection(MNode node, int dX, int dY, int dZ) "Walk" from the parent in the direction specified by the delta, determining the new x,y,z position for such a move and adding or updating a node, as appropriate.net.minecraft.world.level.Levelprotected doubleCalculates a score for potential points where the path may end given no destination By default the heuristic for the closest node is usednet.minecraft.world.entity.Mobprotected intgetGroundHeight(MNode node, int x, int y, int z) Get the height of the ground at the given x,z coordinate, within 1 step of y.Get the pathing options used for this jobGet the path result holder for this jobnet.minecraft.core.BlockPosgetStart()protected voidhandleDebugOptions(MNode node) Handles debugging for a given nodevoidInitializes debug trackingprotected abstract booleanReturn true if the given node is a viable final destination, and the path should generate to here.protected booleanisPassable(int x, int y, int z, boolean head, MNode parent) Checks passabilityprotected booleanisPassable(@NotNull net.minecraft.world.level.block.state.BlockState block, int x, int y, int z, MNode parent, boolean head) Is the space passable.protected doublemodifyCost(double cost, MNode parent, boolean swimstart, boolean swimming, int x, int y, int z, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.block.state.BlockState below) Modifies costs if needed for a nodeprotected @Nullable net.minecraft.world.level.pathfinder.Pathsearch()Perform the search.voidsetPathingOptions(PathingOptions pathingOptions) Sets the pathing optionsprotected booleanstopOnNodeLimit(int totalNodesVisited, MNode bestNode, int nodesSinceEndNode) Stops the pathjob when hitting a node limitvoidSync the path to the client.toString()protected voidVisits the given node and explores neighbours
-
Field Details
-
MAX_NODES
public static final int MAX_NODESMaximium amount of nodes explored- See Also:
-
start
@NotNull protected final @NotNull net.minecraft.core.BlockPos startStart position to path from. -
world
@NotNull protected final @NotNull net.minecraft.world.level.LevelReader worldThe pathing cache. -
entity
@Nullable protected @Nullable net.minecraft.world.entity.Mob entityThe entity this job belongs to, can be none -
cachedBlockLookup
Cached block lookup -
tempWorldPos
protected net.minecraft.core.BlockPos.MutableBlockPos tempWorldPosMutable pos used ot retrieve world info directly -
result
The result of the path calculation. -
maxNodes
protected int maxNodesMaximum nodes we can visit. -
totalNodesVisited
protected int totalNodesVisited -
extraNodes
public int extraNodesAdditional nodes that get explored when reaching the target, useful when the destination is an area or not in a great spot. Pathjobs may increase this value as they see fit -
debugDrawEnabled
protected boolean debugDrawEnabledDebug settings -
debugNodesVisited
-
debugNodesVisitedLater
-
debugNodesNotVisited
-
debugNodesPath
-
debugNodesOrgPath
-
debugNodesExtra
-
heuristicMod
protected double heuristicModHeuristic modifier
-
-
Constructor Details
-
AbstractPathJob
public AbstractPathJob(net.minecraft.world.level.Level world, @NotNull @NotNull net.minecraft.core.BlockPos start, int range, PathResult result, @Nullable @Nullable net.minecraft.world.entity.Mob entity) AbstractPathJob constructor.- Parameters:
world- the world within which to path.start- the start position from which to path from.range- estimated maximum path range.result- path result.entity- the entity.
-
AbstractPathJob
protected AbstractPathJob(net.minecraft.world.level.Level actualWorld, net.minecraft.world.level.LevelReader chunkCache, @NotNull @NotNull net.minecraft.core.BlockPos start, int range, PathResult result, @Nullable @Nullable net.minecraft.world.entity.Mob entity) Internal constructor, for secondary pathjobs within another one- Parameters:
chunkCache-start-range-result-entity-
-
AbstractPathJob
public AbstractPathJob(net.minecraft.world.level.Level world, @NotNull @NotNull net.minecraft.core.BlockPos start, @NotNull @NotNull net.minecraft.core.BlockPos end, PathResult result, @Nullable @Nullable net.minecraft.world.entity.Mob entity) AbstractPathJob constructor.- Parameters:
world- the world within which to path.start- the start position from which to path from.result- path result.entity- the entity.
-
-
Method Details
-
call
public final net.minecraft.world.level.pathfinder.Path call()Callable method for initiating asynchronous task. -
search
@Nullable protected @Nullable net.minecraft.world.level.pathfinder.Path search()Perform the search.- Returns:
- Path of a path to the given location, a best-effort, or null.
-
stopOnNodeLimit
Stops the pathjob when hitting a node limit- Parameters:
totalNodesVisited-bestNode-nodesSinceEndNode-- Returns:
-
visitNode
Visits the given node and explores neighbours- Parameters:
node-
-
exploreInDirection
"Walk" from the parent in the direction specified by the delta, determining the new x,y,z position for such a move and adding or updating a node, as appropriate.- Parameters:
node- Node being walked from.
-
computeHeuristic
protected abstract double computeHeuristic(int x, int y, int z) Compute the heuristic cost ('h' value) of a given position x,y,z.Returning a value of 0 performs a breadth-first search. Returning a value less than actual possible cost to goal guarantees shortest path, but at computational expense. Returning a value exactly equal to the cost to the goal guarantees shortest path and least expense (but generally. only works when path is straight and unblocked). Returning a value greater than the actual cost to goal produces good, but not perfect paths, and is fast. Returning a very high value (such that 'h' is very high relative to 'g') then only 'h' (the heuristic) matters as the search will be a very fast greedy best-first-search, ignoring cost weighting and distance.
- Returns:
- the heuristic.
-
isAtDestination
Return true if the given node is a viable final destination, and the path should generate to here.- Parameters:
n- Node to test.- Returns:
- true if the node is a viable destination.
-
getEndNodeScore
Calculates a score for potential points where the path may end given no destination By default the heuristic for the closest node is used- Parameters:
n- Node to test.- Returns:
- score for the node, lower is better
-
computeCost
protected double computeCost(MNode parent, int dX, int dY, int dZ, boolean isSwimming, boolean onPath, boolean isDiving, boolean onRails, boolean railsExit, boolean swimStart, boolean ladder, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.block.state.BlockState below, int x, int y, int z) Compute the cost (immediate 'g' value) of moving from the parent space to the new space.- Parameters:
parent-isSwimming- true is the current node would require the citizen to swim.onPath- checks if the node is on a path.onRails- checks if the node is a rail block.railsExit- the exit of the rails.swimStart- if its the swim start.state- the blockstate- Returns:
- cost to move from the parent to the new position.
-
modifyCost
protected double modifyCost(double cost, MNode parent, boolean swimstart, boolean swimming, int x, int y, int z, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.block.state.BlockState below) Modifies costs if needed for a node- Parameters:
cost-parent-swimstart-swimming-blockState-state-- Returns:
-
getGroundHeight
Get the height of the ground at the given x,z coordinate, within 1 step of y.- Parameters:
node- parent node.- Returns:
- y height of first open, viable block above ground, or -1 if blocked or too far a drop.
-
isPassable
protected boolean isPassable(@NotNull @NotNull net.minecraft.world.level.block.state.BlockState block, int x, int y, int z, MNode parent, boolean head) Is the space passable.- Parameters:
block- the block we are checking.parent- the parent node.head- the head position.- Returns:
- true if the block does not block movement.
-
isPassable
Checks passability- Parameters:
x-y-z-head-parent-- Returns:
-
initDebug
public void initDebug()Initializes debug tracking -
handleDebugOptions
Handles debugging for a given node- Parameters:
node-
-
syncDebug
Sync the path to the client. -
getResult
Description copied from interface:IPathJobGet the path result holder for this job -
setPathingOptions
Sets the pathing options- Parameters:
pathingOptions- the pathing options to set.
-
getPathingOptions
Description copied from interface:IPathJobGet the pathing options used for this job- Specified by:
getPathingOptionsin interfaceIPathJob- Returns:
-
getEntity
public net.minecraft.world.entity.Mob getEntity() -
getActualWorld
public net.minecraft.world.level.Level getActualWorld()- Specified by:
getActualWorldin interfaceIPathJob
-
getStart
public net.minecraft.core.BlockPos getStart() -
toString
-