Class AbstractPathJob

java.lang.Object
com.minecolonies.core.entity.pathfinding.pathjobs.AbstractPathJob
All Implemented Interfaces:
IPathJob, Callable<net.minecraft.world.level.pathfinder.Path>
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

    Fields
    Modifier and Type
    Field
    Description
    Cached block lookup
    protected boolean
    Debug settings
    protected Set<MNode>
     
    protected Set<MNode>
     
    protected Set<MNode>
     
    protected Set<MNode>
     
    protected Set<MNode>
     
    protected Set<MNode>
     
    protected @Nullable net.minecraft.world.entity.Mob
    The entity this job belongs to, can be none
    int
    Additional nodes that get explored when reaching the target, useful when the destination is an area or not in a great spot.
    protected double
    Heuristic modifier
    static final int
    Maximium amount of nodes explored
    protected int
    Maximum nodes we can visit.
    protected final PathResult
    The result of the path calculation.
    protected final @NotNull net.minecraft.core.BlockPos
    Start position to path from.
    protected net.minecraft.core.BlockPos.MutableBlockPos
    Mutable pos used ot retrieve world info directly
    protected int
     
    protected final @NotNull net.minecraft.world.level.LevelReader
    The pathing cache.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    AbstractPathJob(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.
    protected
    AbstractPathJob(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 Type
    Method
    Description
    final net.minecraft.world.level.pathfinder.Path
    Callable method for initiating asynchronous task.
    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.
    protected abstract double
    computeHeuristic(int x, int y, int z)
    Compute the heuristic cost ('h' value) of a given position x,y,z.
    protected final void
    exploreInDirection(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.Level
     
    protected double
    Calculates a score for potential points where the path may end given no destination By default the heuristic for the closest node is used
    net.minecraft.world.entity.Mob
     
    protected int
    getGroundHeight(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 job
    Get the path result holder for this job
    net.minecraft.core.BlockPos
     
    protected void
    Handles debugging for a given node
    void
    Initializes debug tracking
    protected abstract boolean
    Return true if the given node is a viable final destination, and the path should generate to here.
    protected boolean
    isPassable(int x, int y, int z, boolean head, MNode parent)
    Checks passability
    protected boolean
    isPassable(@NotNull net.minecraft.world.level.block.state.BlockState block, int x, int y, int z, MNode parent, boolean head)
    Is the space passable.
    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
    protected @Nullable net.minecraft.world.level.pathfinder.Path
    Perform the search.
    void
    Sets the pathing options
    protected boolean
    stopOnNodeLimit(int totalNodesVisited, MNode bestNode, int nodesSinceEndNode)
    Stops the pathjob when hitting a node limit
    void
    syncDebug(List<net.minecraft.server.level.ServerPlayer> debugWatchers)
    Sync the path to the client.
     
    protected void
    Visits the given node and explores neighbours

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_NODES

      public static final int MAX_NODES
      Maximium amount of nodes explored
      See Also:
    • start

      @NotNull protected final @NotNull net.minecraft.core.BlockPos start
      Start position to path from.
    • world

      @NotNull protected final @NotNull net.minecraft.world.level.LevelReader world
      The pathing cache.
    • entity

      @Nullable protected @Nullable net.minecraft.world.entity.Mob entity
      The entity this job belongs to, can be none
    • cachedBlockLookup

      protected CachingBlockLookup cachedBlockLookup
      Cached block lookup
    • tempWorldPos

      protected net.minecraft.core.BlockPos.MutableBlockPos tempWorldPos
      Mutable pos used ot retrieve world info directly
    • result

      protected final PathResult result
      The result of the path calculation.
    • maxNodes

      protected int maxNodes
      Maximum nodes we can visit.
    • totalNodesVisited

      protected int totalNodesVisited
    • extraNodes

      public int extraNodes
      Additional 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 debugDrawEnabled
      Debug settings
    • debugNodesVisited

      protected Set<MNode> debugNodesVisited
    • debugNodesVisitedLater

      protected Set<MNode> debugNodesVisitedLater
    • debugNodesNotVisited

      protected Set<MNode> debugNodesNotVisited
    • debugNodesPath

      protected Set<MNode> debugNodesPath
    • debugNodesOrgPath

      protected Set<MNode> debugNodesOrgPath
    • debugNodesExtra

      protected Set<MNode> debugNodesExtra
    • heuristicMod

      protected double heuristicMod
      Heuristic 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.
      Specified by:
      call in interface Callable<net.minecraft.world.level.pathfinder.Path>
      Returns:
      path to follow or null.
    • 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

      protected boolean stopOnNodeLimit(int totalNodesVisited, MNode bestNode, int nodesSinceEndNode)
      Stops the pathjob when hitting a node limit
      Parameters:
      totalNodesVisited -
      bestNode -
      nodesSinceEndNode -
      Returns:
    • visitNode

      protected void visitNode(MNode node)
      Visits the given node and explores neighbours
      Parameters:
      node -
    • exploreInDirection

      protected final void exploreInDirection(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.
      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

      protected abstract boolean isAtDestination(MNode n)
      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

      protected double getEndNodeScore(MNode n)
      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

      protected int getGroundHeight(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.
      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

      protected boolean isPassable(int x, int y, int z, boolean head, MNode parent)
      Checks passability
      Parameters:
      x -
      y -
      z -
      head -
      parent -
      Returns:
    • initDebug

      public void initDebug()
      Initializes debug tracking
    • handleDebugOptions

      protected void handleDebugOptions(MNode node)
      Handles debugging for a given node
      Parameters:
      node -
    • syncDebug

      public void syncDebug(List<net.minecraft.server.level.ServerPlayer> debugWatchers)
      Sync the path to the client.
    • getResult

      public PathResult getResult()
      Description copied from interface: IPathJob
      Get the path result holder for this job
      Specified by:
      getResult in interface IPathJob
      Returns:
    • setPathingOptions

      public void setPathingOptions(PathingOptions pathingOptions)
      Sets the pathing options
      Parameters:
      pathingOptions - the pathing options to set.
    • getPathingOptions

      public PathingOptions getPathingOptions()
      Description copied from interface: IPathJob
      Get the pathing options used for this job
      Specified by:
      getPathingOptions in interface IPathJob
      Returns:
    • getEntity

      public net.minecraft.world.entity.Mob getEntity()
      Specified by:
      getEntity in interface IPathJob
    • getActualWorld

      public net.minecraft.world.level.Level getActualWorld()
      Specified by:
      getActualWorld in interface IPathJob
    • getStart

      public net.minecraft.core.BlockPos getStart()
      Specified by:
      getStart in interface IPathJob
    • toString

      public String toString()
      Overrides:
      toString in class Object