Items and Inventories
An inventory can be a player or entity handle, a positioned container block, [x, y, z], or a screen handle. An online player name can also identify a player inventory. To access equipment or an ender chest, use "equipment", entity or "enderchest", player in place of the inventory argument.
A stack is returned as [itemId, count, nbt]. An empty slot is null. Built-in IDs may be returned without minecraft:.
Inventory slots
Call under mc.inventory | Result |
|---|---|
inventory_size(inventory) | Slot count, or null if there is no inventory. |
inventory_has_items(inventory) | Whether the inventory contains any stack, or null if unavailable. |
inventory_get(inventory[, slot]) | The entire array of slots or one stack by zero-based slot index. |
inventory_find(inventory[, item][, startSlot]) | First matching index, or null. Use null for the item to find the first empty slot. |
inventory_set(inventory, slot, count[, item][, nbt]) | Writes a slot and returns the previous stack. Use a count of 0 to clear it. |
inventory_remove(inventory, item[, amount]) | Tries to remove the requested amount by item type. The default amount is 1. Returns false if there are too few. |
drop_item(inventory, slot[, amount]) | Drops items from the slot into the world and returns the number dropped. Omit the amount or use 0 to drop the whole stack. |
function countStone() {
const player = mc.entities.player();
if (player === null) return 0;
return mc.inventory.inventory_get(player).reduce((total, item) => {
return total + (item !== null && item[0] === "stone" ? item[1] : 0);
}, 0);
}
Items, recipes, and screens
Call under mc.inventory | Use |
|---|---|
stack_limit(item) | Maximum stack size for the item. |
item_list([tag]), item_tags([item][, tag]) | Lists registered items, lists tag members, inspects an item's tags, or checks membership. Pass tag IDs without #. |
recipe_data(item[, recipeType]) | Finds recipes by output item. Defaults to the crafting recipe type. |
crafting_remaining_item(item) | The stack left behind when used in crafting, if any. |
create_screen(player, type, title[, callback]) | Opens a screen for an online player and returns a handle. |
close_screen(screen) | Closes an open screen. |
screen_property(screen, name, ...args) | Reads a screen property or sets it when values follow the name. |