Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/replaceitem: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Remove broken links to missing pages
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
 
Line 1: Line 1:
{{For||Item (disambiguation)}}
{{MC/For||Item (disambiguation)}}
{{exclusive|Bedrock|Education}}
{{MC/Exclusive|Bedrock|Education}}
{{outdated|edition=java|This command was superseded by the {{cmd|item}} command in Java Edition 1.17.}}
{{outdated|edition=java|This command was superseded by the {{MC/Cmd|item}} command in Java Edition 1.17.}}
{{Infobox command
{{Infobox command
|name=replaceitem
|name=replaceitem
Line 16: Line 16:


== Arguments ==
== Arguments ==
{{argument|be=1|position: x y z|CommandPosition}}
{{MC/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}}
: {{MC/Arg desc|be=CommandPosition}}


{{argument|be=1|target: target|CommandSelector<Actor>}}
{{MC/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}}
: {{MC/Arg desc|be=actor}}


{{argument|be=1|slotType: EntityEquipmentSlot|enum}}, <code>slot.container</code> and {{argument|slotId: int|int}}
{{MC/Argument|be=1|slotType: EntityEquipmentSlot|enum}}, <code>slot.container</code> and {{MC/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.
:  <code>slotId: int</code> {{lcfirst:{{arg desc|be=int}}}} And it must be between -2147483648 and 2147483647 (inclusive).
:  <code>slotId: int</code> {{lcfirst:{{MC/Arg desc|be=int}}}} And it must be between -2147483648 and 2147483647 (inclusive).


{{argument|be=1|itemName: Item|enum}}
{{MC/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}}
{{MC/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).
: {{MC/Arg desc|be=int}} And it should be between 1 and 64 (inclusive).


{{argument|be=1|data: int|int}}
{{MC/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).
: {{MC/Arg desc|be=int}} It must be between -2147483648 and 2147483647 (inclusive).


{{argument|be=1|components: json|Json::Value}}
{{MC/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}}
: {{MC/Arg desc|be=Json::Value}}


{{argument|be=1|oldItemHandling: ReplaceMode|enum}}
{{MC/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}}
{{MC/Output table|onlybe=1}}
{{Output table|edition=be|On fail|0}}
{{MC/Output table|edition=be|On fail|0}}
{{Output table|cmd=/replaceitem block ...|On success|1}}
{{MC/Output table|cmd=/replaceitem block ...|On success|1}}
{{Output table|cmd=/replaceitem entity ...|On success|the number of entities whose items are successfully replaced}}
{{MC/Output table|cmd=/replaceitem entity ...|On success|the number of entities whose items are successfully replaced}}
{{Output table}}
{{MC/Output table}}


==Examples==
==Examples==
Line 81: Line 81:
=== ''Java Edition'' ===
=== ''Java Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|java}}
|{{MC/HistoryLine|java}}
|{{HistoryLine||1.8|dev=14w26a|Added {{cmd|replaceitem|link=none}}.}}
|{{HistoryLine||1.8|dev=14w26a|Added {{MC/Cmd|replaceitem|link=none}}.}}
|{{HistoryLine||1.14|dev=18w43a|{{cmd|replaceitem|link=none}} can now be used on item frames.}}
|{{HistoryLine||1.14|dev=18w43a|{{MC/Cmd|replaceitem|link=none}} can now be used on item frames.}}
|{{HistoryLine||1.17|dev=20w46a|Removed {{cmd|replaceitem|link=none}}. Replaced with {{cmd|item replace}}.}}
|{{HistoryLine||1.17|dev=20w46a|Removed {{MC/Cmd|replaceitem|link=none}}. Replaced with {{MC/Cmd|item replace}}.}}
}}
}}


=== ''Bedrock Edition'' ===
=== ''Bedrock Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|pocket}}
|{{MC/HistoryLine|pocket}}
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{cmd|replaceitem|link=none}}.}}
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{MC/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 {{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 {{MC/Cmd|replaceitem|link=none}}.}}
|{{HistoryLine|bedrock}}
|{{MC/HistoryLine|bedrock}}
|{{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.}}
|{{HistoryLine||1.16.0|dev=beta 1.16.0.55| Added new overload for {{MC/Cmd|replaceitem|link=none}} with an option for destroy or keep.}}
}}
}}


== See also ==
== See also ==
* {{cmd|item}} — the {{el|je}} equivalent
* {{MC/Cmd|item}} — the {{MC/El|je}} equivalent
* {{cmd|give}} — give items to players without specifying specific inventory slots or overwriting other items
* {{MC/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  
* {{MC/Cmd|setfixedinvslot}} (''outdated'') — can replace a slot of a mob's inventory  


== External links ==
== External links ==
Line 106: Line 106:


== Navigation ==
== Navigation ==
{{Navbox commands}}
{{MC/Navbox commands}}


de:Befehl/replaceitem
de:Befehl/replaceitem

Latest revision as of 20:13, 9 April 2026

Template:Hatnote Script error: No such module "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 (players or 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

position: x y z: CommandPosition

Specifies the position of the block to be modified.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|block_pos}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}

target: target: CommandSelector<Actor>

Specifies one or more entities to modify.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|inapplicability}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}

slotType: EntityEquipmentSlot: enum, 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. See Minecraft:Slot for details.
slotId: int {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|integer}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} And it must be between -2147483648 and 2147483647 (inclusive).

itemName: Item: enum

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.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|integer}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} And it should 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 defaults to 0. If not specified, defaults to 0.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|integer}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} It must be between -2147483648 and 2147483647 (inclusive).

components: json: Json::Value

Specifies the Minecraft: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 Minecraft:Commands/give#Examples)
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|component}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}

oldItemHandling: ReplaceMode: enum

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

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|be}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/replaceitem block ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|the number of entities whose items are successfully replaced}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/replaceitem entity ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

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

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

See also

  1. REDIRECT Template:Command

Template:Redr — the

  1. REDIRECT Template:Edition

Template:Rcat equivalent

  1. REDIRECT Template:Command

Template:Redr — give items to players without specifying specific inventory slots or overwriting other items

  1. REDIRECT Template:Command

Template:Redr (outdated) — can replace a slot of a mob's inventory

External links

Navigation

All editions
Removed
Template:El only
Debug
Removed
Template:Els only
Template:El only
Removed
Template:El only
Removed
Template:Els only
Removed
Joke
Related

de:Befehl/replaceitem ja:コマンド/replaceitem pt:Comandos/replaceitem ru:Команды консоли/replaceitem uk:Команди консолі/replaceitem zh:命令/replaceitem