Class NpcEntity

  • All Implemented Interfaces:
    Interactable<net.runelite.api.NPC>

    public class NpcEntity
    extends AbstractEntity<net.runelite.api.NPC>
    • Constructor Summary

      Constructors 
      Constructor Description
      NpcEntity​(Context ctx, net.runelite.api.NPC raw)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean attack()
      Attacks an NPC.
      int getDistanceFromPlayer()
      Calculates the distance between the NPC and the local player within the game world.
      net.runelite.api.HeadIcon getHeadIcon()
      Retrieves the head icon associated with the NPC, if it exists.
      double getHealthPercentage()
      Gets the health percentage of the NPC.
      int getId()
      The item ID for the wrapped game entity
      java.lang.String getName()
      The game entities name.
      boolean interact​(java.lang.String action)
      Interacts with the entity using the given action verb.
      boolean isInArea​(GameArea area)
      Checks if the NPC's current location is within the game area.
      boolean useWidget​(net.runelite.api.widgets.Widget widget)
      Uses a specified widget on the NPC (i.e.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NpcEntity

        public NpcEntity​(Context ctx,
                         net.runelite.api.NPC raw)
    • Method Detail

      • getName

        public java.lang.String getName()
        Description copied from interface: Interactable
        The game entities name.
        Returns:
        The name of the game entity i.e. NPC name for NPC's, item name for ContainerItem's, and GameObject name for various game objects.
      • getId

        public int getId()
        Description copied from interface: Interactable
        The item ID for the wrapped game entity
        Returns:
        int Item id
      • getHealthPercentage

        public double getHealthPercentage()
        Gets the health percentage of the NPC.
        Returns:
        Health percentage (0-100), or -1 if unknown
      • getHeadIcon

        public net.runelite.api.HeadIcon getHeadIcon()
        Retrieves the head icon associated with the NPC, if it exists.

        A head icon represents an overhead visual indicator, such as combat prayers or effects like Hunllef's prayers or Nex's deflect melee. This is determined from the NPC's overhead sprite IDs.

        • If no head icons are defined for the NPC, this will return null.
        • If a valid head icon is found, it will be returned as a HeadIcon enum.
        Returns:
        The HeadIcon for the NPC, or null if no valid head icon exists.
      • getDistanceFromPlayer

        public int getDistanceFromPlayer()
        Calculates the distance between the NPC and the local player within the game world.

        The method retrieves the NPC's local location and the local player's location from the game client, then computes the distance between the two positions. If the distance cannot be calculated (e.g., due to a timeout on the client thread), Integer.MAX_VALUE is returned as a fallback.

        • The computation is performed on the game's client thread to ensure thread safety unless the result is unavailable.
        Returns:
        The distance between the NPC's location and the local player's location in the game world, or Integer.MAX_VALUE if the distance cannot be determined.
      • isInArea

        public boolean isInArea​(GameArea area)
        Checks if the NPC's current location is within the game area.
        Parameters:
        area - The GameArea to check.
        Returns:
        True if the NPC location is within the game area and false otherwise.
      • interact

        public boolean interact​(java.lang.String action)
        Description copied from interface: Interactable
        Interacts with the entity using the given action verb.
        Parameters:
        action - The menu action to trigger (e.g., "Attack", "Talk-to", "Take")
        Returns:
        true if the interaction packet was successfully queued/sent
      • attack

        public boolean attack()
        Attacks an NPC. This is a shallow wrapper around the interact() method.
        Returns:
        True if the attack interaction was successful and false otherwise
      • useWidget

        public boolean useWidget​(net.runelite.api.widgets.Widget widget)
        Uses a specified widget on the NPC (i.e. Casting Crumble Undead Spell on the Vorkaths Spawn)
        Parameters:
        widget - The widget to use on the NPC
        Returns:
        True if the interaction was successful and false otherwise