Minecraft:Commands/item: Difference between revisions
More actions
Fix template calls: add MC/ prefix |
Sync: updated from Minecraft |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{for|the {{BE}} equivalent|Commands/replaceitem}} | ||
{{ | {{Exclusive|Java}} | ||
{{Update|/item fill in 26.3}} | |||
{{Infobox command | {{Infobox command | ||
|name=item | |name=item | ||
|oplevel=2 | |oplevel=2 | ||
}} | }} | ||
Manipulate or copy [[Minecraft:item]]s in the inventories of [[Minecraft:block]]s ([[Minecraft:chest]]s, [[Minecraft:furnace]]s, etc.) or entities ( | Manipulate or copy [[Minecraft:item]]s in the [[Minecraft:inventories]] of [[Minecraft:block]]s ([[Minecraft:chest]]s, [[Minecraft:furnace]]s, etc.) or [[Minecraft:entities]] ([[Minecraft:player]]s or [[Minecraft:mob]]s). | ||
== Syntax == | == Syntax == | ||
: <code>'''item modify''' (block <pos>|entity <targets>) <slot> <modifier></code> | : <code>'''item modify''' (block <pos>|entity <targets>) <slot> <modifier></code> | ||
:: Modifies the items in the specified slot with the specified item modifier. | :: Modifies the items in the specified slot with the specified [[Minecraft:item modifier]]. | ||
: <code>'''item replace''' (block <pos>|entity <targets>) <slot> '''with''' <item> [<count>]</code> | : <code>'''item replace''' (block <pos>|entity <targets>) <slot> '''with''' <item> [<count>]</code> | ||
:: Replaces the items in the specified slot with the specified items. | :: Replaces the items in the specified slot with the specified items. | ||
: <code>'''item replace''' (block <pos>|entity <targets>) <slot> '''from''' (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>]</code> | : <code>'''item replace''' (block <pos>|entity <targets>) <slot> '''from''' (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>]</code> | ||
:: Copies the source items to the target slot and optionally modifies it with the <code>modifier</code>. | :: Copies the source items to the target slot and optionally modifies it with the <code>modifier</code>. | ||
: <code>'''item override''' (block <pos>|entity <targets>) <slots> '''with''' <item> [<count>]</code> | |||
: <code>'''item override''' (block <pos>|entity <targets>) <slots> '''from''' (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]</code> | |||
:: Similar to {{cd|'''item replace'''}}, but can fill items across multiple slots. When there are more target slots than source slots, the extra target slots are cleared. See {{slink||Arguments}} and [[Minecraft:Slot]] for more details.{{upcoming|je 26.3}}<code>'''item fill''' (block <pos>|entity <targets>) <slots> '''with''' <item> [<count>]</code> | |||
: <code>'''item fill''' (block <pos>|entity <targets>) <slots> '''from''' (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]</code> | |||
:: Similar to {{cd|'''item override'''}}, but instead of clearing extra target slots, items from the source slots are repeated to fill all target slots.{{upcoming|je 26.3}} | |||
'''Syntax displayed in various ways''' | '''Syntax displayed in various ways''' | ||
| Line 26: | Line 32: | ||
*** <code>... '''with''' <item> [<count>]</code> | *** <code>... '''with''' <item> [<count>]</code> | ||
*** <code>... '''from''' <''SOURCE''> <sourceSlot> [<modifier>]</code> | *** <code>... '''from''' <''SOURCE''> <sourceSlot> [<modifier>]</code> | ||
** <code>... '''override''' <''TARGET''> <slots></code> | |||
** <code>... '''fill''' <''TARGET''> <slots></code> | |||
*** <code>... '''with''' <item> [<count>]</code> | |||
*** <code>... '''from''' <''SOURCE''> <sourceSlots> [<modifier>]</code> | |||
: where substituted arguments are: | : where substituted arguments are: | ||
:: <code><''TARGET''></code> = <code>(block <pos> | :: <code><''TARGET''></code> = <code>(block <pos>|entity <targets>)</code> | ||
:: <code><''SOURCE''></code> = <code>(block <sourcePos> | :: <code><''SOURCE''></code> = <code>(block <sourcePos>|entity <sourceTarget>)</code> | ||
|} | |} | ||
| Line 36: | Line 46: | ||
|- | |- | ||
| | | | ||
: <code>item (modify (block <pos> | : <code>item (modify (block <pos>|entity <targets>) <slot> <modifier>|replace (block <pos>|entity <targets>) <slot> (with <item> [<count>]|from (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>])|(override|fill) (block <pos>|entity <targets>) <slots> (with <item> [<count>]|from (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]))</code> | ||
|} | |} | ||
:{| class="collapsible collapsed collapse-button-none" data-description="maximised_tree" | :{| class="collapsible collapsed collapse-button-none" data-description="maximised_tree" | ||
| Line 51: | Line 61: | ||
: <code>item replace entity <targets> <slot> from block <sourcePos> <sourceSlot> [<modifier>]</code> | : <code>item replace entity <targets> <slot> from block <sourcePos> <sourceSlot> [<modifier>]</code> | ||
: <code>item replace entity <targets> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]</code> | : <code>item replace entity <targets> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]</code> | ||
: <code>item override block <pos> <slot> with <item> [<count>]</code> | |||
: <code>item override block <pos> <slot> from block <sourcePos> <sourceSlots> [<modifier>]</code> | |||
: <code>item override block <pos> <slot> from entity <sourceTarget> <sourceSlots> [<modifier>]</code> | |||
: <code>item override entity <targets> <slot> with <item> [<count>]</code> | |||
: <code>item override entity <targets> <slot> from block <sourcePos> <sourceSlots> [<modifier>]</code> | |||
: <code>item override entity <targets> <slot> from entity <sourceTarget> <sourceSlots> [<modifier>]</code> | |||
: <code>item fill block <pos> <slots> with <item> [<count>]</code> | |||
: <code>item fill block <pos> <slots> from block <sourcePos> <sourceSlots> [<modifier>]</code> | |||
: <code>item fill block <pos> <slots> from entity <sourceTarget> <sourceSlots> [<modifier>]</code> | |||
: <code>item fill entity <targets> <slots> with <item> [<count>]</code> | |||
: <code>item fill entity <targets> <slots> from block <sourcePos> <sourceSlots> [<modifier>]</code> | |||
: <code>item fill entity <targets> <slots> from entity <sourceTarget> <sourceSlots> [<modifier>]</code> | |||
|} | |} | ||
== Arguments == | == Arguments == | ||
{{ | {{argument|pos|block_pos}} | ||
: Specifies the position of the block to be modified. | : Specifies the position of the block to be modified. | ||
: {{ | : {{arg desc|je=block_pos}} | ||
{{ | {{argument|targets|entity}} | ||
: Specifies one or more entities to modify. | : Specifies one or more entities to modify. | ||
: {{ | : {{arg desc|je=entity|amount=multiple|type=entities}} | ||
{{ | {{argument|slot|item_slot}} | ||
: Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified. | : Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified. | ||
: {{ | : {{arg desc|je=item_slot}} | ||
{{ | {{argument|slots|item_slots}} | ||
: | : Similar to {{argument|slot}}, but can contain multiple slots. | ||
: {{ | : {{arg desc|je=item_slots}} | ||
{{ | {{argument|modifier|loot_modifier}} | ||
: Specifies the [[Minecraft:item modifier]] to apply on the chosen item. | |||
: {{Arg desc|je=loot_modifier}} | |||
{{argument|item|item_stack}} | |||
: 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. | ||
: {{ | : {{arg desc|je=item_stack}} | ||
{{ | {{argument|count|integer}} | ||
: 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|je=integer|min=1|max=99}}<!--unparseable if bigger than 99, failed if bigger than the max stack size--> | ||
{{ | {{argument|sourcePos|block_pos}} | ||
: Specifies the position of the block to copy items from. | : Specifies the position of the block to copy items from. | ||
: {{ | : {{arg desc|je=block_pos}} | ||
{{ | {{argument|sourceTarget|entity}} | ||
: Specifies an entity to copy items from. | : Specifies an entity to copy items from. | ||
: {{ | : {{arg desc|je=entity|amount=single|type=entities}}{{Until|je 26.3}} | ||
{{ | {{argument|sourceSlot|item_slot}} | ||
: Specifies the inventory slot to copy the items from. Valid values depend on whether the source is block or an entity. | : Specifies the inventory slot to copy the items from. Valid values depend on whether the source is block or an entity. | ||
: {{ | : {{arg desc|je=item_slot}} | ||
{{argument|sourceSlots|item_slots}} | |||
: Similar to {{argument|sourceSlot}}, but can contain multiple slots. | |||
: {{arg desc|je=item_slots}} | |||
== Result == | == Result == | ||
| Line 114: | Line 144: | ||
== Output == | == Output == | ||
{{ | {{Output table}} | ||
{{ | {{Output table|edition=je|On fail|0|0|0}} | ||
{{Output table|cmd=/item (modify{{!}}replace) block ...|On success|1|1|1}} | {{Output table|cmd=/item (modify{{!}}replace) block ...|On success|1|1|1}} | ||
{{Output table|cmd=/item (modify{{!}}replace) entity ...|On success|1|1|the number of entities whose items are successfully replaced}} | {{Output table|cmd=/item (modify{{!}}replace) entity ...|On success|1|1|the number of entities whose items are successfully replaced}} | ||
{{ | {{Output table}} | ||
== Examples == | == Examples == | ||
| Line 143: | Line 173: | ||
== History == | == History == | ||
{{HistoryTable | {{HistoryTable | ||
|{{ | |{{HistoryLine|java}} | ||
|{{HistoryLine||November 8, 2017|link=https://www.minecraft.net/en-us/article/minecraft-snapshot-17w45a|A command called {{ | |{{HistoryLine||November 8, 2017|link=https://www.minecraft.net/en-us/article/minecraft-snapshot-17w45a|A command called {{cmd|modifyitem|link=none}} was mentioned in snapshot's [[Minecraft:Java Edition 17w45a]] update log at [[Minecraft:minecraft.net]]. At first it was planned to replace {{cmd|enchant}}.}} | ||
|{{HistoryLine||February 9, 2018|link=https://www.minecraft.net/en-us/article/minecraft-snapshot-18w06a|In Java Edition 18w06a's update logs, Dinnerbone states that the team has shelved the {{ | |{{HistoryLine||February 9, 2018|link=https://www.minecraft.net/en-us/article/minecraft-snapshot-18w06a|In [[Minecraft:Java Edition 18w06a]]'s update logs, [[Minecraft:Dinnerbone]] states that the team has shelved the {{cmd|modifyitem|link=none}} idea, but that it may be considered in the future.}} | ||
|{{HistoryLine||1.17|dev=20w46a|Added {{ | |{{HistoryLine||1.17|dev=20w46a|Added {{cmd|item|link=none}}, replacing {{cmd|replaceitem}} and reusing the idea of {{cmd|modifyitem|link=none}} through one of its arguments, <code>modify</code>, which in fact contains a similar functionality to {{cmd|enchant|link=none}}, as they use [[Minecraft:item modifier]]s capable of changing the specified item's enchantments.}} | ||
|{{HistoryLine|||dev=21w19a|Syntax of {{ | |{{HistoryLine|||dev=21w19a|Syntax of {{cmd|item|link=none}} has been changed.}} | ||
|{{HistoryLine||1.19|dev=Pre-release 1|Replacing the off-hand slot using {{ | |{{HistoryLine||1.19|dev=Pre-release 1|Replacing the off-hand slot using {{cmd|item|link=none}} no longer produces a [[Minecraft:vibration]].<ref>{{bug|MC-250022}}</ref>}} | ||
|{{ | |{{HistoryLine||1.20.2|dev=23w31a|Can now replace items in [[Minecraft:jukebox]]es. | ||
|Can now remove items in chiseled bookshelves.}} | |Can now remove items in [[Minecraft:chiseled bookshelves]].}} | ||
|{{HistoryLine|upcoming java}} | |||
|{{HistoryLine||26.3|dev=snapshot1|Now takes a slot source as argument in place of anywhere a slot was previously used.|The entity argument in the {{cd|from entity}} item source can now be a selector targeting multiple entities.|Added new {{cd|fill}} and {{cd|override}} sub-commands, each with syntax identical to {{cmd|item replace}}.}} | |||
}} | }} | ||
== See also == | == See also == | ||
* {{ | * {{cmd|data}} — can also replace items in a container's or mob's inventory, or modify the drop chances of armor and weapons | ||
* {{ | * {{cmd|give}} — give items to players without specifying specific inventory slots or overwriting other items | ||
* {{ | * {{cmd|replaceitem}} — The {{el|be}} equivalent | ||
== Navigation == | == Navigation == | ||
{{ | {{Navbox commands}} | ||
de:Befehl/item | [[Minecraft:de:Befehl/item]] | ||
es:Comandos/item | [[Minecraft:es:Comandos/item]] | ||
ja:コマンド/item | [[Minecraft:fr:Commandes/item]] | ||
pt:Comandos/item | [[Minecraft:ja:コマンド/item]] | ||
ru:Команды консоли/item | [[Minecraft:pt:Comandos/item]] | ||
zh:命令/item | [[Minecraft:ru:Команды консоли/item]] | ||
[[Minecraft:zh:命令/item]] | |||
Latest revision as of 11:04, 26 July 2026
Template:For Template:Exclusive Template:Update Template:Infobox command Manipulate or copy Minecraft:items in the Minecraft:inventories of Minecraft:blocks (Minecraft:chests, Minecraft:furnaces, etc.) or Minecraft:entities (Minecraft:players or Minecraft:mobs).
Syntax
item modify (block <pos>|entity <targets>) <slot> <modifier>- Modifies the items in the specified slot with the specified Minecraft:item modifier.
item replace (block <pos>|entity <targets>) <slot> with <item> [<count>]- Replaces the items in the specified slot with the specified items.
item replace (block <pos>|entity <targets>) <slot> from (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>]- Copies the source items to the target slot and optionally modifies it with the
modifier.
- Copies the source items to the target slot and optionally modifies it with the
item override (block <pos>|entity <targets>) <slots> with <item> [<count>]item override (block <pos>|entity <targets>) <slots> from (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]- Similar to Template:Cd, but can fill items across multiple slots. When there are more target slots than source slots, the extra target slots are cleared. See Template:Slink and Minecraft:Slot for more details.Template:Upcoming
item fill (block <pos>|entity <targets>) <slots> with <item> [<count>]
- Similar to Template:Cd, but can fill items across multiple slots. When there are more target slots than source slots, the extra target slots are cleared. See Template:Slink and Minecraft:Slot for more details.Template:Upcoming
item fill (block <pos>|entity <targets>) <slots> from (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]- Similar to Template:Cd, but instead of clearing extra target slots, items from the source slots are repeated to fill all target slots.Template:Upcoming
Syntax displayed in various ways
Simplified tree: item ...... modify <TARGET> <slot> <modifier>... replace <TARGET> <slot>... with <item> [<count>]... from <SOURCE> <sourceSlot> [<modifier>]
... override <TARGET> <slots>... fill <TARGET> <slots>... with <item> [<count>]... from <SOURCE> <sourceSlots> [<modifier>]
- where substituted arguments are:
<TARGET>=(block <pos>|entity <targets>)<SOURCE>=(block <sourcePos>|entity <sourceTarget>)
Minimised: item (modify (block <pos>|entity <targets>) <slot> <modifier>|replace (block <pos>|entity <targets>) <slot> (with <item> [<count>]|from (block <sourcePos>|entity <sourceTarget>) <sourceSlot> [<modifier>])|(override|fill) (block <pos>|entity <targets>) <slots> (with <item> [<count>]|from (block <sourcePos>|entity <sourceTarget>) <sourceSlots> [<modifier>]))
Maximised: item modify block <pos> <slot> <modifier>item modify entity <targets> <slot> <modifier>item replace block <pos> <slot> with <item> [<count>]item replace block <pos> <slot> from block <sourcePos> <sourceSlot> [<modifier>]item replace block <pos> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]item replace entity <targets> <slot> with <item> [<count>]item replace entity <targets> <slot> from block <sourcePos> <sourceSlot> [<modifier>]item replace entity <targets> <slot> from entity <sourceTarget> <sourceSlot> [<modifier>]item override block <pos> <slot> with <item> [<count>]item override block <pos> <slot> from block <sourcePos> <sourceSlots> [<modifier>]item override block <pos> <slot> from entity <sourceTarget> <sourceSlots> [<modifier>]item override entity <targets> <slot> with <item> [<count>]item override entity <targets> <slot> from block <sourcePos> <sourceSlots> [<modifier>]item override entity <targets> <slot> from entity <sourceTarget> <sourceSlots> [<modifier>]item fill block <pos> <slots> with <item> [<count>]item fill block <pos> <slots> from block <sourcePos> <sourceSlots> [<modifier>]item fill block <pos> <slots> from entity <sourceTarget> <sourceSlots> [<modifier>]item fill entity <targets> <slots> with <item> [<count>]item fill entity <targets> <slots> from block <sourcePos> <sourceSlots> [<modifier>]item fill entity <targets> <slots> from entity <sourceTarget> <sourceSlots> [<modifier>]
Arguments
- Specifies the position of the block to be modified.
- Template:Arg desc
- Specifies one or more entities to modify.
- Template:Arg desc
- Specifies the inventory slot to be modified. Valid values depend on whether a block or an entity is being modified.
- Template:Arg desc
- Similar to Template:Argument, but can contain multiple slots.
- Template:Arg desc
- Specifies the Minecraft:item modifier to apply on the chosen item.
- Template:Arg desc
- Specifies the item to be placed in the block or entity's inventory slot.
- Template:Arg desc
- Specifies the number of items to be placed in the block or entity's inventory slot.
- Template:Arg desc
- Specifies the position of the block to copy items from.
- Template:Arg desc
- Specifies an entity to copy items from.
- Template:Arg descTemplate:Until
- Specifies the inventory slot to copy the items from. Valid values depend on whether the source is block or an entity.
- Template:Arg desc
- Similar to Template:Argument, but can contain multiple slots.
- Template:Arg desc
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 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:
/item replace block ~ ~2 ~ container.26 with minecraft:spruce_sapling 4
- To replace the items in the rightmost hotbar slot of the nearest player with four spruce saplings:
/item replace entity @p hotbar.8 with minecraft:spruce_sapling 4
- To replace the item in the offhand of the selected player with the item in their main hand:
/item replace entity @s weapon.offhand from entity @s weapon.mainhand
- To put a brown Minecraft:banner on a player's head
/item replace entity @s armor.head with minecraft:brown_banner
- To increase the count of the item in your main hand:
/item modify entity @s weapon.mainhand example:increase_count- file in a data pack:
data/example/item_modifier/increase_count.json<syntaxhighlight lang="json">{
"function": "minecraft:set_count", "count": 1, "add": true
}</syntaxhighlight>
- To increase the count of the item in your main hand without external files:
item modify entity @s weapon.mainhand {"function":"minecraft:set_count","count":1,"add":true}
- To put the item in your hand, on your head:
/item replace entity @s armor.head from entity @s weapon.mainhand
History
See also
- Template:Cmd — can also replace items in a container's or mob's inventory, or modify the drop chances of armor and weapons
- Template:Cmd — give items to players without specifying specific inventory slots or overwriting other items
- Template:Cmd — The Template:El equivalent
Minecraft:de:Befehl/item Minecraft:es:Comandos/item Minecraft:fr:Commandes/item Minecraft:ja:コマンド/item Minecraft:pt:Comandos/item Minecraft:ru:Команды консоли/item Minecraft:zh:命令/item