Class Inventory

java.lang.Object
privbot.hooks.Inventory

public final class Inventory extends Object
Inventory hook backed by the client's inventory snapshots.

For multi-step eat flows (query Eat, name patterns, id fallback), see InventoryFoodQueries.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(int... ids)
     
    boolean
    contains(String... names)
     
    int
    count(int id)
     
    int
    count(String exactName)
    Total quantity of items whose display name equals name (case-insensitive), e.g.
    static int
    countAll(int id)
    Static count that needs no ctx; prefer ctx.inventory.count(id).
    static int
    countAll(String exactName)
    Static count that needs no ctx; prefer ctx.inventory.count(name).
    boolean
    drink(String... names)
    Drinks the first inventory item matching any supplied name.
    boolean
    drinkFirst(String... names)
    Drinks the first inventory item matching any supplied name.
    boolean
    drop(String... names)
    Drops the first inventory item matching any supplied name.
    void
    dropAll(String... names)
    Drops every carried item matching names, one dispatch per slot.
    void
    dropAllExcept(int... keepIds)
    Drops every carried item whose id is not in keepIds; does nothing for an empty keep list.
    void
    dropAllExcept(String... keepNames)
    Drops every carried item whose name is not in keepNames; does nothing for an empty keep list.
    void
    Drops every carried item, keeping nothing.
    boolean
    eat(String... names)
    Eats the first inventory item matching any supplied name.
    boolean
    eatFirst(String... names)
    Eats the first inventory item matching any supplied name.
    boolean
    Eats the first inventory item with an Eat action.
    int
    Count of unoccupied inventory slots (max 28).
    static PrivItem
    Static lookup that needs no ctx; prefer ctx.inventory.get(pred).
    first(String... names)
    First inventory item matching any supplied name, or null.
    Same as get(Predicate); Scar-style name.
    First inventory item with an Eat action, or null.
    static boolean
    Static read that needs no ctx; prefer ctx.inventory.isFull().
    First inventory slot matching pred, or null.
    net.runelite.api.ItemContainer
    Returns the raw inventory ItemContainer.
    net.runelite.api.ItemContainer
    Returns the raw equipment ItemContainer.
    boolean
    has(String name)
    True when inventory holds at least one item whose display name matches name (case-insensitive contains, same semantics as contains(String...)).
    boolean
    Whether inventory holds at least one item with an Eat action.
    boolean
    interact(String name, String action)
    Interacts with the first item matching name using action.
    boolean
    Interact with a detached selection after confirming the slot still holds that item and action.
    boolean
     
    boolean
     
    boolean
    outOf(String name)
    True when inventory holds no item matching name.
    A fresh query over the carried items (one read per call).
    Detached facts captured in one client callback.
    boolean
    use(String... names)
    Uses the first inventory item matching any supplied name.
    boolean
    useOn(String sourceName, String targetName)
    Uses the first inventory item matching sourceName on the first item matching targetName (select then use-on-widget).
    boolean
    useOnObject(String itemName, PrivObject object)
    Uses the first inventory item matching itemName on object: select the item ("Use"), then use it on the object, the same two clicks a player makes (Elorin: op 447, then op 62 on the object's scene tag).
    boolean
    wield(String... names)
    Wields or wears the first inventory item matching any supplied name.

    Methods inherited from class java.lang.Object

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

    • snapshot

      public ItemContainerSnapshot snapshot()
      Detached facts captured in one client callback. A supplied client's item container is the source of truth; missing data returns available=false. Adapter-only instances use adapter rows. Repeated calls inside ctx.read(...) reuse the same observation.
    • interact

      public boolean interact(ItemContainerSnapshot.Item selected, String action)
      Interact with a detached selection after confirming the slot still holds that item and action. Delegates dispatch to the existing PrivItem/adapter mapping. True means accepted, not completed.
    • query

      public ItemQuery query()
      A fresh query over the carried items (one read per call).
      Returns:
      the query
    • getContainer

      public net.runelite.api.ItemContainer getContainer()
      Returns the raw inventory ItemContainer. Prefer query(); this exists so callers can replace direct client.getItemContainer(INVENTORY) without rewriting inline ItemContainer iteration logic.
    • getEquipmentContainer

      public net.runelite.api.ItemContainer getEquipmentContainer()
      Returns the raw equipment ItemContainer. Prefer ctx.equipment accessors; this exists for legacy drop-in replacement of client.getItemContainer(EQUIPMENT).
    • contains

      public boolean contains(int... ids)
      Parameters:
      ids - item ids
      Returns:
      whether any carried item has one of ids
    • contains

      public boolean contains(String... names)
      Parameters:
      names - item names (matched as ItemQuery.withName(java.lang.String...) does)
      Returns:
      whether any carried item matches
    • count

      public int count(int id)
      Parameters:
      id - an item id
      Returns:
      the total quantity carried with that id
    • count

      public int count(String exactName)
      Total quantity of items whose display name equals name (case-insensitive), e.g. for Inventory.count(food.getName()) patterns.
    • has

      public boolean has(String name)
      True when inventory holds at least one item whose display name matches name (case-insensitive contains, same semantics as contains(String...)).
    • outOf

      public boolean outOf(String name)
      True when inventory holds no item matching name. Inverse of has(String).
    • get

      public PrivItem get(Predicate<PrivItem> pred)
      First inventory slot matching pred, or null.
    • first

      public PrivItem first(Predicate<PrivItem> pred)
      Same as get(Predicate); Scar-style name.
    • first

      public PrivItem first(String... names)
      First inventory item matching any supplied name, or null.
    • hasFood

      public boolean hasFood()
      Whether inventory holds at least one item with an Eat action.
    • food

      public PrivItem food()
      First inventory item with an Eat action, or null.
    • eatFood

      public boolean eatFood()
      Eats the first inventory item with an Eat action.
    • eatFirst

      public boolean eatFirst(String... names)
      Eats the first inventory item matching any supplied name.
    • eat

      public boolean eat(String... names)
      Eats the first inventory item matching any supplied name.
    • drinkFirst

      public boolean drinkFirst(String... names)
      Drinks the first inventory item matching any supplied name.
    • drink

      public boolean drink(String... names)
      Drinks the first inventory item matching any supplied name.
    • interact

      public boolean interact(String name, String action)
      Interacts with the first item matching name using action.
    • drop

      public boolean drop(String... names)
      Drops the first inventory item matching any supplied name.
    • wield

      public boolean wield(String... names)
      Wields or wears the first inventory item matching any supplied name.
    • use

      public boolean use(String... names)
      Uses the first inventory item matching any supplied name.
    • useOn

      public boolean useOn(String sourceName, String targetName)
      Uses the first inventory item matching sourceName on the first item matching targetName (select then use-on-widget).
    • useOnObject

      public boolean useOnObject(String itemName, PrivObject object)
      Uses the first inventory item matching itemName on object: select the item ("Use"), then use it on the object, the same two clicks a player makes (Elorin: op 447, then op 62 on the object's scene tag). interact("Use") is NOT this: it maps to the item's first option, so bones were buried instead of offered (2026-10-18). Objects have no literal "Use" action either, so the second click cannot be object.interact("Use").
    • emptySlots

      public int emptySlots()
      Count of unoccupied inventory slots (max 28).
    • isFull

      public boolean isFull()
      Returns:
      whether all 28 slots hold an item (false also when the inventory cannot be read)
    • isEmpty

      public boolean isEmpty()
      Returns:
      whether nothing is carried (also true when unreadable: use snapshot() to tell apart)
    • dropAll

      public void dropAll(String... names)
      Drops every carried item matching names, one dispatch per slot.
      Parameters:
      names - item names
    • dropEverything

      public void dropEverything()
      Drops every carried item, keeping nothing.

      Deliberately separate from dropAllExcept(String...), which returns without dropping anything when handed an empty keep list — a safety net for callers that build the list dynamically. "Drop everything" therefore has to be asked for by name, so it can never be the accidental result of an empty parameter.

    • dropAllExcept

      public void dropAllExcept(int... keepIds)
      Drops every carried item whose id is not in keepIds; does nothing for an empty keep list.
      Parameters:
      keepIds - item ids to keep
    • dropAllExcept

      public void dropAllExcept(String... keepNames)
      Drops every carried item whose name is not in keepNames; does nothing for an empty keep list.
      Parameters:
      keepNames - item names to keep
    • full

      public static boolean full()
      Static read that needs no ctx; prefer ctx.inventory.isFull().
      Returns:
      whether the inventory is full
    • find

      public static PrivItem find(Predicate<PrivItem> pred)
      Static lookup that needs no ctx; prefer ctx.inventory.get(pred).
      Parameters:
      pred - the test
      Returns:
      the first matching carried item, or null
    • countAll

      public static int countAll(int id)
      Static count that needs no ctx; prefer ctx.inventory.count(id).
      Parameters:
      id - an item id
      Returns:
      the total quantity carried
    • countAll

      public static int countAll(String exactName)
      Static count that needs no ctx; prefer ctx.inventory.count(name).
      Parameters:
      exactName - the exact item name
      Returns:
      the total quantity carried