Class Inventory

java.lang.Object
com.valhalla.sdk.api.methods.Inventory

public final class Inventory extends Object
Inventory-container queries and capability-backed item actions.

Check Client.supports(String) with Capabilities.INVENTORY before depending on inventory state. Query methods operate on immutable Item snapshots. Action methods return whether native dispatch was accepted, not whether the server applied the action; confirm the expected inventory change in a later loop.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Number of slots in the standard player inventory.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<Item>
    all()
    Returns all occupied inventory slots.
    static int
    Returns standard inventory capacity.
    static boolean
    contains(int id)
    Tests whether an identifier exists.
    static boolean
    contains(int... ids)
    Tests whether any identifier exists.
    static boolean
    contains(Filter<Item> filter)
    Tests whether any item matches a filter.
    static boolean
    contains(Integer... ids)
    Tests whether any boxed identifier exists.
    static boolean
    Tests whether an exact name exists.
    static boolean
    contains(String... names)
    Tests whether any exact name exists.
    static boolean
    containsAll(int... ids)
    Requires every supplied identifier to appear at least once.
    static boolean
    containsAll(String... names)
    Requires every supplied exact name to appear at least once.
    static boolean
    Requires each item, number, or string in a heterogeneous collection to be present.
    static int
    count(int id)
    Counts stack amounts for one identifier.
    static int
    count(Filter<Item> filter)
    Counts stack amounts accepted by a filter.
    static int
    count(String name)
    Counts stack amounts for one exact case-insensitive name.
    static boolean
    drop(Item item)
    Executes the second item operation, conventionally Drop for ordinary inventory items.
    static int
    Counts vacant inventory slots.
    static List<Item>
    except(Filter<Item> filter)
    Selects items rejected by a filter.
    static int
    Counts full inventory slots.
    static Optional<Item>
    get(int id)
    Finds the first item with an identifier.
    static Optional<Item>
    get(int... ids)
    Finds the first item matching any primitive identifier.
    static Optional<Item>
    get(Filter<Item> filter)
    Finds the first item accepted by a filter.
    static Optional<Item>
    get(Integer... ids)
    Finds the first item matching any boxed non-null identifier.
    static Optional<Item>
    get(String name)
    Finds the first item whose full name equals a value, ignoring case.
    static Optional<Item>
    get(String... names)
    Finds the first item whose full name equals any value, ignoring case.
    static Optional<Item>
    getAt(int slot)
    Finds the item occupying a zero-based slot.
    static int
    Counts vacant inventory slots.
    static int
    Finds the first empty slot.
    static int
    Finds the first occupied slot.
    static int
    getIdForSlot(int slot)
    Returns an occupied slot's identifier.
    static Optional<Item>
    getItemInSlot(int slot)
    Alias for getAt(int).
    static String
    getNameForSlot(int slot)
    Returns an occupied slot's name.
    static Optional<Item>
    getRandom(int... ids)
    Selects a random item matching any identifier.
    static Optional<Item>
    Selects a uniformly random item accepted by a filter.
    static Optional<Item>
    getRandom(String... names)
    Selects a random item matching any exact name, ignoring case.
    static boolean
    interact(int id)
    Dispatches the default operation for the first item with an identifier.
    static boolean
    interact(Item item)
    Dispatches the default operation for an item's current slot.
    static boolean
    interact(Filter<Item> filter)
    Dispatches the default operation for the first filtered item.
    static boolean
    Dispatches the default operation for the first exact-name match.
    static boolean
    interactSlot(int slot)
    Dispatches the default operation for a valid inventory slot.
    static boolean
    Reports whether the inventory is empty.
    static boolean
    Reports whether the inventory is full.
    static boolean
    Reports whether the active adapter advertises inventory snapshots.
    static boolean
    isSlotEmpty(int slot)
    Tests whether a valid slot is vacant.
    static boolean
    isSlotFull(int slot)
    Tests whether a valid slot is occupied.
    static List<Item>
    matching(Filter<Item> filter)
    Selects every item accepted by a filter.
    static int
    Counts occupied inventory slots.
    static boolean
    onlyContains(int... ids)
    Tests whether a non-empty inventory contains only allowed identifiers.
    static boolean
    Tests whether every item in a non-empty inventory satisfies a filter.
    static boolean
    onlyContains(String... names)
    Tests whether a non-empty inventory contains only allowed names.
    static boolean
    Opens the inventory tab.
    static int
    Returns inventory size by occupied slots.
    static int
    slot(int id)
    Finds the first slot matching an identifier.
    static int
    slot(Filter<Item> filter)
    Finds the first slot accepted by a filter.
    static int
    slot(String name)
    Finds the first slot matching a name.
    static boolean
    slotContains(int slot, int... ids)
    Tests whether a slot contains any candidate identifier.
    static boolean
    slotContains(int slot, Item item)
    Compares a slot to an item by definition identifier.
    static boolean
    slotContains(int slot, Filter<Item> filter)
    Tests an occupied slot with a predicate.
    static boolean
    slotContains(int slot, String... names)
    Tests whether a slot contains any exact name, ignoring case.
    static boolean
    slotInteract(int slot)
    static boolean
    slotNameContains(int slot, String substring)
    Tests whether a slot's name contains text, ignoring case.
    static Item[]
    Copies inventory snapshots into an array.
    static boolean
    use(int id)
    Compatibility alias for interact(int).
    static boolean
    use(Item item)
    Compatibility alias for interact(Item).
    static boolean
    use(String name)
    Compatibility alias for interact(String).

    Methods inherited from class java.lang.Object

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

    • CAPACITY

      public static final int CAPACITY
      Number of slots in the standard player inventory.
      See Also:
  • Method Details

    • capacity

      public static int capacity()
      Returns standard inventory capacity.
      Returns:
      standard inventory capacity of 28 slots
    • all

      public static List<Item> all()
      Returns all occupied inventory slots.
      Returns:
      inventory item snapshots in native container order
    • matching

      public static List<Item> matching(Filter<Item> filter)
      Selects every item accepted by a filter.
      Parameters:
      filter - item predicate
      Returns:
      matching snapshots in container order
    • get

      public static Optional<Item> get(int id)
      Finds the first item with an identifier.
      Parameters:
      id - item definition identifier
      Returns:
      first matching snapshot, or empty
    • get

      public static Optional<Item> get(int... ids)
      Finds the first item matching any primitive identifier.
      Parameters:
      ids - candidate item identifiers
      Returns:
      first matching snapshot, or empty for no candidates or no match
    • get

      public static Optional<Item> get(Integer... ids)
      Finds the first item matching any boxed non-null identifier.
      Parameters:
      ids - candidate item identifiers
      Returns:
      first matching snapshot, or empty for no candidates or no match
    • get

      public static Optional<Item> get(String name)
      Finds the first item whose full name equals a value, ignoring case.
      Parameters:
      name - exact item name
      Returns:
      first matching snapshot, or empty
    • get

      public static Optional<Item> get(String... names)
      Finds the first item whose full name equals any value, ignoring case.
      Parameters:
      names - exact candidate names
      Returns:
      first matching snapshot, or empty
    • get

      public static Optional<Item> get(Filter<Item> filter)
      Finds the first item accepted by a filter.
      Parameters:
      filter - item predicate
      Returns:
      first matching snapshot, or empty
    • getAt

      public static Optional<Item> getAt(int slot)
      Finds the item occupying a zero-based slot.
      Parameters:
      slot - inventory slot
      Returns:
      item snapshot, or empty when the slot is vacant or out of range
    • getItemInSlot

      public static Optional<Item> getItemInSlot(int slot)
      Alias for getAt(int).
      Parameters:
      slot - inventory slot
      Returns:
      item snapshot, or empty
    • contains

      public static boolean contains(int id)
      Tests whether an identifier exists.
      Parameters:
      id - item identifier
      Returns:
      whether at least one matching item exists
    • contains

      public static boolean contains(int... ids)
      Tests whether any identifier exists.
      Parameters:
      ids - candidate identifiers
      Returns:
      whether at least one candidate exists
    • contains

      public static boolean contains(Integer... ids)
      Tests whether any boxed identifier exists.
      Parameters:
      ids - candidate boxed identifiers
      Returns:
      whether at least one candidate exists
    • contains

      public static boolean contains(String name)
      Tests whether an exact name exists.
      Parameters:
      name - exact case-insensitive name
      Returns:
      whether a matching item exists
    • contains

      public static boolean contains(String... names)
      Tests whether any exact name exists.
      Parameters:
      names - exact candidate names
      Returns:
      whether at least one candidate exists
    • contains

      public static boolean contains(Filter<Item> filter)
      Tests whether any item matches a filter.
      Parameters:
      filter - item predicate
      Returns:
      whether at least one item is accepted
    • count

      public static int count(int id)
      Counts stack amounts for one identifier.
      Parameters:
      id - item identifier
      Returns:
      sum of matching stack amounts
    • count

      public static int count(String name)
      Counts stack amounts for one exact case-insensitive name.
      Parameters:
      name - exact item name
      Returns:
      sum of matching stack amounts, or zero for null
    • count

      public static int count(Filter<Item> filter)
      Counts stack amounts accepted by a filter.
      Parameters:
      filter - item predicate
      Returns:
      sum of matching stack amounts
    • occupiedSlots

      public static int occupiedSlots()
      Counts occupied inventory slots.
      Returns:
      number of occupied inventory slots, independent of stack amounts
    • fullSlotCount

      public static int fullSlotCount()
      Counts full inventory slots.
      Returns:
      number of occupied inventory slots; alias for occupiedSlots()
    • emptySlotCount

      public static int emptySlotCount()
      Counts vacant inventory slots.
      Returns:
      number of vacant slots from zero through CAPACITY
    • getEmptySlots

      public static int getEmptySlots()
      Counts vacant inventory slots.
      Returns:
      number of vacant slots; alias for emptySlotCount()
    • isEmpty

      public static boolean isEmpty()
      Reports whether the inventory is empty.
      Returns:
      whether no inventory item snapshots are present
    • isFull

      public static boolean isFull()
      Reports whether the inventory is full.
      Returns:
      whether all 28 inventory slots are occupied
    • size

      public static int size()
      Returns inventory size by occupied slots.
      Returns:
      number of occupied slots; alias for occupiedSlots()
    • getFirstEmptySlot

      public static int getFirstEmptySlot()
      Finds the first empty slot.
      Returns:
      lowest vacant slot index, or -1 when full
    • getFirstFullSlot

      public static int getFirstFullSlot()
      Finds the first occupied slot.
      Returns:
      lowest occupied slot index, or -1 when empty
    • slot

      public static int slot(int id)
      Finds the first slot matching an identifier.
      Parameters:
      id - item identifier
      Returns:
      first matching slot, or -1
    • slot

      public static int slot(String name)
      Finds the first slot matching a name.
      Parameters:
      name - exact case-insensitive name
      Returns:
      first matching slot, or -1
    • slot

      public static int slot(Filter<Item> filter)
      Finds the first slot accepted by a filter.
      Parameters:
      filter - item predicate
      Returns:
      first matching slot, or -1
    • getIdForSlot

      public static int getIdForSlot(int slot)
      Returns an occupied slot's identifier.
      Parameters:
      slot - inventory slot
      Returns:
      item identifier, or -1 when vacant
    • getNameForSlot

      public static String getNameForSlot(int slot)
      Returns an occupied slot's name.
      Parameters:
      slot - inventory slot
      Returns:
      item name, or an empty string when vacant
    • slotContains

      public static boolean slotContains(int slot, int... ids)
      Tests whether a slot contains any candidate identifier.
      Parameters:
      slot - inventory slot
      ids - candidate identifiers
      Returns:
      true when the occupied slot matches one candidate
    • slotContains

      public static boolean slotContains(int slot, String... names)
      Tests whether a slot contains any exact name, ignoring case.
      Parameters:
      slot - inventory slot
      names - candidate names
      Returns:
      true when the occupied slot matches one candidate
    • containsAll

      public static boolean containsAll(int... ids)
      Requires every supplied identifier to appear at least once.
      Parameters:
      ids - required identifiers
      Returns:
      true when every identifier is present; false for null
    • containsAll

      public static boolean containsAll(String... names)
      Requires every supplied exact name to appear at least once.
      Parameters:
      names - required case-insensitive names
      Returns:
      true when every name is present; false for null
    • containsAll

      public static boolean containsAll(Collection<?> values)
      Requires each item, number, or string in a heterogeneous collection to be present.
      Parameters:
      values - required Item, Number, or String values
      Returns:
      false for null, unsupported element types, or a missing value
    • onlyContains

      public static boolean onlyContains(int... ids)
      Tests whether a non-empty inventory contains only allowed identifiers.
      Parameters:
      ids - allowed identifiers
      Returns:
      true when every item is allowed; false for null or empty inventory
    • onlyContains

      public static boolean onlyContains(Filter<Item> filter)
      Tests whether every item in a non-empty inventory satisfies a filter.
      Parameters:
      filter - allowed-item predicate
      Returns:
      true when every item is accepted and the inventory is non-empty
    • onlyContains

      public static boolean onlyContains(String... names)
      Tests whether a non-empty inventory contains only allowed names.
      Parameters:
      names - allowed exact case-insensitive names
      Returns:
      true when every item is allowed; false for null or empty inventory
    • except

      public static List<Item> except(Filter<Item> filter)
      Selects items rejected by a filter.
      Parameters:
      filter - exclusion predicate
      Returns:
      snapshots for which the predicate returned false
    • toArray

      public static Item[] toArray()
      Copies inventory snapshots into an array.
      Returns:
      inventory snapshots as a newly allocated array
    • isSlotEmpty

      public static boolean isSlotEmpty(int slot)
      Tests whether a valid slot is vacant.
      Parameters:
      slot - inventory slot
      Returns:
      true only for a valid vacant slot
    • isSlotFull

      public static boolean isSlotFull(int slot)
      Tests whether a valid slot is occupied.
      Parameters:
      slot - inventory slot
      Returns:
      true only for a valid occupied slot
    • slotContains

      public static boolean slotContains(int slot, Filter<Item> filter)
      Tests an occupied slot with a predicate.
      Parameters:
      slot - inventory slot
      filter - item predicate
      Returns:
      true when the slot is occupied and accepted
    • slotContains

      public static boolean slotContains(int slot, Item item)
      Compares a slot to an item by definition identifier.
      Parameters:
      slot - inventory slot
      item - comparison item
      Returns:
      true when the occupied slot has the same identifier
    • slotNameContains

      public static boolean slotNameContains(int slot, String substring)
      Tests whether a slot's name contains text, ignoring case.
      Parameters:
      slot - inventory slot
      substring - name fragment
      Returns:
      true when an occupied slot's name contains the fragment
    • getRandom

      public static Optional<Item> getRandom(Filter<Item> filter)
      Selects a uniformly random item accepted by a filter.
      Parameters:
      filter - item predicate
      Returns:
      random matching snapshot, or empty
    • getRandom

      public static Optional<Item> getRandom(int... ids)
      Selects a random item matching any identifier.
      Parameters:
      ids - candidate identifiers
      Returns:
      random matching snapshot, or empty
    • getRandom

      public static Optional<Item> getRandom(String... names)
      Selects a random item matching any exact name, ignoring case.
      Parameters:
      names - candidate names
      Returns:
      random matching snapshot, or empty
    • interactSlot

      public static boolean interactSlot(int slot)
      Dispatches the default operation for a valid inventory slot.
      Parameters:
      slot - zero-based inventory slot
      Returns:
      true when the capability is available and dispatch was accepted
    • slotInteract

      public static boolean slotInteract(int slot)
      Parameters:
      slot - zero-based inventory slot
      Returns:
      true when dispatch was accepted
    • interact

      public static boolean interact(Item item)
      Dispatches the default operation for an item's current slot.
      Parameters:
      item - current inventory snapshot
      Returns:
      true when dispatch was accepted
    • interact

      public static boolean interact(int id)
      Dispatches the default operation for the first item with an identifier.
      Parameters:
      id - item identifier
      Returns:
      true when a matching item existed and dispatch was accepted
    • interact

      public static boolean interact(String name)
      Dispatches the default operation for the first exact-name match.
      Parameters:
      name - exact case-insensitive name
      Returns:
      true when a matching item existed and dispatch was accepted
    • interact

      public static boolean interact(Filter<Item> filter)
      Dispatches the default operation for the first filtered item.
      Parameters:
      filter - item predicate
      Returns:
      true when a matching item existed and dispatch was accepted
    • use

      public static boolean use(Item item)
      Compatibility alias for interact(Item).
      Parameters:
      item - current inventory snapshot
      Returns:
      true when dispatch was accepted
    • use

      public static boolean use(int id)
      Compatibility alias for interact(int).
      Parameters:
      id - item identifier
      Returns:
      true when dispatch was accepted
    • use

      public static boolean use(String name)
      Compatibility alias for interact(String).
      Parameters:
      name - exact case-insensitive name
      Returns:
      true when dispatch was accepted
    • drop

      public static boolean drop(Item item)
      Executes the second item operation, conventionally Drop for ordinary inventory items.
      Parameters:
      item - current inventory snapshot
      Returns:
      true when dispatch was accepted; verify removal separately
    • open

      public static boolean open()
      Opens the inventory tab.
      Returns:
      true when opening the inventory tab was accepted
    • isLoaded

      public static boolean isLoaded()
      Reports whether the active adapter advertises inventory snapshots.
      Returns:
      true when Capabilities.INVENTORY is available