Class InventoryContainer

java.lang.Object
com.botwithus.bot.api.inventory.InventoryContainer
Direct Known Subclasses:
Backpack, Bank, Equipment

public class InventoryContainer extends Object
Snapshot-backed wrapper for one game inventory (backpack, bank, equipment, ...).

Reads ride on GameSnapshot.inventories() — no RPC for read paths. Item-name lookup goes through ItemType definitions cached by id at the subclass level (one cache per facade instance).

Slot interactions build a GameAction with action id ActionTypes.COMPONENT, the right-click option index in param1, the slot index (sub-component id) in param2, and the packed (iface<<16)|comp of the slot grid in param3. The packing matches what ApplyDeferredUpdate uses on the producer side.

Subclasses (Backpack, Bank, Equipment) bind the inventory id and the slot-grid component coordinates; this class holds the queries.

  • Constructor Details

    • InventoryContainer

      public InventoryContainer(GameAPI api, int invId)
      Read-only construction for ad-hoc inventories (shops, generic containers) where the script only needs item-list reads. Interface/component IDs are unset, so interact calls will fail — use Backpack, Bank, or Equipment for any inventory with click targets.
  • Method Details

    • invId

      public int invId()
    • interfaceId

      public int interfaceId()
    • componentId

      public int componentId()
    • clearDefinitionCache

      public final void clearDefinitionCache()
      Drop the ItemType cache. Useful between game updates or in tests.
    • definitionCacheSize

      public final int definitionCacheSize()
      Diagnostic — number of cached ItemType definitions.
    • getAllSlots

      public List<InventoryItem> getAllSlots()
      All slots, including empties. Empty list if the inventory isn't published yet.
    • getItems

      public List<InventoryItem> getItems()
      Non-empty slots only.
    • getSlot

      public InventoryItem getSlot(int slot)
      One slot by 0-based index, or null when out of range.
    • slotCount

      public int slotCount()
      Slot count from the snapshot header (0 when not published).
    • occupiedSlots

      public int occupiedSlots()
    • freeSlots

      public int freeSlots()
    • isEmpty

      public boolean isEmpty()
    • isNotEmpty

      public boolean isNotEmpty()
    • isFull

      public boolean isFull()
    • isNotFull

      public boolean isNotFull()
    • getSlotVars

      public Map<Integer,Integer> getSlotVars(int slot)
      Per-item obj vars for one slot — the per-instance variables the item in that slot carries inside its ObjVarDomain (augmentation XP, charges, etc.). Returns varId -> value, empty when the slot is empty or carries no obj vars. On-demand RPC read (not snapshot-backed).
    • getAllSlotVars

      public Map<Integer, Map<Integer,Integer>> getAllSlotVars()
      Per-item obj vars for every filled slot in this container. Returns slot -> (varId -> value), empty when nothing here carries obj vars. On-demand RPC read (not snapshot-backed).
    • contains

      public boolean contains(int itemId)
    • contains

      public boolean contains(int itemId, int amount)
      True when the total quantity of itemId is at least amount.
    • containsAny

      public boolean containsAny(int... itemIds)
    • containsAll

      public boolean containsAll(int... itemIds)
    • contains

      public boolean contains(String name)
      Containment by name (case-insensitive substring match against ItemType.name).
    • count

      public int count(int itemId)
    • count

      public int count(String name)
      Total quantity of items whose name matches (case-insensitive contains).
    • getFirst

      public InventoryItem getFirst(int itemId)
    • findFirst

      public Optional<InventoryItem> findFirst(int itemId)
    • getFirst

      public InventoryItem getFirst(String name)
    • findFirst

      public Optional<InventoryItem> findFirst(String name)
    • getAll

      public List<InventoryItem> getAll(String name)
    • containsGameval

      public boolean containsGameval(String gameval)
      Containment by gameval name, e.g. "YEW_LOGS".
    • countGameval

      public int countGameval(String gameval)
      Total quantity of the item with the given gameval name.
    • getFirstGameval

      public InventoryItem getFirstGameval(String gameval)
      First slot holding the item with the given gameval name, or null.
    • findFirstGameval

      public Optional<InventoryItem> findFirstGameval(String gameval)
      First slot holding the item with the given gameval name, as an Optional.
    • interactFirstGameval

      public boolean interactFirstGameval(String gameval, int optionIndex)
      Click the first slot holding the item with the given gameval name, using the given 1-based option index. false when the name doesn't resolve or the item isn't present.
    • interactFirstGameval

      public boolean interactFirstGameval(String gameval, String option)
      Click the first slot holding the item with the given gameval name, using the named option. false when the name doesn't resolve, the item isn't present, or the option isn't offered.
    • interact

      public boolean interact(int slot, int optionIndex)
      Click the given slot with the given 1-based right-click option index. Builds a GameAction with action id ActionTypes.COMPONENT (57), option in param1, the slot index in param2, and the packed (iface<<16)|comp of the slot grid in param3.
      Returns:
      true when a queue_action was sent (slot is in range); false when the slot index is out of range
    • interactFirst

      public boolean interactFirst(int itemId, int optionIndex)
      Click the first slot containing itemId with the given 1-based option index (no name lookup). Returns false if the item isn't in the inventory.
    • interactFirst

      public boolean interactFirst(int itemId, String option)
      Click the first slot containing itemId with the named option. Resolves option against ItemType.inventoryOptions. Returns false when the item isn't present or the option isn't on its menu.
    • interact

      public boolean interact(int itemId, String option)