Inventory
com.jsmacrosce.jsmacros.client.api.classes.inventory.Inventory
Wraps a container screen's menu; specialized subclasses represent recognized screen types.
Use instanceof Inventories.Crafting and the other Inventories names to branch on those wrapper types; getType() returns the screen name used for identification.
Slot indices refer to the menu's full slot list. getMap() groups applicable indices by section name; available sections depend on the screen.
js
const inv = Player.openInventory();
// which kind of container is this?
Chat.log(`this is ${inv.getType()}`);
// the named sections, rather than slot numbers that move per screen
Chat.log(`main: ${inv.getSlots("main")}`);
Chat.log(`hotbar: ${inv.getSlots("hotbar")}`);
// count what is in there, without touching any slot
const counts = inv.getItemCount();
for (const id of counts.keySet()) {
Chat.log(`${id} x ${counts.get(id)}`);
}Available in scripts as Inventories.Inventory.
Type Parameters
T: concrete container screen type wrapped by this inventory
Methods
click
Performs a primary-button pickup click on a menu slot.
Parameters:
slot: index in the menu's full slot list
Returns: this inventory for chaining
Performs a pickup click, except button
2 clones the stack.Parameters:
slot: index in the menu's full slot listmouseButton:2to clone; all other values perform a pickup click
Returns: this inventory wrapper
close
close(): void#Requests closure of the player's current container on the client thread and immediately clears this wrapper's screen and menu references.
closeAndDrop
closeAndDrop(): Inventory<T extends AbstractContainerScreen<?>>#Drops the entire carried stack outside the menu, then closes the inventory.
Returns: this wrapper, which now refers to the closed inventory
contains
Parameters:
item: stack to compare against
Returns:
true if any inventory stack equals itemcreate
Wraps the current container screen, or the player's inventory if no container screen is open. The fallback is a synthetic screen wrapper, so getSlotUnderMouse() cannot be used until its screen is current.
Returns: a wrapper for the open container or the player's inventory
Wraps a container screen without falling back to another inventory. Recognized screen types receive specialized wrappers; other container screens receive a base wrapper.
Parameters:
s: the screen to describe
Returns: a handler for the container behind it, or
null if it is not a container screendragClick
dragClick(int[] slots, int mouseButton): Inventory<T extends AbstractContainerScreen<?>>#Distributes the carried stack across the specified menu slots using quick-craft.
Parameters:
slots: the slots to spread across, which do not have to be adjacent or in ordermouseButton:0selects even distribution; any other value selects greedy distribution
Returns: this inventory wrapper
dropSlot
Drops one item from a menu slot.
Parameters:
slot: index in the menu's full slot list
Returns: this inventory wrapper, for chaining
Drops one item or the whole stack from a menu slot.
Parameters:
slot: index in the menu's full slot liststack:trueto drop the whole stack;falseto drop one item
Returns: this inventory wrapper
findFreeHotbarSlot
Returns: the first empty slot in the
hotbar section, or -1 if it has no empty slot.findFreeInventorySlot
Returns: the first empty slot in the
main or hotbar sections, or -1 if neither section has an empty slot.findFreeSlot
findItem
Parameters:
item: stack to compare with each slot
Returns: indices of slots whose stacks equal
itemgetContainerTitle
getCurrentSyncId
Returns: the menu's synchronization ID
getHeld
getHeld(): ItemStackHelper#Returns: the item stack currently carried by the menu
getItemCount
getItems
Returns: non-empty stacks from the menu's full slot list
Parameters:
mapIdentifiers: names of the inventory sections to include; unknown names are ignored
Returns: non-empty stacks from the specified sections
getLocation
getMap
getRawContainer
getRawContainer(): T extends AbstractContainerScreen<?>#Returns the screen wrapped by this inventory, or
null after close(). Unlike the methods around it this one carries no @since: the version it arrived in is not recorded anywhere, so it is left unstated rather than guessed. [citation needed]Returns: the wrapped screen
getSelectedHotbarSlotIndex
Returns: the selected hotbar slot index
getSlot
getSlot(int slot): ItemStackHelper#Parameters:
slot: menu slot index
Returns: the stack in that menu slot
getSlotPos
getSlots
getSlotUnderMouse
Returns: the menu slot index under the mouse, or
-999 if the pointer is outside all slots; throws if this inventory's screen is not opengetTotalSlots
getTotalSlots(): int#Returns: the number of slots in the menu's full slot list
getType
grabAll
grabAll(int slot): Inventory<T extends AbstractContainerScreen<?>>#Picks up the selected slot's stack, then attempts to collect matching items from other menu slots into the carried stack.
Parameters:
slot: slot whose stack to pick up
Returns: this inventory
is
isContainer
Returns:
true for container, dispenser, hopper, or shulker-box screens; false otherwiseopenGui
Opens this inventory's screen on the Minecraft client thread.
quick
quick(int slot): Inventory<T extends AbstractContainerScreen<?>>#Performs a quick-move click on a menu slot (the usual shift-click action).
Parameters:
slot: index in the menu's full slot list
Returns: this inventory wrapper, for chaining
quickAll
Quick-moves items matching the selected slot's stack from its backing container.
Parameters:
slot: menu slot index whose stack and backing container determine the matches
Returns: the total stack count in matching slots considered for quick-move
Quick-moves matching stacks from the selected slot's backing container.
Parameters:
slot: menu slot index whose stack and backing container determine the matchesbutton: mouse button value passed with each quick-move click
Returns: the total stack count in matching slots considered for quick-move
setSelectedHotbarSlotIndex
Sets the selected hotbar slot; indices outside
0–8 are ignored.Parameters:
index: hotbar slot index
split
split(int slot1, int slot2): Inventory<T extends AbstractContainerScreen<?>>#Performs a secondary-button pickup click on
slot1, then a primary-button pickup click on slot2. The slots must be distinct and empty, or this method throws an exception. For quick-craft distribution, use Inventory.dragClick(int[], int).Parameters:
slot1: first empty menu slotslot2: second, distinct empty menu slot
Returns: this inventory wrapper
swapHotbar
Swaps a menu slot with a hotbar slot or the offhand slot.
Parameters:
slot: menu slot to swaphotbarSlot: hotbar index from0to8, or40for offhand
Returns: this inventory