Class InventoryContainer
java.lang.Object
com.botwithus.bot.api.inventory.InventoryContainer
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 Summary
ConstructorsConstructorDescriptionInventoryContainer(GameAPI api, int invId) Read-only construction for ad-hoc inventories (shops, generic containers) where the script only needs item-list reads. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidDrop the ItemType cache.intbooleancontains(int itemId) booleancontains(int itemId, int amount) True when the total quantity ofitemIdis at leastamount.booleanContainment by name (case-insensitive substring match against ItemType.name).booleancontainsAll(int... itemIds) booleancontainsAny(int... itemIds) booleancontainsGameval(String gameval) Containment by gameval name, e.g.intcount(int itemId) intTotal quantity of items whose name matches (case-insensitive contains).intcountGameval(String gameval) Total quantity of the item with the given gameval name.final intDiagnostic — number of cached ItemType definitions.findFirst(int itemId) findFirstGameval(String gameval) First slot holding the item with the given gameval name, as an Optional.intAll slots, including empties.Per-item obj vars for every filled slot in this container.getFirst(int itemId) getFirstGameval(String gameval) First slot holding the item with the given gameval name, ornull.getItems()Non-empty slots only.getSlot(int slot) One slot by 0-based index, ornullwhen out of range.getSlotVars(int slot) Per-item obj vars for one slot — the per-instance variables the item in that slot carries inside itsObjVarDomain(augmentation XP, charges, etc.).booleaninteract(int slot, int optionIndex) Click the given slot with the given 1-based right-click option index.booleanAlias forinteractFirst(int, String).booleaninteractFirst(int itemId, int optionIndex) Click the first slot containingitemIdwith the given 1-based option index (no name lookup).booleaninteractFirst(int itemId, String option) Click the first slot containingitemIdwith the named option.booleaninteractFirstGameval(String gameval, int optionIndex) Click the first slot holding the item with the given gameval name, using the given 1-based option index.booleaninteractFirstGameval(String gameval, String option) Click the first slot holding the item with the given gameval name, using the named option.intintinvId()booleanisEmpty()booleanisFull()booleanbooleanintintSlot count from the snapshot header (0 when not published).
-
Constructor Details
-
InventoryContainer
-
-
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
All slots, including empties. Empty list if the inventory isn't published yet. -
getItems
Non-empty slots only. -
getSlot
One slot by 0-based index, ornullwhen 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
Per-item obj vars for one slot — the per-instance variables the item in that slot carries inside itsObjVarDomain(augmentation XP, charges, etc.). ReturnsvarId -> value, empty when the slot is empty or carries no obj vars. On-demand RPC read (not snapshot-backed). -
getAllSlotVars
-
contains
public boolean contains(int itemId) -
contains
public boolean contains(int itemId, int amount) True when the total quantity ofitemIdis at leastamount. -
containsAny
public boolean containsAny(int... itemIds) -
containsAll
public boolean containsAll(int... itemIds) -
contains
Containment by name (case-insensitive substring match against ItemType.name). -
count
public int count(int itemId) -
count
Total quantity of items whose name matches (case-insensitive contains). -
getFirst
-
findFirst
-
getFirst
-
findFirst
-
getAll
-
containsGameval
Containment by gameval name, e.g."YEW_LOGS". -
countGameval
Total quantity of the item with the given gameval name. -
getFirstGameval
First slot holding the item with the given gameval name, ornull. -
findFirstGameval
First slot holding the item with the given gameval name, as an Optional. -
interactFirstGameval
Click the first slot holding the item with the given gameval name, using the given 1-based option index.falsewhen the name doesn't resolve or the item isn't present. -
interactFirstGameval
-
interact
public boolean interact(int slot, int optionIndex) Click the given slot with the given 1-based right-click option index. Builds aGameActionwith action idActionTypes.COMPONENT(57), option inparam1, the slot index inparam2, and the packed(iface<<16)|compof the slot grid inparam3.- Returns:
truewhen a queue_action was sent (slot is in range);falsewhen the slot index is out of range
-
interactFirst
public boolean interactFirst(int itemId, int optionIndex) Click the first slot containingitemIdwith the given 1-based option index (no name lookup). Returnsfalseif the item isn't in the inventory. -
interactFirst
Click the first slot containingitemIdwith the named option. ResolvesoptionagainstItemType.inventoryOptions. Returnsfalsewhen the item isn't present or the option isn't on its menu. -
interact
Alias forinteractFirst(int, String).
-