Interface NpcContainer


public interface NpcContainer
A container that manages and caches NPC (Non-Player Character) instances.

This interface provides low-level access to the NPC cache, which maintains wrapped INPC instances for all NPCs in the current world view. The container is responsible for creating, updating, and removing NPC wrappers as NPCs spawn, change, or despawn in the game.

The container is updated each game tick and responds to NPC-related events to ensure the cache remains synchronized with the game state. Each NPC is indexed by its server-assigned index, allowing O(1) retrieval.

For most use cases, prefer using INPCs which provides a higher-level API with filtering and searching capabilities.

Example usage:

 
 // Get an NPC by index
 INPC npc = npcContainer.get(1234);

 // Get all cached NPCs
 Collection<INPC> allNpcs = npcContainer.getAll();

 // Get the hint-arrowed NPC
 INPC hinted = npcContainer.getHintArrowed();

 // Get the player's follower (pet)
 INPC pet = npcContainer.getFollower();
 
 

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    create(net.runelite.api.NPC npc)
    Creates or updates an NPC wrapper for the given RuneLite NPC.
    get(int index)
    Gets an NPC by its server-assigned index.
    Gets all NPCs currently in the cache.
    Gets the player's follower NPC (pet).
    Gets the NPC that currently has the hint arrow pointing to it.
  • Method Details

    • get

      INPC get(int index)
      Gets an NPC by its server-assigned index.

      The index is unique to each NPC instance in the game and is assigned by the server. This is different from the NPC's definition ID (which identifies the NPC type).

      Parameters:
      index - the server-assigned NPC index
      Returns:
      the cached NPC wrapper, or null if no NPC exists at that index
    • getAll

      Collection<INPC> getAll()
      Gets all NPCs currently in the cache.

      Returns a collection of all NPC wrappers that are currently being tracked by this container. The collection represents a snapshot of all visible NPCs in the current world view.

      Returns:
      a collection of all cached NPCs; never null but may be empty
    • getHintArrowed

      INPC getHintArrowed()
      Gets the NPC that currently has the hint arrow pointing to it.

      The hint arrow is a visual indicator typically used by the game to highlight quest-related NPCs or other important characters that the player should interact with.

      Returns:
      the hint-arrowed NPC, or null if no NPC has a hint arrow
    • getFollower

      INPC getFollower()
      Gets the player's follower NPC (pet).

      A follower is an NPC that follows the player around, such as a pet. Only one follower can be active at a time.

      Returns:
      the follower NPC, or null if the player has no active follower
    • create

      INPC create(net.runelite.api.NPC npc)
      Creates or updates an NPC wrapper for the given RuneLite NPC.

      If a wrapper already exists for this NPC (based on its index), the existing wrapper is updated with the new NPC data. Otherwise, a new wrapper is created and added to the cache.

      This method is primarily used internally by the container to maintain the cache in response to game events.

      Parameters:
      npc - the RuneLite NPC to wrap
      Returns:
      the created or updated NPC wrapper