Class NavigatorParameters

java.lang.Object
net.citizensnpcs.api.ai.NavigatorParameters
All Implemented Interfaces:
Cloneable

public class NavigatorParameters extends Object implements Cloneable
  • Constructor Details

    • NavigatorParameters

      public NavigatorParameters()
  • Method Details

    • addRunCallback

      public NavigatorParameters addRunCallback(Runnable callback)
      Adds a Runnable callback that will be called every tick while the path is running.
      Parameters:
      callback - The callback to add
    • addSingleUseCallback

      public NavigatorParameters addSingleUseCallback(NavigatorCallback callback)
      Adds a NavigatorCallback that will be removed immediately after being called.
      Parameters:
      callback - The callback
    • attackDelayTicks

      public int attackDelayTicks()
      Returns:
      The number of ticks to wait between attacks
      See Also:
    • attackDelayTicks

      public NavigatorParameters attackDelayTicks(int ticks)
      Sets the delay between attacks. When attacking a target using an aggressive target strategy, the NPC waits for a certain number of ticks between attacks to avoid spamming damage to the target. This determines the number of ticks to wait.
      Parameters:
      ticks - The new number of ticks to wait between attacks
    • attackRange

      public double attackRange()
      Returns:
      The attack range, in blocks
      See Also:
    • attackRange

      public NavigatorParameters attackRange(double range)
      When using aggressive NPC navigation, the NPC will wait until close enough to the target before attempting to use the attackStrategy(). This parameter determines the range in blocks squared before the target will be valid to attack.
      Parameters:
      range - The new attack range, in blocks
    • attackStrategy

      public AttackStrategy attackStrategy()
      Returns:
      The AttackStrategy currently in use or the defaultAttackStrategy() if not configured (may return null)
    • attackStrategy

      public void attackStrategy(AttackStrategy strategy)
      Sets the AttackStrategy for use when attacking entity targets.
      Parameters:
      strategy - The strategy to use
    • avoidWater

      public boolean avoidWater()
      Returns:
      Whether to avoid water while pathfinding
    • avoidWater

      public NavigatorParameters avoidWater(boolean avoidWater)
      Sets whether to avoid water while pathfinding
      Parameters:
      avoidWater - Whether to avoid water
    • baseSpeed

      public float baseSpeed()
      Returns:
      The base movement speed
    • baseSpeed

      public NavigatorParameters baseSpeed(float speed)
      Sets the base movement speed of the Navigator. Note that this is mob-specific and may not always be sane. Using speedModifier() is preferred.
      Parameters:
      speed - The new movement speed
      See Also:
    • callbacks

      public Iterable<NavigatorCallback> callbacks()
      Returns:
      All callbacks currently registered
    • clearExaminers

      public NavigatorParameters clearExaminers()
      Clears all current BlockExaminers.
    • clone

      public NavigatorParameters clone()
      Overrides:
      clone in class Object
    • debug

      public boolean debug()
      Returns whether this path will be debugged. Path debugging happens by repeatedly setting the next destination block to a client-sided flower.
      Returns:
      Whether the path is debugging
    • debug

      public NavigatorParameters debug(boolean debug)
      Sets whether the path should be debugged.
      See Also:
    • defaultAttackStrategy

      public AttackStrategy defaultAttackStrategy()
      Returns the configured default attack strategy, which tries to perform the most Minecraft-like attack on the target.
      Returns:
      The default strategy
    • defaultAttackStrategy

      public NavigatorParameters defaultAttackStrategy(AttackStrategy defaultStrategy)
      Sets the default AttackStrategy.
      Parameters:
      defaultStrategy - The new default strategy
      See Also:
    • destinationTeleportMargin

      public double destinationTeleportMargin()
      See Also:
    • destinationTeleportMargin

      public NavigatorParameters destinationTeleportMargin(double margin)
      Sets the distance (in blocks) after which the NPC will directly teleport to the destination or -1 if disabled. For example, if the destination teleport margin was 1.5 and the NPC reached 1.5 blocks from the target it would instantly teleport to the target location.
      Parameters:
      margin - Distance teleport margin
    • distanceMargin

      public double distanceMargin()
      Returns the distance margin or leeway that the Navigator will be able to stop from the target destination. The margin will be measured against the block distance. For example: if the distance margin were 2, then the Navigator could stop moving towards the target when it is 2 blocks away from it.
      Returns:
      The distance margin
    • distanceMargin

      public NavigatorParameters distanceMargin(double newMargin)
      Sets the distance margin.
      Parameters:
      newMargin - The new distance margin
      See Also:
    • entityTargetLocationMapper

      public Function<Entity,Location> entityTargetLocationMapper()
      Gets the target location mapper. This is a function that maps from a target entity to the location the NPC should pathfind to. The default mapper returns the location using Entity.getLocation(Location).
    • entityTargetLocationMapper

      public NavigatorParameters entityTargetLocationMapper(Function<Entity,Location> mapper)
      Set the target location mapper.
      Parameters:
      mapper - The new mapper
      See Also:
    • examiner

      public NavigatorParameters examiner(BlockExaminer examiner)
      Adds the given BlockExaminer.
      Parameters:
      examiner - The BlockExaminer to add
    • examiners

      public BlockExaminer[] examiners()
      Gets a copy of all current BlockExaminers.
      Returns:
      An array of all current examiners
    • hasExaminer

      public boolean hasExaminer(Class<? extends BlockExaminer> clazz)
    • lookAtFunction

      public Function<Navigator,Location> lookAtFunction()
      See Also:
    • lookAtFunction

      public NavigatorParameters lookAtFunction(Function<Navigator,Location> lookAt)
      Sets the position to look at during pathfinding, overriding the default 'look at target' behaviour.
      Parameters:
      lookAt - Where to look
    • modifiedSpeed

      public float modifiedSpeed(float toModify)
      Modifieds the given speed value based on the current parameters.
      Parameters:
      toModify - The speed value to modify
      Returns:
      The modified speed
    • pathDistanceMargin

      public double pathDistanceMargin()
      Gets the path distance margin.
      See Also:
    • pathDistanceMargin

      public NavigatorParameters pathDistanceMargin(double distance)
      Sets the path distance margin. This is how close the pathfinder should pathfind to the target in blocks. If you need to set the cutoff distance before the NPC considers their path completed, use distanceMargin(double).
      Parameters:
      distance - The distance margin
    • range

      public float range()
      Returns:
      The pathfinding range of the navigator in blocks.
      See Also:
    • range

      public NavigatorParameters range(float range)
      Sets the pathfinding range in blocks. The pathfinding range determines how far away the Navigator will attempt to pathfind before giving up to save computation.
      Parameters:
      range - The new range
    • removeRunCallback

      public NavigatorParameters removeRunCallback(Runnable runnable)
      Removes a previously added run callback.
      Parameters:
      runnable - The run callback to remove
      See Also:
    • run

      public void run()
      FOR INTERNAL USE ONLY: ticks all Runnable callbacks.
    • speed

      public float speed()
      Returns:
      The modified movement speed as given by baseSpeed() multiplied by speedModifier()
    • speed

      @Deprecated public NavigatorParameters speed(float speed)
      Deprecated.
      Sets the base movement speed of the Navigator. Note that this is mob-specific and may not always be sane. Using speedModifier() is preferred.
      Parameters:
      speed - The new movement speed
      See Also:
    • speedModifier

      public float speedModifier()
      Returns:
      The movement speed modifier
      See Also:
    • speedModifier

      public NavigatorParameters speedModifier(float percent)
      Sets the movement speed modifier of the Navigator. This is a percentage modifier that alters the movement speed returned in speed().
      Parameters:
      percent - The new speed modifier
    • stationaryTicks

      public int stationaryTicks()
      Returns:
      The number of stationary ticks
      See Also:
    • stationaryTicks

      public NavigatorParameters stationaryTicks(int ticks)
      Sets the number of stationary ticks before navigation is cancelled with a CancelReason of STUCK.
      Parameters:
      ticks - The new number of stationary ticks
    • straightLineTargetingDistance

      public float straightLineTargetingDistance()
      Returns:
      The distance
      See Also:
    • straightLineTargetingDistance

      public NavigatorParameters straightLineTargetingDistance(float distance)
      Sets the distance (in blocks) at which the entity targeter will switch to simply following a straight line to the target instead of pathfinding.
      Parameters:
      distance - The distance (in blocks)
    • stuckAction

      public StuckAction stuckAction()
      Gets the StuckAction of these parameters. This will be run when the navigation is stuck and must either be fixed up or cancelled.
      Returns:
      The current stuck action
    • stuckAction

      public NavigatorParameters stuckAction(StuckAction action)
      Sets the StuckAction of the parameters.
      Parameters:
      action - The new stuck action
      See Also:
    • updatePathRate

      public int updatePathRate()
      Returns:
      The current path rate
      See Also:
    • updatePathRate

      public NavigatorParameters updatePathRate(int rate)
      Sets the update path rate, in ticks (default 20). Mainly used for target following at this point - the NPC will recalculate its path to the target every rate ticks.
      Parameters:
      rate - The new rate in ticks to use
    • useNewPathfinder

      public boolean useNewPathfinder()
      Returns:
      Whether to use the new pathfinder
      See Also:
    • useNewPathfinder

      public NavigatorParameters useNewPathfinder(boolean use)
      Sets whether or not to use an A* pathfinder defined in AStarMachine for pathfinding. If this is set to false, then the Minecraft pathfinder will be used, which may or may not be more consistent. Note that certain API features will not be possible if this is set to false - this includes examiner(BlockExaminer) and distanceMargin(double).
      Parameters:
      use - Whether to use the A* pathfinder