Commands/replaceitem

From Minecraft Wiki
Jump to: navigation, search
replaceitem
Restrictions

Operator

First introduced

1.8 (14w26a)
PE 1.0.5 (PE 1.0.5 build 1)

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

Syntax
  • Java Edition
replaceitem block <x> <y> <z> <slot> <item> [amount] [data] [dataTag]
replaceitem entity <selector> <slot> <item> [amount] [data] [dataTag]
  • Pocket Edition
replaceitem block <position: x y z> <slotType: string> <slotId: int> <itemName: string> [amount: int] [data: int]
replaceitem entity <target: target> <slotType: string> <slotId: int> <itemName: string> [amount: int] [data: int]
Arguments
x y z (PE: position: x y z) (block 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.
selector (PE: target: target) (entity mode only)
Specifies one or more entities to modify. Must be a player name or target selector.
slot (PE: slotType and slotId)
Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified.
For blocks, must be slot.container.slot_number where slot_number 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 /blockdata.
For entities, must be one of the following, where slot_number is replaced with a number specifying the slot:
Slot Slot Numbers Restrictions
slot.armor.chest armor stands, mobs, and players only (though not all mobs will show or make use of the items)
slot.armor.feet
slot.armor.head
slot.armor.legs
slot.weapon.mainhand
slot.weapon.offhand
slot.enderchest.slot_number 0 to 26 players only
slot.hotbar.slot_number 0 to 8
slot.inventory.slot_number 0 to 26
slot.horse.saddle horses, donkeys, and mules only; item must be a saddle
slot.horse.chest donkeys, and mules only; item must be a chest
slot.horse.armor horses and llamas only; item must be a type of horse armor (if a horse) or a carpet (if a llama)
slot.horse.slot_number 0 to 14 donkeys and mules with chests only
slot.villager.slot_number 0 to 7 villagers only
The inventory of an item frame can only be changed with /entitydata.
item (PE: itemName: string)
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 (for example, minecraft:golden_sword).
amount (PE: amount: int) (optional)
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.
data (PE: data: int) optional)
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.
dataTag (optional)[Java Edition only]
Specifies the data tag for the item(s) to be placed in the block or entity's inventory slot. Must be a compound NBT tag (for example, {display:{Name:Fred}}).
Result
Fails if the arguments are not specified correctly, if the specified block is not a container, if selector fails to resolve to one or more entities (named players must be online), or if none of the targeted entities have the specified slot (for example, zombies don't have slot.horse.armor).
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 one block above with four spruce saplings:
replaceitem block ~ ~1 ~ slot.container.26 minecraft: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 minecraft:sapling 4 1
See also
/blockdata — can also replace items in a container
/entitydata — can also replace items in a mob's inventory, or modify the drop chances of armor and weapons
/give — give items to players without specifying specific inventory slots or overwriting other items