Minecraft:Commands/replaceitem: Difference between revisions
More actions
Fix template calls: add MC/ prefix |
Sync: updated from Minecraft |
||
| Line 1: | Line 1: | ||
{{ | {{For||Item (disambiguation)}} | ||
{{ | {{exclusive|Bedrock|Education}} | ||
{{outdated|edition=java|This command was superseded by the {{ | {{outdated|edition=java|This command was superseded by the {{cmd|item}} command in [[Minecraft:Java Edition 1.17]].}} | ||
{{Infobox command | {{Infobox command | ||
|name=replaceitem | |name=replaceitem | ||
| Line 7: | Line 7: | ||
|cheat=y | |cheat=y | ||
}} | }} | ||
Replaces the [[Minecraft:item]]s in a specified slot of either a [[Minecraft:block|block']]s ([[Minecraft:chest]], [[Minecraft:furnace]]s, etc.) or entity's (players or mobs) [[Minecraft:inventory]], with a specified item. | Replaces the [[Minecraft:item]]s in a specified slot of either a [[Minecraft:block|block']]s ([[Minecraft:chest]], [[Minecraft:furnace]]s, etc.) or [[Minecraft:Entity|entity's]] ([[Minecraft:players]] or [[Minecraft:mobs]]) [[Minecraft:inventory]], with a specified item. | ||
== Syntax == | == Syntax == | ||
| Line 16: | Line 16: | ||
== Arguments == | == Arguments == | ||
{{ | {{argument|be=1|position: x y z|CommandPosition}} | ||
: Specifies the position of the block to be modified. | : Specifies the position of the block to be modified. | ||
: {{ | : {{arg desc|be=CommandPosition}} | ||
{{ | {{argument|be=1|target: target|CommandSelector<Actor>}} | ||
: Specifies one or more entities to modify. | : Specifies one or more entities to modify. | ||
: {{ | : {{arg desc|be=actor}} | ||
{{ | {{argument|be=1|slotType: EntityEquipmentSlot|enum}}, <code>slot.container</code> and {{argument|slotId: int|int}} | ||
: Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified. See [[Minecraft:Slot]] for details. | : Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified. See [[Minecraft:Slot]] for details. Note that you can target a player's [[Minecraft:Ender Chest|ender chest]] by using <code>slot.enderchest</code>. | ||
: <code>slotId: int</code> {{lcfirst:{{ | : <code>slotId: int</code> {{lcfirst:{{arg desc|be=int}}}} And it must be between -2147483648 and 2147483647 (inclusive). | ||
{{ | {{argument|be=1|itemName: Item|enum}} | ||
: Specifies the item to be placed in the block or entity's inventory slot. | : Specifies the item to be placed in the block or entity's inventory slot. | ||
{{ | {{argument|be=1|amount: int|int}} | ||
: Specifies the number of items 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. | ||
: {{ | : {{arg desc|be=int}} And it should be between 1 and 64 (inclusive). | ||
{{ | {{argument|be=1|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 defaults to 0. If not specified, defaults to 0. | : 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 defaults to 0. If not specified, defaults to 0. | ||
: {{ | : {{arg desc|be=int}} It must be between -2147483648 and 2147483647 (inclusive). | ||
{{ | {{argument|be=1|components: json|Json::Value}} | ||
: Specifies the [[Minecraft:item components]]. Like data tags but supports only <code>minecraft:can_place_on</code>, <code>minecraft:can_destroy</code>, <code>minecraft:item_lock</code>, and <code>minecraft:keep_on_death</code> functions (see [[Minecraft:Commands/give#Examples]]) | : Specifies the [[Minecraft:item components]]. Like data tags but supports only <code>minecraft:can_place_on</code>, <code>minecraft:can_destroy</code>, <code>minecraft:item_lock</code>, and <code>minecraft:keep_on_death</code> functions (see [[Minecraft:Commands/give#Examples]]) | ||
: {{ | : {{arg desc|be=Json::Value}} | ||
{{ | {{argument|be=1|oldItemHandling: ReplaceMode|enum}} | ||
: Must be one of: | : Must be one of: | ||
:: <code>destroy</code> - Directly replaces items ignoring the original items in the specified slot. | :: <code>destroy</code> - Directly replaces items ignoring the original items in the specified slot. | ||
| Line 66: | Line 66: | ||
== Output == | == Output == | ||
{{ | {{Output table|onlybe=1}} | ||
{{ | {{Output table|edition=be|On fail|0}} | ||
{{ | {{Output table|cmd=/replaceitem block ...|On success|1}} | ||
{{ | {{Output table|cmd=/replaceitem entity ...|On success|the number of entities whose items are successfully replaced}} | ||
{{ | {{Output table}} | ||
==Examples== | ==Examples== | ||
| Line 77: | Line 77: | ||
* To replace the items in the rightmost hotbar slot of the nearest player with four spruce saplings: | * To replace the items in the rightmost hotbar slot of the nearest player with four spruce saplings: | ||
** <code>replaceitem entity @p slot.hotbar 8 sapling 4 1</code> | ** <code>replaceitem entity @p slot.hotbar 8 sapling 4 1</code> | ||
* To clear the first slot of every player's ender chest: | |||
** <code>replaceitem entity @a slot.enderchest 0 air</code> | |||
== History == | == History == | ||
=== ''Java Edition'' === | === ''Java Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{ | |{{HistoryLine|java}} | ||
|{{HistoryLine||1.8|dev=14w26a|Added {{ | |{{HistoryLine||1.8|dev=14w26a|Added {{cmd|replaceitem|link=none}}.}} | ||
|{{HistoryLine||1.14|dev=18w43a|{{ | |{{HistoryLine||1.14|dev=18w43a|{{cmd|replaceitem|link=none}} can now be used on [[Minecraft:item frame]]s.}} | ||
|{{HistoryLine||1.17|dev=20w46a|Removed {{ | |{{HistoryLine||1.17|dev=20w46a|Removed {{cmd|replaceitem|link=none}}. Replaced with {{cmd|item replace}}.}} | ||
}} | }} | ||
=== ''Bedrock Edition'' === | === ''Bedrock Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{ | |{{HistoryLine|pocket}} | ||
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{ | |{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{cmd|replaceitem|link=none}}.}} | ||
|{{HistoryLine||1.1.0|dev=alpha 1.1.0.0|<code>CanPlaceOn</code> and <code>CanDestroy</code> functions are now supported for {{ | |{{HistoryLine||1.1.0|dev=alpha 1.1.0.0|<code>CanPlaceOn</code> and <code>CanDestroy</code> functions are now supported for {{cmd|replaceitem|link=none}}.}} | ||
|{{ | |{{HistoryLine|bedrock}} | ||
|{{HistoryLine||1.16.0|dev=beta 1.16.0.55| Added new overload for {{ | |{{HistoryLine||1.16.0|dev=beta 1.16.0.55| Added new overload for {{cmd|replaceitem|link=none}} with an option for destroy or keep.}} | ||
}} | }} | ||
== See also == | == See also == | ||
* {{ | * {{cmd|item}} — the {{el|je}} equivalent | ||
* {{ | * {{cmd|give}} — give items to players without specifying specific inventory slots or overwriting other items | ||
* {{ | * {{cmd|setfixedinvslot}} (''outdated'') — can replace a slot of a mob's inventory | ||
== External links == | == External links == | ||
| Line 106: | Line 108: | ||
== Navigation == | == Navigation == | ||
{{ | {{Navbox commands}} | ||
de:Befehl/replaceitem | [[Minecraft:de:Befehl/replaceitem]] | ||
ja:コマンド/replaceitem | [[Minecraft:ja:コマンド/replaceitem]] | ||
pt:Comandos/replaceitem | [[Minecraft:pt:Comandos/replaceitem]] | ||
ru:Команды консоли/replaceitem | [[Minecraft:ru:Команды консоли/replaceitem]] | ||
uk:Команди консолі/replaceitem | [[Minecraft:uk:Команди консолі/replaceitem]] | ||
zh:命令/replaceitem | [[Minecraft:zh:命令/replaceitem]] | ||
Latest revision as of 11:06, 11 May 2026
Template:For Template:Exclusive Template:Outdated Template:Infobox command Replaces the Minecraft:items in a specified slot of either a block's (Minecraft:chest, Minecraft:furnaces, etc.) or entity's (Minecraft:players or Minecraft:mobs) Minecraft: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.
- Template:Arg desc
- Specifies one or more entities to modify.
- Template:Arg desc
Template:Argument, slot.container and Template:Argument
- Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified. See Minecraft:Slot for details. Note that you can target a player's ender chest by using
slot.enderchest. slotId: intTemplate:Arg desc 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.
- Template:Arg desc 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 defaults to 0. If not specified, defaults to 0.
- Template:Arg desc It must be between -2147483648 and 2147483647 (inclusive).
- Specifies the Minecraft:item components. Like data tags but supports only
minecraft:can_place_on,minecraft:can_destroy,minecraft:item_lock, andminecraft:keep_on_deathfunctions (see Minecraft:Commands/give#Examples) - Template:Arg desc
- 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
Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table
Output
Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table
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
- To clear the first slot of every player's ender chest:
replaceitem entity @a slot.enderchest 0 air
History
Java Edition
Bedrock Edition
See also
- Template:Cmd — the Template:El equivalent
- Template:Cmd — give items to players without specifying specific inventory slots or overwriting other items
- Template:Cmd (outdated) — can replace a slot of a mob's inventory
External links
Minecraft:de:Befehl/replaceitem Minecraft:ja:コマンド/replaceitem Minecraft:pt:Comandos/replaceitem Minecraft:ru:Команды консоли/replaceitem Minecraft:uk:Команди консолі/replaceitem Minecraft:zh:命令/replaceitem