Commands/replaceitem

Replaces the items in a specified slot of either a block's (chest, furnaces, etc.) or entity's (players or mobs) inventory, with a specified item.
== Syntax ==
: replaceitem block <position: x y z> slot.container <slotId: int> <itemName: Item> [amount: int] [data: int] [components: json]
:
: replaceitem entity <target: target> <slotType: EntityEquipmentSlot> <slotId: int> <itemName: Item> [amount: int] [data: int] [components: json]
:
: replaceitem block <position: x y z> slot.container <slotId: int> <oldItemHandling: ReplaceMode> <itemName: Item> [amount: int] [data: int] [components: json]
:
: replaceitem entity <target: target> <slotType: EntityEquipmentSlot> <slotId: int> <oldItemHandling: ReplaceMode> <itemName: Item> [amount: int] [data: int] [components: json]
== Arguments ==
: Specifies the position of the block to be modified.
: 
: Specifies one or more entities to modify.
: 
, slot.container and 
: Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified. See Slot for details.
: slotId: int And it must be between -2147483648 and 2147483647 (inclusive).
: Specifies the item to be placed in the block or entity's inventory slot.
: Specifies the number of items to be placed in the block or entity's inventory slot.
: And it should be between 1 and 64 (inclusive).
:: Specifies the item data for the item(s) to be placed in the block or entity's inventory slot. Values which are invalid for the specified item id will default to 0. If not specified, defaults to 0.
: It must be between -2147483648 and 2147483647 (inclusive).
: Specifies the item components. Like data tags but supports only minecraft:can_place_on, minecraft:can_destroy, minecraft:item_lock, and minecraft:keep_on_death functions (see Commands/give#Examples)
: 
: Must be one of: 
:: destroy - Directly replaces items ignoring the original items in the specified slot.
:: keep - Does not replace items if an item occupies that slot.
== Result ==
== Output ==
==Examples==
* To replace the items in the bottom-right slot of a single chest two block above with four spruce saplings:
** replaceitem block ~ ~2 ~ slot.container 26 sapling 4 1
* To replace the items in the rightmost hotbar slot of the nearest player with four spruce saplings:
** replaceitem entity @p slot.hotbar 8 sapling 4 1
== History ==
== See also ==
* — the equivalent
* — give items to players without specifying specific inventory slots or overwriting other items
* (outdated) — can replace a slot of a mob's inventory 
* (outdated) — can replace items of a mob's inventory
Category:Removed Java Features
de:Befehl/replaceitem
es:Comandos/replaceitem
ja:コマンド/replaceitem
ru:Команды консоли/replaceitem
pt:Comandos/replaceitem
uk:Команди консолі/replaceitem
zh:命令/replaceitem