Class ItemContainerSnapshot

java.lang.Object
privbot.hooks.container.ItemContainerSnapshot

public final class ItemContainerSnapshot extends Object
Detached item facts, safe to rank on a worker or display on the UI without client access.
  • Field Details

    • items

      public final List<ItemContainerSnapshot.Item> items
      The occupied slots, in slot order (unmodifiable).
    • available

      public final boolean available
      False means unavailable, not an observed empty container.
  • Constructor Details

    • ItemContainerSnapshot

      public ItemContainerSnapshot(List<ItemContainerSnapshot.Item> items, boolean available)
      Parameters:
      items - the occupied slots (copied; no nulls)
      available - false when the container could not be read
  • Method Details

    • unavailable

      public static ItemContainerSnapshot unavailable()
      Returns:
      a snapshot of a container that could not be read: empty, and available false
    • size

      public int size()
      Returns:
      the number of occupied slots (0 also when unavailable: check available)
    • freeSlots

      public int freeSlots(int capacity)
      Parameters:
      capacity - the container's slot count (28 for the inventory)
      Returns:
      free slots; meaningless when unavailable
    • count

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

      public int count(String name)
      Total stack quantity for an exact, case-insensitive name.
    • count

      public int count(Predicate<ItemContainerSnapshot.Item> match)
      Parameters:
      match - the test
      Returns:
      total quantity of matching slots (saturates at Integer.MAX_VALUE)
    • slot

      public ItemContainerSnapshot.Item slot(int slot)
      Parameters:
      slot - a slot index
      Returns:
      the item in it, or null when empty
    • id

      public ItemContainerSnapshot.Item id(int id)
      Parameters:
      id - an item id
      Returns:
      the first slot holding it, or null
    • first

      Parameters:
      match - the test
      Returns:
      the first matching slot, or null
    • first

      public ItemContainerSnapshot.Item first(String name)
      Exact name first, then a case-insensitive substring match. Blank names never match.
    • firstOf

      public ItemContainerSnapshot.Item firstOf(String... names)
      Parameters:
      names - names in preference order (each: exact first, then substring)
      Returns:
      the first slot matching the earliest name that matches, or null
    • has

      public boolean has(String name)
      Parameters:
      name - an item name (exact, then substring)
      Returns:
      whether a slot matches
    • hasAny

      public boolean hasAny(String... names)
      Parameters:
      names - item names
      Returns:
      whether any of them matches a slot
    • firstWithAction

      public ItemContainerSnapshot.Item firstWithAction(String action)
      Parameters:
      action - a menu action ("Eat"), case-insensitive
      Returns:
      the first slot whose item lists it, or null
    • names

      public List<String> names()
      Returns:
      the item names in slot order (unmodifiable)