Commands/replaceitem

Replaces items in the inventories of blocks (chest, furnaces, etc.) or entities (players or mobs) with the given item(s).

Syntax

 * Java Edition


 * Bedrock Edition

Arguments
(BE: ) (  mode only)
 * Specifies the position of the block to be modified. May use tilde notation to specify a position relative to the command's execution.

(BE: ) (  mode only)
 * Specifies one or more entities to modify. Must be a player name, target selector, or a UUID.
 * Permits entities other than players.

(BE:  and  )
 * Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified.


 * For blocks, must be  (BE:  ) where slot_number or slotId: int is replaced with a number specifying the slot.
 * Chests, dispensers, droppers, hoppers, and trapped chests are numbered 0 for the top-left slot and then increase first horizontally, then vertically (so, for example, a chest's top row slots are numbered 0 to 8 from left to right). Double chests and double trapped chests are treated as two single container blocks.
 * A brewing stand's bottom slots are numbered 0 to 2 from left to right, its top slot is 3 and the fuel slot is 4.
 * A furnace's slots are numbered 0 for the input slot, 1 for the fuel slot, and 2 for the output slot.
 * Other blocks which hold items but don't have inventory GUIs (flower pots and jukeboxes) can only be changed with.


 * For entities, must be one of the following, where slot_number is replaced with a number specifying the slot:


 * {| class="wikitable" data-description="Slot information"

!Slot !Slot Numbers !Restrictions
 * rowspan=6|armor stands, mobs, and players only (though not all mobs will show or make use of the items)
 * align="center"|0–53
 * players and minecarts only
 * (BE: )
 * align="center"|0–26
 * rowspan=2|players only
 * (BE: )
 * align="center"|0–8
 * (BE: )
 * align="center"|0–26
 * item frames (slot 0) and players only
 * (BE: )
 * horses, donkeys, and mules only; item must be a saddle
 * donkeys, and mules only; item must be a chest
 * (BE: )
 * horses and llamas only; item must be a type of horse armor (if a horse) or a carpet (if a llama)
 * (BE: )
 * align="center"|0–14
 * donkeys and mules with chests only
 * align="center"|0–7
 * villagers only
 * }
 * players and minecarts only
 * (BE: )
 * align="center"|0–26
 * rowspan=2|players only
 * (BE: )
 * align="center"|0–8
 * (BE: )
 * align="center"|0–26
 * item frames (slot 0) and players only
 * (BE: )
 * horses, donkeys, and mules only; item must be a saddle
 * donkeys, and mules only; item must be a chest
 * (BE: )
 * horses and llamas only; item must be a type of horse armor (if a horse) or a carpet (if a llama)
 * (BE: )
 * align="center"|0–14
 * donkeys and mules with chests only
 * align="center"|0–7
 * villagers only
 * }
 * (BE: )
 * horses and llamas only; item must be a type of horse armor (if a horse) or a carpet (if a llama)
 * (BE: )
 * align="center"|0–14
 * donkeys and mules with chests only
 * align="center"|0–7
 * villagers only
 * }
 * align="center"|0–7
 * villagers only
 * }
 * villagers only
 * }

(BE: )
 * Specifies the item to be placed in the block or entity's inventory slot. Must be an item id, or a block id for which an item exists.

(BE: amount: int )
 * Specifies the number of items to be placed in the block or entity's inventory slot. Must be between 1 and 64 (inclusive), even for items with a smaller stack size.


 * Specifies the item data for the item(s) to be placed in the block or entity's inventory slot. Must be an integer between -2,147,483,648 and 2,147,483,647 (inclusive, without the commas), but values which are invalid for the specified item id will default to 0. If not specified, defaults to 0.


 * Specifies the item components. Like data tags but only supports   and   functions (for example,  )


 * Must be one of:
 * - Directly replaces items ignoring the original items in the specified slot.
 * - Does not replace items if an item occupies that slot.

Result
Fails if the arguments are not specified correctly, if the specified block is not a container, if  fails to resolve to one or more entities (named players must be online), if none of the targeted entities have the specified slot (for example, zombies don't have  ), or if an item occupies the specified slot in   mode $$.

On success, replaces the items in the specified slot with the specified items (previous items in that slot are lost) wherever possible.

Examples

 * To replace the items in the bottom-right slot of a single chest two block above with four spruce saplings:


 * To replace the items in the rightmost hotbar slot of the nearest player with four spruce saplings: