InventoryAPI
Read your 28 inventory slots and use the items in them.
ClassRLPlugins API
public class InventoryAPINames in contains and containsAny ignore capital letters. Names in count, getItem and interact must match exactly, including capital letters.
Actions also ignore capital letters, and "Wear", "Wield" and "Equip" count as the same action.
Example
@Subscribe
public void onGameTick(GameTick tick) {
if (!GameAPI.isLoggedIn()) {
return;
}
for (ItemEx item : InventoryAPI.getItems()) {
if ("Logs".equals(item.getName())) {
InventoryAPI.interact(item, "Drop");
return; // one item per tick
}
}
}Members
Static methods
- intcanonicalCount(int...)
Counts items whether they are noted or not.
- booleancontains(String...)
Whether you have all of these items.
- booleancontains(int...)
Whether you have all of these items.
- booleancontainsAny(String...)
Whether you have at least one of these items.
- booleancontainsAny(int...)
Whether you have at least one of these items.
- intcount(String...)
Counts items by name.
- intcount(int...)
Counts items by ID.
- voiddeselectItem()
Clears the current selected inventory item.
- voiddragItem(ItemEx, int)
Drags an inventory item to another slot.
- voiddragItem(int, int)
Drags an inventory item to another slot.
- voiddragItem(int, int, int)
Drags an inventory item to another slot.
- intdropAll(List<Integer>)
Drop all items from your inventory by list of ids.
- intdropAll(String)
Drops every item with one of these ids. Returns how many it dropped.
- intdropAll(String...)
Drop all items from your inventory by list of ids.
- intdropAll(int)
Drop all items from your inventory by list of ids.
- intdropAll(int...)
Drop all items from your inventory by list of ids.
- intgetCount(int)
Get the total count of an item in your inventory by id.
- intgetCount(int, boolean)
Get the total count of an item in your inventory by id.
- intgetEmptySlots()
How many inventory slots are free.
- ItemExgetItem(Predicate<ItemEx>)
Get an item in your inventory by predicate.
- ItemExgetItem(String)
The first item with this name.
- ItemExgetItem(int)
The first item with this ID.
- List<ItemEx>getItems()
Every item in your inventory.
- StringgetSelectedItemName()
Gets the name of the currently selected inventory item.
- booleanhasAction(ItemEx, String)
Whether an item offers an action.
- voidinteract(ItemEx, String)
Clicks an action on an item.
- voidinteract(ItemEx, String...)
Clicks the first of these actions the item offers.
- voidinteract(ItemEx, int)
Interact with an item in your inventory by action index.
- voidinteract(String, String)
Clicks an action on the first item with this name.
- voidinteract(String, int)
Interact with an item in your inventory by name and action index.
- voidinteract(int, String)
Clicks an action on the first item with this ID.
- voidinteract(int[], int)
Interact with the first item found in your inventory by ids and action index.
- voidinteract(int, int)
Interact with an item in your inventory by id and action index.
- voidinteractSubOp(ItemEx, String, String)
Interact with an item in your inventory by subOp and action.
- voidinteractSubOp(String, String, String)
Interact with an item in your inventory by name, subOp and action.
- voidinteractSubOp(int, String, String)
Interact with an item in your inventory by id, subOp and action.
- booleanisEmpty()
Whether your inventory is empty.
- booleanisFull()
Whether all 28 slots are used.
- booleanisItemSelected()
Checks whether an inventory item is currently selected for a use-on action.
- voiditemAction(int, int, int)
Interact with an item in your inventory by slot, id and action index.
- booleanreorder(InventoryProfile)
Move one available item towards its saved slot; call again after a game tick.
- InventoryQuerysearch()
Creates an instance of InventoryQuery from the Inventory.
- booleanselectItem(ItemEx)
Select a current inventory item for the player's next use-on click.
- voiduseOn(ItemEx, ItemEx)
Use an item on another item in your inventory.
- voiduseOn(ItemEx, NpcEx)
Use an item on an npc.
- voiduseOn(ItemEx, PlayerEx)
Use an item on a player.
- voiduseOn(ItemEx, TileItemEx)
Use an item on a ground item.
- voiduseOn(ItemEx, TileObjectEx)
Use an item on a tile object.
- voiduseOnEquipment(ItemEx, ItemEx)
Use an inventory item on an equipped item, preserving each container's widget identity.
canonicalCount(int...)static
public static int canonicalCount(int... itemIds)Counts items whether they are noted or not.
Pass the unnoted ID: its noted form counts too.
Parameters
itemIds- Unnoted item IDs.
Returns
The total quantity of both forms.
contains(String...)static
public static boolean contains(String... itemNames)Whether you have all of these items.
Parameters
itemNames- One or more item names. Capital letters are ignored.
Returns
true only if every name is in your inventory.
contains(int...)static
public static boolean contains(int... itemIds)Whether you have all of these items.
Parameters
itemIds- One or more item IDs.
Returns
true only if every ID is in your inventory.
containsAny(String...)static
public static boolean containsAny(String... itemNames)Whether you have at least one of these items.
Parameters
itemNames- One or more item names. Capital letters are ignored.
Returns
true if any of the names is in your inventory.
containsAny(int...)static
public static boolean containsAny(int... itemIds)Whether you have at least one of these items.
Parameters
itemIds- One or more item IDs.
Returns
true if any of the IDs is in your inventory.
count(String...)static
public static int count(String... itemNames)Counts items by name.
Parameters
itemNames- Exact item names, including capital letters.
Returns
The total quantity over all slots. A stack counts its full amount.
count(int...)static
public static int count(int... itemIds)Counts items by ID.
Parameters
itemIds- One or more item IDs.
Returns
The total quantity over all slots. A stack counts its full amount.
int lobsters = InventoryAPI.count(379);deselectItem()static
public static void deselectItem()Clears the current selected inventory item.
dragItem(ItemEx, int)static
public static void dragItem(ItemEx item, int toSlot)Drags an inventory item to another slot.
Parameters
item- Item.
toSlot- To slot.
dragItem(int, int)static
public static void dragItem(int id, int toSlot)Drags an inventory item to another slot.
Parameters
id- Id.
toSlot- To slot.
dragItem(int, int, int)static
public static void dragItem(int itemId, int fromSlot, int toSlot)Drags an inventory item to another slot.
Parameters
itemId- Item id.
fromSlot- From slot.
toSlot- To slot.
dropAll(List<Integer>)static
public static int dropAll(List<Integer> ids)Drop all items from your inventory by list of ids.
Parameters
ids- Item ids to drop.
Returns
Number of ticks it will take.
dropAll(String)static
public static int dropAll(String name)Drops every item with one of these ids. Returns how many it dropped.
Parameters
name- Name.
dropAll(String...)static
public static int dropAll(String... ids)Drop all items from your inventory by list of ids.
Parameters
ids- Item ids to drop.
Returns
Number of ticks it will take.
dropAll(int)static
public static int dropAll(int id)Drop all items from your inventory by list of ids.
Parameters
id- Item id to drop.
Returns
Number of ticks it will take.
dropAll(int...)static
public static int dropAll(int... ids)Drop all items from your inventory by list of ids.
Parameters
ids- Item ids to drop.
Returns
Number of ticks it will take.
getCount(int)static
public static int getCount(int id)Get the total count of an item in your inventory by id.
Parameters
id- Item id.
Returns
Int.
getCount(int, boolean)static
public static int getCount(int id, boolean canonicalize)Get the total count of an item in your inventory by id.
Parameters
id- Item id.
canonicalize- Whether to canonicalize the id (normalize all ids to un-noted version for the count).
Returns
Int.
getEmptySlots()static
public static int getEmptySlots()How many inventory slots are free.
Returns
From 0 to 28.
getItem(Predicate<ItemEx>)static
public static ItemEx getItem(Predicate<ItemEx> predicate)Get an item in your inventory by predicate.
Parameters
predicate- Predicate.
Returns
ItemEx.
getItem(String)static
public static ItemEx getItem(String itemName)The first item with this name.
Parameters
itemName- The exact item name, including capital letters.
Returns
The item, or null if you do not have it.
getItem(int)static
public static ItemEx getItem(int itemId)The first item with this ID.
Parameters
itemId- The item ID.
Returns
The item, or null if you do not have it.
getItems()static
public static List<ItemEx> getItems()Every item in your inventory.
Returns
One ItemEx per filled slot. Empty slots are left out.
getSelectedItemName()static
public static String getSelectedItemName()Gets the name of the currently selected inventory item.
Returns
Selected item name, or null when no inventory item is selected.
hasAction(ItemEx, String)static
public static boolean hasAction(ItemEx item, String action)Whether an item offers an action.
Parameters
item- An item from your inventory.
action- An action such as
"Eat", or an option inside one of the item's submenus.
Returns
true if the item's menu has the action.
interact(ItemEx, String)static
public static void interact(ItemEx item, String action)Clicks an action on an item.
Parameters
item- An item from your inventory.
action- The action to click.
ItemEx food = InventoryAPI.getItem("Lobster");
if (food != null) {
InventoryAPI.interact(food, "Eat");
}interact(ItemEx, String...)static
public static void interact(ItemEx item, String... actions)Clicks the first of these actions the item offers.
Parameters
item- An item from your inventory.
actions- Actions to try, in order.
ItemEx potion = InventoryAPI.getItem("Prayer potion(4)");
if (potion != null) {
InventoryAPI.interact(potion, "Drink", "Use");
}interact(ItemEx, int)static
public static void interact(ItemEx item, int action)Interact with an item in your inventory by action index.
Parameters
item- Item.
action- Action index.
interact(String, String)static
public static void interact(String itemName, String action)Clicks an action on the first item with this name.
Does nothing if you do not have the item.
Parameters
itemName- The exact item name, including capital letters.
action- The action to click.
interact(String, int)static
public static void interact(String itemName, int action)Interact with an item in your inventory by name and action index.
Parameters
itemName- Item name.
action- Action index.
interact(int, String)static
public static void interact(int itemId, String action)Clicks an action on the first item with this ID.
Does nothing if you do not have the item.
Parameters
itemId- The item ID.
action- The action to click, such as
"Eat".
interact(int[], int)static
public static void interact(int[] itemIds, int action)Interact with the first item found in your inventory by ids and action index.
Parameters
itemIds- Item ids.
action- Action index.
interact(int, int)static
public static void interact(int itemId, int action)Interact with an item in your inventory by id and action index.
Parameters
itemId- Item id.
action- Action index.
interactSubOp(ItemEx, String, String)static
public static void interactSubOp(ItemEx item, String menu, String action)Interact with an item in your inventory by subOp and action.
Parameters
item- Item.
menu- Menu (Eg. "Rub").
action- Action (Eg. "Grand Exchange").
interactSubOp(String, String, String)static
public static void interactSubOp(String itemName, String menu, String action)Interact with an item in your inventory by name, subOp and action.
Parameters
itemName- ItemName.
menu- Menu (Eg. "Rub").
action- Action (Eg. "Grand Exchange").
interactSubOp(int, String, String)static
public static void interactSubOp(int itemId, String menu, String action)Interact with an item in your inventory by id, subOp and action.
Parameters
itemId- ItemId.
menu- Menu (Eg. "Rub").
action- Action (Eg. "Grand Exchange").
isEmpty()static
public static boolean isEmpty()Whether your inventory is empty.
Returns
true when no slot holds an item.
isFull()static
public static boolean isFull()Whether all 28 slots are used.
Returns
true when no slot is free.
isItemSelected()static
public static boolean isItemSelected()Checks whether an inventory item is currently selected for a use-on action.
Returns
True when a selected widget is an inventory item.
itemAction(int, int, int)static
public static void itemAction(int slot, int id, int action)Interact with an item in your inventory by slot, id and action index.
Parameters
slot- Slot.
id- Id.
action- Action index.
reorder(InventoryProfile)static
public static boolean reorder(InventoryProfile profile)Move one available item towards its saved slot; call again after a game tick.
Parameters
profile- Profile.
search()static
public static InventoryQuery search()Creates an instance of InventoryQuery from the Inventory.
Returns
InventoryQuery.
selectItem(ItemEx)static
public static boolean selectItem(ItemEx item)Select a current inventory item for the player's next use-on click.
Parameters
item- Item.
useOn(ItemEx, ItemEx)static
public static void useOn(ItemEx item, ItemEx target)Use an item on another item in your inventory.
Parameters
item- Item.
target- Target item.
useOn(ItemEx, NpcEx)static
public static void useOn(ItemEx item, NpcEx npc)Use an item on an npc.
Parameters
item- Item.
npc- Npc.
useOn(ItemEx, PlayerEx)static
public static void useOn(ItemEx item, PlayerEx player)Use an item on a player.
Parameters
item- Item.
player- Player.
useOn(ItemEx, TileItemEx)static
public static void useOn(ItemEx item, TileItemEx tileItem)Use an item on a ground item.
Parameters
item- Item.
tileItem- Tile item.
useOn(ItemEx, TileObjectEx)static
public static void useOn(ItemEx item, TileObjectEx tileObject)Use an item on a tile object.
Parameters
item- Item.
tileObject- Tile object.
useOnEquipment(ItemEx, ItemEx)static
public static void useOnEquipment(ItemEx inventoryItem, ItemEx equippedItem)Use an inventory item on an equipped item, preserving each container's widget identity.
Parameters
inventoryItem- Source item in the inventory.
equippedItem- Target item in the worn equipment container.
Also allowed
Every class has these, as in plain Java.
equals, toString