Replace Items in Block and Entity Inventories
The /replaceitem command in Minecraft Bedrock Edition lets you place or swap items directly inside block inventories and entity equipment slots. You can choose the exact slot number, item count, data value, and extra JSON components.
Map makers and server operators use this command to equip mobs with gear, restock container blocks at specific coordinates, or lock items into a player's inventory. To run it, you must have cheats enabled and have the Game Directors permission level.
/replaceitem block <position: x y z> slot.container <slotId: int> <itemName: Item> [amount: int] [data: int] [components: json]Replace item
/replaceitem entity <target: target> <slotType: EntityEquipmentSlot> <slotId: int> <itemName: Item> [amount: int] [data: int] [components: json]Replace entity
/replaceitem block <position: x y z> slot.container <slotId: int> <oldItemHandling: ReplaceMode> <itemName: Item> [amount: int] [data: int] [components: json]Replace block, old item handling
/replaceitem entity <target: target> <slotType: EntityEquipmentSlot> <slotId: int> <oldItemHandling: ReplaceMode> <itemName: Item> [amount: int] [data: int] [components: json]Replace entity, old item handling
| Argument | Type | What it means |
|---|---|---|
amount | int | An optional integer that sets how many of the item to place in the slot, defaulting to 1. |
components | json | An optional JSON object that adds rules like minecraft:can_place_on, minecraft:can_destroy, minecraft:item_lock, or minecraft:keep_on_death. |
data | int | An optional integer that sets the item data value, defaulting to 0. |
itemName | Item | The name of the item to put into the block or entity slot. |
oldItemHandling | ReplaceMode | Sets how to handle existing items in the slot: use destroy to overwrite them or keep to leave existing items untouched. |
position: x y z | position | The X, Y, and Z coordinates of the container block you want to modify. |
slotId | int | An integer that sets the exact slot number to modify, with a default value of 0. |
slotType | EntityEquipmentSlot | The equipment or inventory category on the entity that you want to modify. |
target | target | The player name or target selector that chooses which entity or player gets the item. |
/replaceitem block 10 64 10 slot.container 0 applePlaces 1 apple into the first slot (slot 0) of a container block located at coordinates 10, 64, 10.
/replaceitem block ~ ~1 ~ slot.container 5 bread 16Puts a stack of 16 bread into slot 5 of the container block directly above your current position.
/replaceitem block -25 70 140 slot.container 2 keep emerald 32Places 32 emeralds into slot 2 of the container at -25, 70, 140 only if that slot does not already hold an item.
/replaceitem block 0 80 0 slot.container 1 destroy diamond_sword 1 0 {"minecraft:keep_on_death":{}}Overwrites slot 1 of the container at 0, 80, 0 with a diamond sword that stays in a player's inventory if they die.
/replaceitem entity @p slot.hotbar 0 compassPlaces a compass into the first hotbar slot of the nearest player.
/replaceitem entity @a slot.armor.head 0 carved_pumpkin 1 0 {"minecraft:item_lock":{"mode":"lock_in_slot"}}Puts a carved pumpkin onto the head armor slot of all players and locks it so they cannot take it off.
/replaceitem entity @e[type=zombie] slot.weapon.mainhand 0 keep iron_axeGives an iron axe to the main hand of every zombie that is not already holding something.
/replaceitem entity Steve slot.inventory 9 destroy Torch 64 0Replaces whatever is in slot 9 of the player Steve's inventory with 64 torches.
In Minecraft Java Edition, this command has been replaced by the /item command, which uses forms like /item fill block <target> <slots> with <item> [<count>] or copies items directly between blocks and entities using from block and from entity.
Use the syntax form that includes the oldItemHandling argument and set it to keep instead of destroy so existing items are left alone.
Yes, add the components JSON argument at the end of the command and include minecraft:item_lock after specifying the amount and data values.
Your world must have cheats turned on, and you need the Game Directors permission level to execute the command.