Class Npc

java.lang.Object
net.risingworld.api.objects.Npc

public final class Npc extends Object
Represents an npc, i.e animals, humans, monsters etc.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes the npc.
    void
    Removes an attribute.
    int
    Gets the "age" of the npc in seconds, i.e how many seconds passed since the npc was spawned.
    Gets the currently active attack reaction of this particular npc.
    Gets the value to which the specified key is mapped, or null if no attribute is stored for that key.
    Gets the currently active behaviour of this particular npc.
    Gets a Clothes object which contains the clothes the npc is currently wearing.
    Gets the definition for this npc.
    Gets the currently equipped item (i.e the item the npc currently holds in his hands), or null if no item is equipped.
    long
    Gets the unique global ID of the npc.
    int
    Gets the optional "group ID" of the npc.
    int
    Gets the current health of the npc.
    Gets the "hostile player".
    int
    Gets the current hunger level of the npc.
    Gets the optional custom name of the npc.
    Gets the nearest player, or more precisely, the player which is considered the "nearest player" by the npc.
    void
    getPlayerInLineOfSight(float distance, Callback<Player> callback)
    Gets the player in line-of-sight of the player (i.e the player animal is currently looking at).
    Gets the current world position of the npc.
    Gets the rider of the npc, if present.
    Gets the current rotation of the npc.
    Gets the currently equipped secondary item (i.e the optional additional item the npc currently holds in his hands), or null if no secondary item is equipped.
    Gets a Skin object which represents the appearance of the npc, i.e gender, haircut, skin color, hair color etc.
    int
    Gets the current thirst level of the npc.
    short
    Gets the type ID of the npc, i.e the internal ID of the npc in the definitions database.
    int
    Gets the variant of the npc.
    Gets a normalized vector from the npc position to the position of the nearest player.
    Gets the current view direction of the npc as a normalized vector.
    boolean
    Gets whether or not the provided attribute exists.
    boolean
    Gets whether or not the provided attribute exists (also checks if it has a specific type).
    boolean
    Gets whether or not the npc is currently alerted/alarmed.
    boolean
    Gets whether or not alert sounds (including hurt and attack sounds) are enabled for this npc (enabled by default).
    boolean
    Gets whether or not the attack reaction of this particular npc was overridden by a player or via API.
    boolean
    Gets whether or not the behaviour of this particular npc was overridden by a player or via API.
    boolean
    Gets whether or not collisions are enabled for this npc (enabled by default).
    boolean
    Gets whether or not the npc is dead.
    boolean
    Gets whether or not footstep sounds are enabled for this npc (enabled by default).
    boolean
    Gets whether or not idle sounds are enabled for this npc (enabled by default).
    boolean
    Gets whether or not interactions are enabled for this npc (enabled by default).
    boolean
    Gets whether or not the npc is invincible, this means it cannot be killed by any players or other npcs.
    boolean
    Gets whether or not the npc is invisible.
    boolean
    Gets whether the npc is currently in water or not.
    boolean
    Gets whether or not the npc is currently "locked".
    boolean
    Gets whether or not the npc is only alive during night (i.e despawns/dies at daybreak).
    boolean
    Gets whether or not the npc is currently sleeping.
    boolean
    Gets whether the npc is "transient" or not.
    boolean
    Gets whether the npc is currently under water or not.
    void
    Kills the npc instantly.
    void
    moveTo(float x, float y, float z)
    Forces the npc to move to the provided position.
    void
    moveTo(Vector3f position)
    Forces the npc to move to the provided position.
    void
    Forces this npc to play an alert/hurt sound.
    void
    Forces this npc to play its death sound.
    void
    Forces this npc to play an idle sound.
    void
    Resets the overridden attack reaction to the default reaction
    void
    Resets the overridden behaviour to the default behaviour
    void
    setAge(int age)
    Sets the "age" of the npc.
    void
    setAlerted(boolean set)
    Changes the "alert" state of the npc.
    void
    setAlerted(boolean set, int duration)
    Changes the "alert" state of the npc.
    void
    Overrides the attack reaction of this specific npc, i.e how it reacts when being attacked by a player.
    This setting is saved to the npc database, so it's still active after a server restart!
    void
    setAttribute(String key, Object value)
    Stores an attribute for this npc.
    void
    Overrides the behaviour of this particular npc, i.e how it behaves when seeing a player.
    This setting is saved to the npc database, so it's still active after a server restart!

    Note: In many cases it's also necessary to update the attack reaction of the npc (see setAttackReaction(Npcs.AttackReaction))!
    void
    setColliderEnabled(boolean set)
    Enables/disables the colliders for this npc.
    void
    setGroupID(int groupID)
    Sets the "group ID" for the npc.
    void
    setHealth(int health)
    Sets the health of the npc.
    void
    setHunger(int hunger)
    Sets the hunger level of the npc.
    void
    setInteractable(boolean set)
    Enables/disables interactions with this npc.
    void
    setInvincible(boolean set)
    Enables/disables invincibility for this npc.
    void
    setInvisible(boolean set)
    Makes the npc invisible or visible again.
    void
    setLocked(boolean set)
    Locks or unlocks the npc.
    void
    Sets the custom name of this npc.
    void
    setPosition(float x, float y, float z)
    Sets the world position of the npc (teleports the npc).
    void
    Sets the world position of the npc (teleports the npc).
    void
    setRotation(float pitch, float yaw, float roll)
    Sets the npc rotation.
    void
    setRotation(Quaternion quaternion)
    Sets the npc rotation.
    void
    setSoundsEnabled(boolean footstepSounds, boolean idleSounds, boolean alertSounds)
    Enables/disables various sounds the npc makes.
    void
    setThirst(int thirst)
    Sets the thirst level of the npc.
    void
    setViewDirection(float dirx, float diry, float dirz)
    Sets the view direction of the npc.
    void
    Sets the view direction of the npc.
    boolean
    transform(short typeID, int variant)
    Turns this npc into another npc.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getGlobalID

      public long getGlobalID()
      Gets the unique global ID of the npc.
      Returns:
      the unique ID of npc.
    • getDefinition

      public Npcs.NpcDefinition getDefinition()
      Gets the definition for this npc.
      Returns:
      the npc definition.
      Example: Check if a particular npc is a human
      1Npc npc = World.getNpc(...);
      2if(npc != null) {
      3 Npcs.NpcDefinition def = npc.getDefinition();
      4 if(def.type == Npcs.Type.Human) {
      5 System.out.println("NPC is a human!");
      6 }
      7}
    • getTypeID

      public short getTypeID()
      Gets the type ID of the npc, i.e the internal ID of the npc in the definitions database.
      Returns:
      the type ID of the npc.
    • getVariant

      public int getVariant()
      Gets the variant of the npc. By default it's 0. Only certain npc can have different variations. To find out if an npc has multiple variants, check if Npcs.NpcDefinition.variations is greater than 0.
      Returns:
      the variant of the npc. Default variant is 0.
    • getGroupID

      public int getGroupID()
      Gets the optional "group ID" of the npc. A group is basically a herd or a squad. Only certain npc are member of a group/squad/herd (e.g bandits or animals which spawned in a herd).
      If a group member is alerted, all other group members will be alerted too (unless they're too far away).
      Returns:
      the group ID of the npc. -1 if no group is set.
    • setGroupID

      public void setGroupID(int groupID)
      Sets the "group ID" for the npc. A group is basically a herd or a squad.
      If a group member is alerted, all other group members will be alerted too (unless they're too far away).
      To get a new, unused group ID, you can call World.getNextNpcGroupID().
      Parameters:
      groupID - the group ID for the npc. Set -1 to set the group to "none"
      See Also:
    • isTransient

      public boolean isTransient()
      Gets whether the npc is "transient" or not. If it is transient, it will not be stored in the database (i.e it can be considered a temporary npc then which will disappear after server restart).
      Returns:
      true if the npc is transient, false if not.
    • isOnlyAliveDuringNight

      public boolean isOnlyAliveDuringNight()
      Gets whether or not the npc is only alive during night (i.e despawns/dies at daybreak).
      Returns:
      true if the npc is only alive during the night, false if not.
    • getName

      public String getName()
      Gets the optional custom name of the npc. By default npcs don't have a custom name, unless it was set by a player.

      Note: This is not to be confused this with the internal name of the npc type (e.g "cow", "bear" etc). If you want to get that name, use the npc definition instead, e.g String name = npc.getDefinition().name;
      Returns:
      the optional custom npc name, or null if no custom name was set for this npc.
    • setName

      public void setName(String name)
      Sets the custom name of this npc. When setting a name, it will appear as nametag above the npc (visible for all players).
      Parameters:
      name - the custom name you want to set for the npc. Provide null if you want to remove the custom name (which also removes the nametag above the npc).
    • getAge

      public int getAge()
      Gets the "age" of the npc in seconds, i.e how many seconds passed since the npc was spawned. Some npcs only live for a certain amount of time.
      Returns:
      the age of the npc (in seconds).
      Example: Kill npc if it's older than 2 hours
      1//Get current age of the npc, in seconds
      2int age = npc.getAge();
      3
      4//2 hours == 120 minutes == 7200 seconds
      5if (age > (2 * 60 * 60)) {
      6 npc.kill();
      7}
    • setAge

      public void setAge(int age)
      Sets the "age" of the npc. The age describes how many seconds the npc is already alive (i.e how many seconds passed since the npc was spawned).
      Parameters:
      age - the new age, in seconds.
    • getEquippedItem

      public Item getEquippedItem()
      Gets the currently equipped item (i.e the item the npc currently holds in his hands), or null if no item is equipped. Please bear in mind that only certain npcs (humans, skeletons etc) can have an item equipped
      Returns:
      the equipped item, or null if no item is equipped.
      See Also:
    • getSecondaryItem

      public Item getSecondaryItem()
      Gets the currently equipped secondary item (i.e the optional additional item the npc currently holds in his hands), or null if no secondary item is equipped. The secondary item is typically a torch or lamp. Please bear in mind that only certain npcs (humans, skeletons etc) can have an item equipped
      Returns:
      the equipped item, or null if no item is equipped.
      See Also:
    • getNearestPlayer

      public Player getNearestPlayer()
      Gets the nearest player, or more precisely, the player which is considered the "nearest player" by the npc.
      Returns:
      the nearest player, or null if no player is in proximity of the npc.
    • getHostilePlayer

      public Player getHostilePlayer()
      Gets the "hostile player". For example, once a player attacks the npc, he's usually considered "hostile" by the npc, so the npc either attacks the player or tries to escape. Once the distance between the player and the npc is big enough, the "hostile player" will be reset (so the player is no longer considered hostile).
      Returns:
      the "hostile player" (see above), or null if there is currently no hostile player.
    • isLocked

      public boolean isLocked()
      Gets whether or not the npc is currently "locked". If an npc is locked, it will never move away or attack the player. Basically it stands still at the current location (although it can still fall down if spawned in the air, for example).
      Returns:
      true if the npc is "locked", false if not.
      See Also:
    • setLocked

      public void setLocked(boolean set)
      Locks or unlocks the npc. If an npc is locked, it will never move away or attack the player. Basically it stands still at the current location (although it can still fall down if spawned in the air, for example).
      This setting is saved to the npc database, so it's still active after a server restart.
      Parameters:
      set - true to lock the npc (so it will never move away), false to unlock it (default behavior).
      See Also:
    • isInvincible

      public boolean isInvincible()
      Gets whether or not the npc is invincible, this means it cannot be killed by any players or other npcs.
      Returns:
      true if the npc is invincible, false if not (default).
      See Also:
    • setInvincible

      public void setInvincible(boolean set)
      Enables/disables invincibility for this npc. If the npc is invincible, it cannot be killed by any players or other npcs.
      This setting is saved to the npc database, so it's still active after a server restart!
      Parameters:
      set - true to make this npc invincible, false to make it vulnerable again.
      See Also:
    • isInvisible

      public boolean isInvisible()
      Gets whether or not the npc is invisible. If the npc is invisible, it's still there (making noises, having collision, player can still interact with it etc), but it's no longer rendered.
      Returns:
      true if the npc is invisible, false if not (default).
      See Also:
    • setInvisible

      public void setInvisible(boolean set)
      Makes the npc invisible or visible again. If the npc is invisible, it's still there (making noises, having collision, player can still interact with it etc), but it's no longer rendered.
      This setting is saved to the npc database, so it's still active after a server restart!
      Parameters:
      set - true to make this npc invisible, false to make it visible again (default state).
      See Also:
    • setColliderEnabled

      public void setColliderEnabled(boolean set)
      Enables/disables the colliders for this npc. The npc still collides with the environment then (i.e it doesn't walk through walls etc), but the player no longer collides with the npc and the player is also no longer able to hit the npc with a weapon or tool.
      This setting is saved to the npc database, so it's still active after a server restart!
      Parameters:
      set - true to enable collisions, false to disable them (i.e player can walk through npc and no longer hit it).
      See Also:
    • isColliderEnabled

      public boolean isColliderEnabled()
      Gets whether or not collisions are enabled for this npc (enabled by default).
      Returns:
      true if the colliders are active, false if not.
      See Also:
    • setInteractable

      public void setInteractable(boolean set)
      Enables/disables interactions with this npc. By default, interactions are enabled, i.e the player can press hit interaction key (F) while looking at the npc (to interact with it). If you set this to false, the player is no longer able to interact with the npc (this also means the PlayerNpcInteractionEvent will on longer be triggered).
      This setting is saved to the npc database, so it's still active after a server restart!
      Parameters:
      set - true to set interactions enabled (default behaviour), false to disable them.
      See Also:
    • isInteractable

      public boolean isInteractable()
      Gets whether or not interactions are enabled for this npc (enabled by default).
      Returns:
      true if interactions are enabled, false if they're disabled.
      See Also:
    • setBehaviour

      public void setBehaviour(Npcs.Behaviour behaviour)
      Overrides the behaviour of this particular npc, i.e how it behaves when seeing a player.
      This setting is saved to the npc database, so it's still active after a server restart!

      Note: In many cases it's also necessary to update the attack reaction of the npc (see setAttackReaction(Npcs.AttackReaction))!
      Parameters:
      behaviour - the new behaviour.
      Example: Make nearest npc aggressive (so it attacks the player on sight)
      1//Find nearest npc to player
      2Npc npc = World.findNearestNpc(player.getPosition());
      3
      4//Check if an npc was found (ie not null)
      5if (npc != null) {
      6 //Set "Aggressive" behaviour, so it attacks the player on sight
      7 npc.setBehaviour(Npcs.Behaviour.Aggressive);
      8
      9 //Also change the attack reaction
      10 npc.setAttackReaction(Npcs.AttackReaction.Attack);
      11}
      See Also:
    • getBehaviour

      public Npcs.Behaviour getBehaviour()
      Gets the currently active behaviour of this particular npc. If the behaviour was overridden by a player or via API, the overridden behaviour is returned. Else the default npc behaviour is returned.
      Returns:
      the currently active behaviour for this npc instance.
      See Also:
    • isBehaviourOverridden

      public boolean isBehaviourOverridden()
      Gets whether or not the behaviour of this particular npc was overridden by a player or via API.
      Returns:
      true if the behaviour was overridden, false if not.
      See Also:
    • resetBehaviour

      public void resetBehaviour()
      Resets the overridden behaviour to the default behaviour
      See Also:
    • setAttackReaction

      public void setAttackReaction(Npcs.AttackReaction attackReaction)
      Overrides the attack reaction of this specific npc, i.e how it reacts when being attacked by a player.
      This setting is saved to the npc database, so it's still active after a server restart!
      Parameters:
      attackReaction - the new attack reaction.
      See Also:
    • getAttackReaction

      public Npcs.AttackReaction getAttackReaction()
      Gets the currently active attack reaction of this particular npc. If the attack reaction was overridden by a player or via API, the overridden attack reaction is returned. Else the default npc attack reaction is returned.
      Returns:
      the currently active attack reaction for this npc instance.
      See Also:
    • isAttackReactionOverridden

      public boolean isAttackReactionOverridden()
      Gets whether or not the attack reaction of this particular npc was overridden by a player or via API.
      Returns:
      true if the attack reaction was overridden, false if not.
      See Also:
    • resetAttackReaction

      public void resetAttackReaction()
      Resets the overridden attack reaction to the default reaction
      See Also:
    • getRider

      public Object getRider()
      Gets the rider of the npc, if present. This only works for "Mounts", i.e if npc.getDefinition().type == Npcs.Type.Mount. If there is no rider (or if the npc isn't a mount), this function returns null.
      Returns:
      the rider of this npc (a Player, if present).
      See Also:
    • transform

      public boolean transform(short typeID, int variant)
      Turns this npc into another npc.
      Parameters:
      typeID - the target npc type ID.
      variant - the optional target variant.
      Returns:
      true if the npc type/variant could be changed, false if not (e.g if the target type ID is invalid).
    • setSoundsEnabled

      public void setSoundsEnabled(boolean footstepSounds, boolean idleSounds, boolean alertSounds)
      Enables/disables various sounds the npc makes.
      This setting is saved to the npc database, so it's still active after a server restart!
      Parameters:
      footstepSounds - true if you want footstep sounds to be enabled for this npc, false to disable them.
      idleSounds - true if you want idle sounds to be enabled for this npc, false to disable them.
      alertSounds - true if you want alert sounds (hurt sounds, attack sounds, death sound etc) to be enabled for this npc, false to disable them.
      See Also:
    • isFootstepSoundEnabled

      public boolean isFootstepSoundEnabled()
      Gets whether or not footstep sounds are enabled for this npc (enabled by default).
      Returns:
      true if footstep sounds are enabled, false if not.
      See Also:
    • isIdleSoundEnabled

      public boolean isIdleSoundEnabled()
      Gets whether or not idle sounds are enabled for this npc (enabled by default).
      Returns:
      true if idle sounds are enabled, false if not.
      See Also:
    • isAlertSoundEnabled

      public boolean isAlertSoundEnabled()
      Gets whether or not alert sounds (including hurt and attack sounds) are enabled for this npc (enabled by default).
      Returns:
      true if alert sounds are enabled, false if not.
      See Also:
    • playIdleSound

      public void playIdleSound()
      Forces this npc to play an idle sound. The sound is even played if idle sounds are disabled for the npc (see isIdleSoundEnabled())
    • playAlertSound

      public void playAlertSound()
      Forces this npc to play an alert/hurt sound. The sound is even played if idle sounds are disabled for the npc (see isAlertSoundEnabled())
    • playDeathSound

      public void playDeathSound()
      Forces this npc to play its death sound.
    • getPosition

      public Vector3f getPosition()
      Gets the current world position of the npc.
      Returns:
      the npc world position as Vector3f.
    • setPosition

      public void setPosition(Vector3f position)
      Sets the world position of the npc (teleports the npc).
      Parameters:
      position - a Vector3f containing the world target position.
    • setPosition

      public void setPosition(float x, float y, float z)
      Sets the world position of the npc (teleports the npc).
      Parameters:
      x - world X coordinate to set (horizontally).
      y - world Y coordinate to set (vertically).
      z - world Z coordinate to set (horizontally).
    • moveTo

      public void moveTo(Vector3f position)
      Forces the npc to move to the provided position. The regular npc behaviour still remains active, this means it will walk to that position if possible. The npc can't reach the position if the way is obstructed, for example. If the npc is alerted, it will run to the position (instead of walking).
      Parameters:
      position - the target position. The y coordinate is usually irrelevant (unless it's a flying or swimming npc), because the npc will try to walk to that position.
    • moveTo

      public void moveTo(float x, float y, float z)
      Forces the npc to move to the provided position. The regular npc behaviour still remains active, this means it will walk to that position if possible. The npc can't reach the position if the way is obstructed, for example. If the npc is alerted, it will run to the position (instead of walking).
      Parameters:
      x - the target position X coordinate.
      y - the target position Y coordinate. Usually it's irrelevant (unless it's a flying or swimming npc), because the npc will try to walk to that position.
      z - the target position Z coordinate.
    • getRotation

      public Quaternion getRotation()
      Gets the current rotation of the npc.
      Returns:
      the npc rotation as Quaternion.
    • setRotation

      public void setRotation(Quaternion quaternion)
      Sets the npc rotation.
      Parameters:
      quaternion - the new npc rotation.
    • setRotation

      public void setRotation(float pitch, float yaw, float roll)
      Sets the npc rotation.
      Parameters:
      pitch - pitch (euler x rotation).
      yaw - yaw (euler y rotation).
      roll - roll (euler z rotation).
    • getViewDirection

      public Vector3f getViewDirection()
      Gets the current view direction of the npc as a normalized vector.
      Returns:
      the view direction as a Vector3f (float).
    • setViewDirection

      public void setViewDirection(Vector3f direction)
      Sets the view direction of the npc. You can use this function to force the npc to look into a certain direction.
      Parameters:
      direction - the new view direction as a Vector3f (float). Make sure to use a unit/normalized vector.
    • setViewDirection

      public void setViewDirection(float dirx, float diry, float dirz)
      Sets the view direction of the npc. You can use this function to force the npc to look into a certain direction.
      Parameters:
      dirx - X component of the new view direction vector.
      diry - Y component of the new view direction vector.
      dirz - Z component of the new view direction vector.
    • getVectorToNearestPlayer

      public Vector3f getVectorToNearestPlayer()
      Gets a normalized vector from the npc position to the position of the nearest player. If there is no player, null is returned.
      Returns:
      a vector from the npc position to the position of the nearest player (as an unit/normalized vector).
    • getPlayerInLineOfSight

      public void getPlayerInLineOfSight(float distance, Callback<Player> callback)
      Gets the player in line-of-sight of the player (i.e the player animal is currently looking at). This is a convenience method which performs a raycast under the hood.
      Parameters:
      distance - the max allowed distance for the player.
      callback - the callback that will be invoked once the result is available. It contains the player the npc is currently looking at (within the distance), or null if no player was found.
    • isInWater

      public boolean isInWater()
      Gets whether the npc is currently in water or not.
      Returns:
      true if the npc is in water, false if not.
    • isUnderwater

      public boolean isUnderwater()
      Gets whether the npc is currently under water or not.
      Returns:
      true if the npc is under water, false if not.
    • setAlerted

      public void setAlerted(boolean set)
      Changes the "alert" state of the npc. If an npc is alerted/alarmed, it starts running, and if a player is in his proximity, it will either attack the player (if it's a hostile animal) or flee from him. Setting the alert state of an npc to true, this state will last for around 20 seconds.
      Please keep in mind that the game may always override the alert state.
      Parameters:
      set - true to set the npc alerted/alarmed, false to disable the alert state.
      Example: Alert all npcs closer than 50 block to the player
      1//Get all npcs in range
      2Npc[] ncps = World.getAllNpcsInRange(player.getPosition(), 50);
      3
      4//Go through npcs and set alert state
      5for (Npc npc : npcs) {
      6 npc.setAlerted(true);
      7}
    • setAlerted

      public void setAlerted(boolean set, int duration)
      Changes the "alert" state of the npc. If an npc is alerted/alarmed, it starts running, and if a player is in his proximity, it will either attack the player (if it's a hostile animal) or flee from him. By setting the duration parameter, you can determine how long the npc will stay alerted.

      Please keep in mind that the game may always override the alert state or the alert duration.
      Parameters:
      set - true to set the npc alerted/alarmed, false to disable the alert state.
      duration - the duration (in seconds) how long the npc will stay alerted. Does nothing when setting the alert state to false.
    • isAlerted

      public boolean isAlerted()
      Gets whether or not the npc is currently alerted/alarmed.
      Returns:
      true if the npc is alerted, false if not.
    • getHealth

      public int getHealth()
      Gets the current health of the npc.
      Returns:
      the current health of the npc.
    • setHealth

      public void setHealth(int health)
      Sets the health of the npc.
      Parameters:
      health - the new npc health.
      Example: Set health back to default
      1//To find out the default health, get the npc definition
      2Npcs.NpcDefinition def = npc.getDefinition();
      3
      4//Set health
      5npc.setHealth(def.health);
    • getHunger

      public int getHunger()
      Gets the current hunger level of the npc. 100 means the npc is not hungry, 0 means the npc is starving.
      Returns:
      the current hunger level of the npc.
    • setHunger

      public void setHunger(int hunger)
      Sets the hunger level of the npc. 100 means the npc is not hungry, 0 means the npc is starving.
      Parameters:
      hunger - the new hunger level.
    • getThirst

      public int getThirst()
      Gets the current thirst level of the npc. 100 means the npc is not thirsty, 0 means the npc is dying of dehydration.
      Returns:
      the current thirst level of the npc.
    • setThirst

      public void setThirst(int thirst)
      Sets the thirst level of the npc. 100 means the npc is not thirsty, 0 means the npc is dying of dehydration.
      Parameters:
      thirst - the new thirst level.
    • isSleeping

      public boolean isSleeping()
      Gets whether or not the npc is currently sleeping.
      Returns:
      true if the npc is sleeping, false if not.
    • isDead

      public boolean isDead()
      Gets whether or not the npc is dead.
      Returns:
      true if the npc is dead, false if not.
    • kill

      public void kill()
      Kills the npc instantly. Spawns a dead body and removes the npc instance from the world.
      See Also:
    • delete

      public void delete()
      Deletes the npc. Similar to kill(), but without spawning a dead body. NOTE: There is no need to call delete after calling kill()! Doing so does not remove the dead body of the npc (which was spawned by kill()). If you want to remove an npc without spawning a corpse, only call delete(), without kill()
    • getSkin

      public Skin getSkin()
      Gets a Skin object which represents the appearance of the npc, i.e gender, haircut, skin color, hair color etc.
      Only certain npc have a skin object (e.g humans)! Other npcs - like animals - usually don't have a Skin object.
      Returns:
      a Skin object representing the visual appearance of the npc.
    • getClothes

      public Clothes getClothes()
      Gets a Clothes object which contains the clothes the npc is currently wearing.
      Only certain npc have a clothes object! Human npc can wear the same clothes as the player, while other npc can only wear certain clothes (like mounts, which can only wear saddles etc) or no clothes at all (e.g animals).
      Returns:
      a Clothes object representing the clothes of the npc.
    • setAttribute

      public void setAttribute(String key, Object value)
      Stores an attribute for this npc. You can store any type of object. Note that all attributes will be reset upon server restart.
      Parameters:
      key - the name of the attribute.
      value - the value/object you want to store.
    • getAttribute

      public Object getAttribute(String key)
      Gets the value to which the specified key is mapped, or null if no attribute is stored for that key.
      Parameters:
      key - the name of the attribute.
      Returns:
      the attribute that is stored for that key, or null of the key does not exists.
    • hasAttribute

      public boolean hasAttribute(String key)
      Gets whether or not the provided attribute exists.
      Parameters:
      key - the name of the attribute.
      Returns:
      true if the attribute exists, false if not.
    • hasAttribute

      public boolean hasAttribute(String key, Class type)
      Gets whether or not the provided attribute exists (also checks if it has a specific type).
      Parameters:
      key - the name of the attribute.
      type - the type of the attribute
      Returns:
      true if the attribute exists and if it has the desired type, false if not.
    • deleteAttribute

      public void deleteAttribute(String key)
      Removes an attribute. Does nothing if the attribute doesn't exist.
      Parameters:
      key - the name of the attribute you want to delete.