Minecraft Wiki
Advertisement
Minecraft Wiki
Information icon.svg
This feature is exclusive to Bedrock Edition and Education Edition. 
Rose (texture) JE1.png
This page describes content that exists only in outdated versions of Java Edition. 
This command was superseded by the /item command in Java Edition 1.17.
replaceitem
Permission level
required

1

Restrictions

Cheat only

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

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[]

<position: x y z>: CommandPosition

Specifies the position of the block to be modified.
It must be a three-dimensional coordinates composed of <x>, <y> and <z>, each of which must be a floating-point number or tilde and caret notation.

<target: target>: CommandSelector<Actor>

Specifies one or more entities to modify.
Must be a player name or a target selector.

slotType: EntityEquipmentSlot, slot.container and <slotId: int>: int

Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified.
slotId: int must be a 32-bit integer number. And it must be between -2147483648 and 2147483647 (inclusive).
For blocks, must be slot.container <slotId: int> 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.
For entities, must be one of the following, where slot number or slot id is replaced with a number specifying the slot:
Slot Slot Numbers Restrictions
slot.armor.chest <slotId: int> any number armor stands, mobs, and players only (though not all mobs will show or make use of the items)
slot.armor.feet <slotId: int> any number
slot.armor.head <slotId: int> any number
slot.armor.legs <slotId: int> any number
slot.weapon.mainhand <slotId: int> any number
slot.weapon.offhand <slotId: int> any number
slot.container <slotId: int> 0–53 players and minecarts only
slot.enderchest <slotId: int> 0–26 players only
slot.hotbar <slotId: int> 0–8
slot.inventory <slotId: int> 0–26
slot.saddle <slotId: int> any number horses, donkeys, and mules only; <item> or itemName: Item must be a saddle
slot.armor <slotId: int> any number‌[Bedrock Edition only] horses and llamas only; <item> or itemName: Item must be a type of horse armor (if a horse) or a carpet (if a llama)
slot.chest <slotId: int> 0–14 donkeys and mules with chests only
slot.inventory <slotId: int> 0–7 villagers only

<itemName: Item>: CommandItem

Specifies the item to be placed in the block or entity's inventory slot.

<amount: int>: int

Specifies the number of items to be placed in the block or entity's inventory slot.
Must be a 32-bit integer number. And it must be between 1 and 64 (inclusive).

data: int: int

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.
Must be a 32-bit integer number. It must be between -2147483648 and 2147483647 (inclusive).

components: json: Json::Value

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 a JSON Object.

oldItemHandling: ReplaceMode

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[]

CommandTriggerBedrock Edition
anythe arguments are not specified correctly Failed
/replaceitem block ...the specified block is not a container Failed
the specified block does not have the specified slot
/replaceitem entity ...<targets> or target: target fails to resolve to one or more entities (named players must be online)
All selected entities meets one or more of the following conditions:
  • It doesn't have the specified slot (for example, zombies don't have horse.armor)
  • Specified item cannot be place into the specified slot of its(for example, place a stone into armor.chest of a player)
/replaceitem ... keepan item occupies the specified slot in keep mode
anyOn successReplaces the items in the specified slot with the specified items (previous items in that slot are lost).

Output[]

CommandEditionSituationSuccess Count/execute store success .../execute store result ...
anyBedrock EditionOn fail0N/AN/A
/replaceitem block ...On success1N/AN/A
/replaceitem entity ...On successthe number of entities whose items are successfully replacedN/AN/A

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[]

Java Edition
1.814w26aAdded /replaceitem.
1.1418w43a/replaceitem can now be used on item frames.
1.1720w46aRemoved /replaceitem. Replaced with /item replace.
Pocket Edition
1.0.5alpha 1.0.5.0Added /replaceitem.
1.1.0alpha 1.1.0.0CanPlaceOn and CanDestroy functions are now supported for /replaceitem.
Bedrock Edition
1.16.0beta 1.16.0.55 Added new overload for /replaceitem with an option for destroy or keep.

See also[]

  • /item — the Java Edition equivalent
  • /give — give items to players without specifying specific inventory slots or overwriting other items
  • /setfixedinvslot (outdated) — can replace a slot of a mob's inventory
  • /setfixedinvslot (outdated) — can replace items of a mob's inventory
Advertisement