/item replace entity @s weapon.mainhand with minecraft:diamond_sword
The /item command directly manipulates inventory slots on entities and block containers. Place a diamond sword in a zombie's main hand, fill a chest with specific items, or apply item modifiers to gear that is already equipped, all through precise slot targeting.
The /item command replaced the older /replaceitem in Java Edition 1.17. It has two forms: /item replace overwrites a slot with a new item, and /item modify applies an item modifier function to whatever is already in the slot.
Unlike /give, which adds items to the first available slot and only targets players, /item works on any entity with an inventory and any block container in the world. You can equip armor stands, fill barrels, load furnaces, and stock villager trading inventories.
| Command | Effect |
|---|---|
| /item replace entity @s weapon.mainhand with diamond_sword | Puts a diamond sword in your main hand |
| /item replace entity @s armor.head with diamond_helmet | Equips a diamond helmet on your head |
| /item replace block ~ ~ ~ container.0 with diamond 3 | Places 3 diamonds in the first slot of a container |
| /item modify entity @s weapon.mainhand my_modifier | Applies an item modifier to your held item |
| /item replace entity @s weapon.mainhand from entity @s weapon.offhand | Copies your offhand item into your main hand |
Source options: /item replace can pull from a literal item (with), another slot (from entity or from block), or a loot table. /item modify only changes the item already in the target slot.
| Slot Type | Slot Names | Target |
|---|---|---|
| Weapons | weapon.mainhand, weapon.offhand | Entity |
| Armor | armor.head, armor.chest, armor.legs, armor.feet | Entity |
| Hotbar | hotbar.0 through hotbar.8 | Player |
| Inventory | inventory.0 through inventory.26 | Player |
| Ender Chest | enderchest.0 through enderchest.26 | Player |
| Horse | horse.saddle, horse.armor, horse.0-14 | Horse or Donkey |
| Villager | villager.0 through villager.7 | Villager |
| Container | container.0 through container.53 | Block |
Block coordinates accept absolute numbers, tilde for relative offsets, and caret for local directions. Point them at a real container or the command silently does nothing.
The /item command replaces or modifies items in specific inventory slots of entities or blocks. It has two forms: /item replace sets a slot to a specific item, and /item modify applies an item modifier to whatever is already in the slot. It replaced the older /replaceitem command in Java Edition 1.17.
For entities: weapon.mainhand, weapon.offhand, armor.head, armor.chest, armor.legs, armor.feet, hotbar.0-8, inventory.0-26, enderchest.0-26, and horse and villager slots. For blocks: container.0-53 for chests, furnaces, and other containers.
The /give command adds an item to a player's first available inventory slot and only works on players. The /item command places an item into a specific slot, overwriting what was there, and works on any entity or block container like chests and furnaces.
Check that you are on Java Edition 1.17 or later, since /item replaced /replaceitem. Confirm the slot name matches the target type: entity slots like weapon.mainhand for mobs, container.0-53 for blocks. Block coordinates must point at an actual container.
Browse more Minecraft tools: