/item
< Commands
For the Bedrock Edition equivalent, see Commands/replaceitem.
This feature is exclusive to Java Edition.
/item| Permission level required |
2 |
|---|---|
| Restrictions |
None |
{
"title": "<code>/item</code>",
"rows": [
{
"field": "2",
"label": "(link to Permission level article, displayed as Permission level<br>required)"
},
{
"field": "None",
"label": "(link to Commands#Restrictions article, displayed as Restrictions)"
}
],
"invimages": [],
"images": []
}
Manipulate or copy items in the inventories of blocks (chests, furnaces, etc.) or entities (players or mobs).
Syntax
item modify (block <pos>|entity <targets>) <slot> <modifier>- Modifies the items in the specified slot with the specified item modifier.
item replace (block <pos>|entity <targets>) <slot> with <item> [<count>]- Replaces the items in the specified slot with the specified items.
item replace (block <pos>|entity <targets>) <slot> from (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>]- Copies the source items to the target slot and optionally modifies it with the
modifier.
- Copies the source items to the target slot and optionally modifies it with the
Syntax displayed in various ways
Simplified tree: item ...... modify <TARGET> <slot> <modifier>... replace <TARGET> <slot>... with <item> [<count>]... from <SOURCE> <sourceSlot> [<modifier>]
- where substituted arguments are:
<TARGET>=(block <pos>|entity <targets>)<SOURCE>=(block <sourcePos>|entity <sourceTarget>)
Minimised: item (modify (block <pos>|entity <targets>) <slot> <modifier>|replace (block <pos>|entity <targets>) <slot> (with <item> [<count>]|from (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>]))
Maximised: item modify block <pos> <slot> <modifier>item modify entity <targets> <slot> <modifier>item replace block <pos> <slot> with <item> [<count>]item replace block <pos> <slot> from block <sourcePos> <sourceSlot> [<modifier>]item replace block <pos> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]item replace entity <targets> <slot> with <item> [<count>]item replace entity <targets> <slot> from block <sourcePos> <sourceSlot> [<modifier>]item replace entity <targets> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]
Arguments
<pos>: block_pos
- Specifies the position of the block to be modified.
- Must be a block position composed of
<X>,<Y>and<Z>, each of which must be an integer or a tilde and caret notation.
<targets>: entity
- Specifies one or more entities to modify.
- Must be a player name, a target selector or a UUID.
<slot>: item_slot
- Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified.
- Must be a string notation that refer to a single slot in the inventory, which consists of "slot type" and optional "slot number", in the format of
<slot_type>or<slot_type>.<slot_number>. See Slot for details.
<modifier>: loot_modifier
- Specifies the item modifier to apply on the chosen item.
- Specifies a item modifier with a resource location or in SNBT format. Must be a valid item modifier definition in SNBT format, or a resource location of an existing item modifier (an entry in
minecraft:item_modifierregistry). For NBT tag, if it is a string tag, the tag is also parsed into a resource location and resolved into an existing item modifier; otherwise, the tag is parsed as a new item modifier definition.
<item>: item_stack
- Specifies the item to be placed in the block or entity's inventory slot.
- It must be in the format of
item_id[data_components], in which[data_components]can be omitted when they are not needed. See minecraft:item_stack for details.
<count>: integer
- Specifies the number of items to be placed in the block or entity's inventory slot.
- Must be a [Int]32-bit integer number (from -2147483648 (-231) to 2147483647 (231-1) ). And it must be between 1 and 99 (inclusive).
<sourcePos>: block_pos
- Specifies the position of the block to copy items from.
- Must be a block position composed of
<X>,<Y>and<Z>, each of which must be an integer or a tilde and caret notation.
<sourceTarget>: entity
- Specifies an entity to copy items from.
- Must be a player name, a target selector or a UUID.
<sourceSlot>: item_slot
- Specifies the inventory slot to copy the items from. Valid values depend on whether the source is block or an entity.
- Must be a string notation that refer to a single slot in the inventory, which consists of "slot type" and optional "slot number", in the format of
<slot_type>or<slot_type>.<slot_number>. See Slot for details.
Result
| Command | Trigger | Java Edition |
|---|---|---|
| Any | The command is incomplete, or any argument is not specified correctly. | Unparseable |
/item modify ... | <modifier> doesn't meet any of the following conditions:
| Failed |
/item modify block ... | <pos> is unloaded or out of the world. | |
The block at the <pos> is not a container. | ||
The block at the <pos> does not have the specified slot. | ||
/item modify entity ... | <targets> fails to resolve to one or more entities (named player must be online). | |
All selected entities meet one or more of the following conditions:
horse.armor).armor.chest of a player). | ||
/... with <item> <count> | <count> exceeds the stack limit of the specified item. | |
/... from block ... | <sourcePos> is unloaded or out of the world. | |
The block at <sourcePos> is not a container. | ||
The block at <sourcePos> does not have the specified slot. | ||
/... from entity ... | <sourceTarget> fails to resolve to a single entity (named player must be online). | |
The <sourceTarget> doesn't have the specified slot (for example, zombies have no horse.armor). | ||
| Any | Otherwise | Successful |
Output
| Command | Edition | Situation | Success Count | /execute store success ... | /execute store result ... |
|---|---|---|---|---|---|
| Any | Java Edition | On fail | 0 | 0 | 0 |
/item (modify|replace) block ... | On success | 1 | 1 | 1 | |
/item (modify|replace) entity ... | On success | 1 | 1 | the number of entities whose items are successfully replaced |
Examples
- To replace the items in the bottom-right slot of a single chest two block above with four spruce saplings:
/item replace block ~ ~2 ~ container.26 with minecraft:spruce_sapling 4
- To replace the items in the rightmost hotbar slot of the nearest player with four spruce saplings:
/item replace entity @p hotbar.8 with minecraft:spruce_sapling 4
- To replace the item in the offhand of the selected player with the item in their main hand:
/item replace entity @s weapon.offhand from entity @s weapon.mainhand
- To put a brown banner on a player's head
/item replace entity @s armor.head with minecraft:brown_banner
- To increase the count of the item in your main hand:
/item modify entity @s weapon.mainhand example:increase_count- file in a data pack:
data/example/item_modifier/increase_count.json{ "function": "minecraft:set_count", "count": 1, "add": true }
- To increase the count of the item in your main hand without external files:
item modify entity @s weapon.mainhand {"function":"minecraft:set_count","count":1,"add":true}
- To put the item in your hand, on your head:
/item replace entity @s armor.head from entity @s weapon.mainhand
History
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| November 8, 2017 | A command called /modifyitem was mentioned in snapshot's Java Edition 17w45a update log at minecraft.net. At first it was planned to replace /enchant. | ||||||
| February 9, 2018 | In Java Edition 18w06a's update logs, Dinnerbone states that the team has shelved the /modifyitem idea, but that it may be considered the future. | ||||||
| 1.17 | 20w46a | Added /item, replacing /replaceitem and reusing the idea of /modifyitem through one of its arguments, modify, which in fact contains a similar functionality to /enchant, as they use item modifiers capable of changing the specified item's enchantments. | |||||
| 21w19a | Syntax of /item has been changed. | ||||||
| 1.19 | Pre-release 1 | Replacing the off-hand slot using /item no longer produces a vibration.[1] | |||||
| 1.20.2 | 23w31a | Can now replace items in jukeboxes. | |||||
| Can now remove items in chiseled bookshelves. | |||||||
See also
/data— can also replace items in a container's or mob's inventory, or modify the drop chances of armor and weapons/give— give items to players without specifying specific inventory slots or overwriting other items/replaceitem— The Bedrock Edition equivalent