Package net.citizensnpcs.api.ai
Class NavigatorParameters
java.lang.Object
net.citizensnpcs.api.ai.NavigatorParameters
- All Implemented Interfaces:
Cloneable
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddRunCallback
(Runnable callback) Adds aRunnable
callback that will be called every tick while the path is running.addSingleUseCallback
(NavigatorCallback callback) Adds aNavigatorCallback
that will be removed immediately after being called.int
attackDelayTicks
(int ticks) Sets the delay between attacks.double
attackRange
(double range) When using aggressive NPC navigation, the NPC will wait until close enough to the target before attempting to use theattackStrategy()
.void
attackStrategy
(AttackStrategy strategy) Sets theAttackStrategy
for use when attacking entity targets.boolean
avoidWater
(boolean avoidWater) Sets whether to avoid water while pathfindingfloat
baseSpeed
(float speed) Sets the base movement speed of theNavigator
.Clears all currentBlockExaminer
s.clone()
boolean
debug()
Returns whether this path will be debugged.debug
(boolean debug) Sets whether the path should be debugged.Returns the configured default attack strategy, which tries to perform the most Minecraft-like attack on the target.defaultAttackStrategy
(AttackStrategy defaultStrategy) Sets the defaultAttackStrategy
.double
destinationTeleportMargin
(double margin) Sets the distance (in blocks) after which the NPC will directly teleport to the destination or -1 if disabled.double
Returns the distance margin or leeway that theNavigator
will be able to stop from the target destination.distanceMargin
(double newMargin) Sets the distance margin.Gets the target location mapper.entityTargetLocationMapper
(Function<Entity, Location> mapper) Set the target location mapper.examiner
(BlockExaminer examiner) Adds the givenBlockExaminer
.Gets a copy of all currentBlockExaminer
s.boolean
hasExaminer
(Class<? extends BlockExaminer> clazz) lookAtFunction
(Function<Navigator, Location> lookAt) Sets the position to look at during pathfinding, overriding the default 'look at target' behaviour.float
modifiedSpeed
(float toModify) Modifieds the given speed value based on the current parameters.double
Gets the path distance margin.pathDistanceMargin
(double distance) Sets the path distance margin.float
range()
range
(float range) Sets the pathfinding range in blocks.removeRunCallback
(Runnable runnable) Removes a previously added run callback.void
run()
FOR INTERNAL USE ONLY: ticks allRunnable
callbacks.float
speed()
speed
(float speed) Deprecated.float
speedModifier
(float percent) Sets the movement speed modifier of theNavigator
.int
stationaryTicks
(int ticks) Sets the number of stationary ticks before navigation is cancelled with aCancelReason
of STUCK.float
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.Gets theStuckAction
of these parameters.stuckAction
(StuckAction action) Sets theStuckAction
of the parameters.int
updatePathRate
(int rate) Sets the update path rate, in ticks (default 20).boolean
useNewPathfinder
(boolean use) Sets whether or not to use an A* pathfinder defined inAStarMachine
for pathfinding.
-
Constructor Details
-
NavigatorParameters
public NavigatorParameters()
-
-
Method Details
-
addRunCallback
Adds aRunnable
callback that will be called every tick while the path is running.- Parameters:
callback
- The callback to add
-
attackDelayTicks
public int attackDelayTicks()- Returns:
- The number of ticks to wait between attacks
- See Also:
-
attackDelayTicks
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
When using aggressive NPC navigation, the NPC will wait until close enough to the target before attempting to use theattackStrategy()
. 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
- Returns:
- The
AttackStrategy
currently in use or thedefaultAttackStrategy()
if not configured (may return null)
-
attackStrategy
Sets theAttackStrategy
for use when attacking entity targets.- Parameters:
strategy
- The strategy to use
-
avoidWater
public boolean avoidWater()- Returns:
- Whether to avoid water while pathfinding
-
avoidWater
Sets whether to avoid water while pathfinding- Parameters:
avoidWater
- Whether to avoid water
-
baseSpeed
public float baseSpeed()- Returns:
- The base movement speed
-
baseSpeed
Sets the base movement speed of theNavigator
. Note that this is mob-specific and may not always be sane. UsingspeedModifier()
is preferred.- Parameters:
speed
- The new movement speed- See Also:
-
callbacks
- Returns:
- All callbacks currently registered
-
clearExaminers
Clears all currentBlockExaminer
s. -
clone
-
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
Sets whether the path should be debugged.- See Also:
-
defaultAttackStrategy
Returns the configured default attack strategy, which tries to perform the most Minecraft-like attack on the target.- Returns:
- The default strategy
-
defaultAttackStrategy
Sets the defaultAttackStrategy
.- Parameters:
defaultStrategy
- The new default strategy- See Also:
-
destinationTeleportMargin
public double destinationTeleportMargin()- See Also:
-
destinationTeleportMargin
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 theNavigator
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 theNavigator
could stop moving towards the target when it is 2 blocks away from it.- Returns:
- The distance margin
-
distanceMargin
Sets the distance margin.- Parameters:
newMargin
- The new distance margin- See Also:
-
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 usingEntity.getLocation(Location)
. -
entityTargetLocationMapper
Set the target location mapper.- Parameters:
mapper
- The new mapper- See Also:
-
examiner
Adds the givenBlockExaminer
.- Parameters:
examiner
- The BlockExaminer to add
-
examiners
Gets a copy of all currentBlockExaminer
s.- Returns:
- An array of all current examiners
-
hasExaminer
-
lookAtFunction
- See Also:
-
lookAtFunction
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
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, usedistanceMargin(double)
.- Parameters:
distance
- The distance margin
-
range
public float range()- Returns:
- The pathfinding range of the navigator in blocks.
- See Also:
-
range
Sets the pathfinding range in blocks. The pathfinding range determines how far away theNavigator
will attempt to pathfind before giving up to save computation.- Parameters:
range
- The new range
-
removeRunCallback
Removes a previously added run callback.- Parameters:
runnable
- The run callback to remove- See Also:
-
run
public void run()FOR INTERNAL USE ONLY: ticks allRunnable
callbacks. -
speed
public float speed()- Returns:
- The modified movement speed as given by
baseSpeed()
multiplied byspeedModifier()
-
speed
Deprecated.@seebaseSpeed(float)
Sets the base movement speed of theNavigator
. Note that this is mob-specific and may not always be sane. UsingspeedModifier()
is preferred.- Parameters:
speed
- The new movement speed- See Also:
-
speedModifier
public float speedModifier()- Returns:
- The movement speed modifier
- See Also:
-
speedModifier
Sets the movement speed modifier of theNavigator
. This is a percentage modifier that alters the movement speed returned inspeed()
.- Parameters:
percent
- The new speed modifier
-
stationaryTicks
public int stationaryTicks()- Returns:
- The number of stationary ticks
- See Also:
-
stationaryTicks
Sets the number of stationary ticks before navigation is cancelled with aCancelReason
of STUCK.- Parameters:
ticks
- The new number of stationary ticks
-
straightLineTargetingDistance
public float straightLineTargetingDistance()- Returns:
- The distance
- See Also:
-
straightLineTargetingDistance
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
Gets theStuckAction
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
Sets theStuckAction
of the parameters.- Parameters:
action
- The new stuck action- See Also:
-
updatePathRate
public int updatePathRate()- Returns:
- The current path rate
- See Also:
-
updatePathRate
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 everyrate
ticks.- Parameters:
rate
- The new rate in ticks to use
-
useNewPathfinder
public boolean useNewPathfinder()- Returns:
- Whether to use the new pathfinder
- See Also:
-
useNewPathfinder
Sets whether or not to use an A* pathfinder defined inAStarMachine
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 includesexaminer(BlockExaminer)
anddistanceMargin(double)
.- Parameters:
use
- Whether to use the A* pathfinder
-
baseSpeed(float)