Minecraft:Commands/data: Difference between revisions
More actions
imported>LauraFii m Revert edits by ~2026-DiamondGolemMeadow5739 (talk) |
Fix template calls: add MC/ prefix |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{MC/Distinguish|Commands/datapack}} | ||
{{ | {{MC/Exclusive|java}} | ||
{{Infobox command | {{Infobox command | ||
|name=data | |name=data | ||
| Line 6: | Line 6: | ||
}} | }} | ||
Allows the user to get, merge, modify, and remove | Allows the user to get, merge, modify, and remove NBT data of a [[Minecraft:block entity]], entity, or Command NBT storage. | ||
== Syntax == | == Syntax == | ||
[[File:Data graph.svg|thumb|A graph that describes the syntax of this command.]] | [[File:Data graph.svg|thumb|A graph that describes the syntax of this command.]] | ||
There are four instructions for {{ | There are four instructions for {{MC/Code|/data}} ({{MC/Code|[[#get|get]]}}, {{MC/Code|[[#merge|merge]]}}, {{MC/Code|[[#modify|modify]]}}, {{MC/Code|[[#remove|remove]]}}), and the targets/sources referenced by each instruction command may be either {{MC/Code|block <targetPos>}}, {{MC/Code|entity <target>}}, or {{MC/Cd|storage <target>}}. | ||
; {{ | ; {{MC/Code|/'''data''' ...}} | ||
: <code>... '''{{Text anchor|get}}'''</code> | : <code>... '''{{MC/Text anchor|get}}'''</code> | ||
:: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) [<path>] [<scale>]}} | :: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) [<path>] [<scale>]}} | ||
::: Read off the entire NBT data or the subsection of the NBT data from the targeted block position or entity to the executor with syntax highlighting, scaled by {{ | ::: Read off the entire NBT data or the subsection of the NBT data from the targeted block position or entity to the executor with syntax highlighting, scaled by {{MC/Code|<scale>}} if specified. | ||
: <code>... '''{{Text anchor|merge}}'''</code> | : <code>... '''{{MC/Text anchor|merge}}'''</code> | ||
:: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <nbt>}} | :: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <nbt>}} | ||
::: Merge the NBT data from the target block position or entity with the specified {{ | ::: Merge the NBT data from the target block position or entity with the specified {{MC/Code|<nbt>}} data. | ||
: <code>... '''{{Text anchor|modify}}''' (block <targetPos>|entity <target>|storage <target>) <targetPath> ...</code> | : <code>... '''{{MC/Text anchor|modify}}''' (block <targetPos>|entity <target>|storage <target>) <targetPath> ...</code> | ||
:: {{code|... '''append''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | :: {{code|... '''append''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | ||
:: {{code|... '''append''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | :: {{code|... '''append''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | ||
:: {{ | :: {{MC/Code|... '''append''' value <value>}} | ||
::: Append the source data or direct value data onto the ''end'' of the pointed-to list or array. | ::: Append the source data or direct value data onto the ''end'' of the pointed-to list or array. | ||
:: {{code|... '''insert <index>''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | :: {{code|... '''insert <index>''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | ||
:: {{code|... '''insert <index>''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | :: {{code|... '''insert <index>''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | ||
:: {{ | :: {{MC/Code|... '''insert <index>''' value <value>}} | ||
::: Insert the source data or direct value data into the pointed-to list or array as element {{ | ::: Insert the source data or direct value data into the pointed-to list or array as element {{MC/Code|<index>}}, then shift higher elements one position upward. | ||
:: {{code|... '''merge''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | :: {{code|... '''merge''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | ||
:: {{code|... '''merge''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | :: {{code|... '''merge''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | ||
:: {{ | :: {{MC/Code|... '''merge''' value <value>}} | ||
::: Merge the source data or direct value data into the pointed-to object. | ::: Merge the source data or direct value data into the pointed-to object. | ||
:: {{code|... '''prepend''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | :: {{code|... '''prepend''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | ||
:: {{code|... '''prepend''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | :: {{code|... '''prepend''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | ||
:: {{ | :: {{MC/Code|... '''prepend''' value <value>}} | ||
::: Prepend the source data or direct value data onto the ''beginning'' of the pointed-to list or array. | ::: Prepend the source data or direct value data onto the ''beginning'' of the pointed-to list or array. | ||
:: {{code|... '''set''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | :: {{code|... '''set''' from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | ||
:: {{code|... '''set''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | :: {{code|... '''set''' string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | ||
:: {{ | :: {{MC/Code|... '''set''' value <value>}} | ||
::: Set the tag specified by {{ | ::: Set the tag specified by {{MC/Code|<targetPath>}} to the source data or direct value data. | ||
: <code>... '''{{Text anchor|remove}}'''</code> | : <code>... '''{{MC/Text anchor|remove}}'''</code> | ||
:: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <path>}} | :: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <path>}} | ||
::: Removes NBT data at {{ | ::: Removes NBT data at {{MC/Code|<path>}} from the targeted block position or entity. Player NBT data cannot be removed. | ||
| Line 54: | Line 54: | ||
|- | |- | ||
| | | | ||
: {{ | : {{MC/Code|'''/data'''}} | ||
:* {{ | :* {{MC/Code|… '''[[#get|get]]''' <''TARGET''> [<path>] [<scale>]}} | ||
:* {{ | :* {{MC/Code|… '''[[#merge|merge]]''' <''TARGET''> <nbt>}} | ||
:* {{ | :* {{MC/Code|… '''[[#modify|modify]]''' <''TARGET''> <targetPath> <''MODIFICATION''>}} | ||
:** {{ | :** {{MC/Code|… from <''SOURCE''> [<sourcePath>]}} | ||
:** {{ | :** {{MC/Code|… string <''SOURCE''> [<sourcePath>] [<start>] [<end>]}} | ||
:** {{ | :** {{MC/Code|… value <value>}} | ||
:* {{ | :* {{MC/Code|… '''[[#remove|remove]]''' <TARGET> <path>}} | ||
: where substituted arguments are: | : where substituted arguments are: | ||
:: {{ | :: {{MC/Code|<''TARGET''>}} = {{code|(block <targetPos> {{!}} entity <target> {{!}} storage <target>)}} | ||
:: {{ | :: {{MC/Code|<''MODIFICATION''>}} = {{code|('''[[#modify|append]]'''{{!}}'''[[#modify|insert <index>]]'''{{!}}'''[[#modify|merge]]'''{{!}}'''[[#modify|prepend]]'''{{!}}'''[[#modify|set]]''')}} | ||
:: {{ | :: {{MC/Code|<''SOURCE''>}} = {{code|(block <sourcePos> {{!}} entity <source> {{!}} storage <source>)}} | ||
|} | |} | ||
:{| class="collapsible collapsed collapse-button-none" data-description="squished_tree" | :{| class="collapsible collapsed collapse-button-none" data-description="squished_tree" | ||
| Line 72: | Line 72: | ||
|- | |- | ||
| | | | ||
: {{ | : {{MC/Code|'''/data'''}} | ||
:* {{code|… '''[[#get|get]]''' (block <targetPos>{{!}}entity <target>{{!}}storage <target>) [<path>] [<scale>]}} | :* {{code|… '''[[#get|get]]''' (block <targetPos>{{!}}entity <target>{{!}}storage <target>) [<path>] [<scale>]}} | ||
:* {{code|… '''[[#merge|merge]]''' (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <nbt>}} | :* {{code|… '''[[#merge|merge]]''' (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <nbt>}} | ||
| Line 78: | Line 78: | ||
:** {{code|… from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | :** {{code|… from (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>]}} | ||
:** {{code|… string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | :** {{code|… string (block <sourcePos>{{!}}entity <source>{{!}}storage <source>) [<sourcePath>] [<start>] [<end>]}} | ||
:** {{ | :** {{MC/Code|… value <value>}} | ||
:* {{code|… '''[[#remove|remove]]''' (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <path>}} | :* {{code|… '''[[#remove|remove]]''' (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <path>}} | ||
|}<!-- | |}<!-- | ||
| Line 93: | Line 93: | ||
|- | |- | ||
| | | | ||
: {{ | : {{MC/Code|data '''[[#get|get]]''' block <targetPos> [<path>] [<scale>]}} | ||
: {{ | : {{MC/Code|data get entity <target> [<path>] [<scale>]}} | ||
: {{ | : {{MC/Code|data get storage <target> [<path>] [<scale>]}} | ||
: {{ | : {{MC/Code|data '''[[#merge|merge]]''' block <targetPos> <nbt>}} | ||
: {{ | : {{MC/Code|data merge entity <target> <nbt>}} | ||
: {{ | : {{MC/Code|data merge storage <target> <nbt>}} | ||
: {{ | : {{MC/Code|data '''[[#modify|modify]]''' block <targetPos> <targetPath> '''[[#modify|append]]''' from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> append from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> append from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> append string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> append string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> append value <value>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|insert <index>]]''' from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> insert <index> from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> insert <index> from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> insert <index> value <value>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|merge]]''' from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> merge from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> merge from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> merge string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> merge string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> merge value <value>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|prepend]]''' from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> prepend from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> prepend from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> prepend string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> prepend string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> prepend value <value>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|set]]''' from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> set from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> set from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> set string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> set string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify block <targetPos> <targetPath> set value <value>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> append from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> append from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> append from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> append string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> append string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> append value <value>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> insert <index> from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> insert <index> from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> insert <index> value <value>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> merge from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> merge from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> merge from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> merge string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> merge value <value>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> prepend from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> prepend from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> prepend from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> prepend string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> prepend value <value>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> set from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> set from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> set from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> set string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> set string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify entity <target> <targetPath> set value <value>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> append from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> append from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> append from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> append string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> append string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> append value <value>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> insert <index> from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> insert <index> from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> insert <index> value <value>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> merge from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> merge from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> merge from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> merge string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> merge value <value>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> prepend from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> prepend from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> prepend from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> prepend string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> prepend value <value>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> set from block <sourcePos> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> set from entity <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> set from storage <source> <sourcePath>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> set string entity <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> set string storage <source> <sourcePath> <start> <end>}} | ||
: {{ | : {{MC/Code|data modify storage <target> <targetPath> set value <value>}} | ||
: {{ | : {{MC/Code|data '''[[#remove|remove]]''' block <targetPos> <path>}} | ||
: {{ | : {{MC/Code|data remove entity <target> <path>}} | ||
: {{ | : {{MC/Code|data remove storage <target> <path>}} | ||
|} | |} | ||
== Arguments == | == Arguments == | ||
{{ | {{MC/Argument|targetPos|block_pos}} | ||
: The position of the target [[Minecraft:block entity]] whose NBT is to be operated on. | : The position of the target [[Minecraft:block entity]] whose NBT is to be operated on. | ||
: {{ | : {{MC/Arg desc|je=block_pos}} | ||
{{ | {{MC/Argument|target|entity}} (in {{MC/Cd|entity <target>}} mode) | ||
: Specifies an entity whose NBT is to be operated on. | : Specifies an entity whose NBT is to be operated on. | ||
: {{ | : {{MC/Arg desc|je=entity|amount=single|type=entities}} | ||
{{ | {{MC/Argument|target|resource_location}} (in {{MC/Cd|storage <target>}} mode) | ||
: Specifies a storage to be operated on. | : Specifies a storage to be operated on. | ||
: {{ | : {{MC/Arg desc|je=resource_location}} | ||
{{ | {{MC/Argument|path|nbt_path}} | ||
: Specifies the NBT to retrieve or remove. | : Specifies the NBT to retrieve or remove. | ||
: {{ | : {{MC/Arg desc|je=nbt_path}} | ||
{{ | {{MC/Argument|scale|double}} | ||
: Scalar for the command's output value. | : Scalar for the command's output value. | ||
: {{ | : {{MC/Arg desc|je=double}} | ||
{{ | {{MC/Argument|nbt|nbt_compound_tag}} | ||
: Specifies a compound tag to be merged into somewhere. | : Specifies a compound tag to be merged into somewhere. | ||
: {{ | : {{MC/Arg desc|je=nbt_compound_tag}} | ||
{{ | {{MC/Argument|targetPath|nbt_path}} | ||
: Specifies target NBT to modify. | : Specifies target NBT to modify. | ||
: {{ | : {{MC/Arg desc|je=nbt_path}} | ||
{{ | {{MC/Argument|index|integer}} | ||
: Specifies an item's index within a list. | : Specifies an item's index within a list. | ||
: {{ | : {{MC/Arg desc|je=integer}} | ||
{{ | {{MC/Argument|sourcePos|block_pos}} | ||
: The position of the target [[Minecraft:block entity]] whose NBT is to be used. | : The position of the target [[Minecraft:block entity]] whose NBT is to be used. | ||
: {{ | : {{MC/Arg desc|je=block_pos}} | ||
{{ | {{MC/Argument|source|entity}} (in {{MC/Cd|entity <source>}} mode) | ||
: Specifies an entity whose NBT is to be used by {{ | : Specifies an entity whose NBT is to be used by {{MC/Code|modify}}. | ||
: {{ | : {{MC/Arg desc|je=entity|amount=single|type=entities}} | ||
{{ | {{MC/Argument|source|resource_location}} (in {{MC/Cd|storage <source>}} mode) | ||
: Specifies a storage to be used by {{ | : Specifies a storage to be used by {{MC/Code|modify}}. | ||
: {{ | : {{MC/Arg desc|je=resource_location}} | ||
{{ | {{MC/Argument|sourcePath|nbt_path}} | ||
: Specifies the source NBT to be used by {{ | : Specifies the source NBT to be used by {{MC/Code|modify}}. | ||
: {{ | : {{MC/Arg desc|je=nbt_path}} | ||
{{ | {{MC/Argument|start|integer}} | ||
: Specifies the index of first character to include at the start of the string. Negative values are interpreted as index counted from the end of the string. | : Specifies the index of first character to include at the start of the string. Negative values are interpreted as index counted from the end of the string. | ||
: {{ | : {{MC/Arg desc|je=integer}} | ||
{{ | {{MC/Argument|end|integer}} | ||
: Specifies the index of the first character to exclude at the end of the string. Negative values are interpreted as index counted from the end of the string. | : Specifies the index of the first character to exclude at the end of the string. Negative values are interpreted as index counted from the end of the string. | ||
: {{ | : {{MC/Arg desc|je=integer}} | ||
{{ | {{MC/Argument|value|nbt_tag}} | ||
: Value used in modifying the target NBT. | : Value used in modifying the target NBT. | ||
: {{ | : {{MC/Arg desc|je=nbt_tag}} | ||
== Result == | == Result == | ||
{{Result table|onlyje=1}} | {{Result table|onlyje=1}} | ||
{{Result table|The command is incomplete, or any argument is not specified correctly.|unparseable}} | {{Result table|The command is incomplete, or any argument is not specified correctly.|unparseable}} | ||
{{Result table|{{ | {{Result table|{{MC/Code|<targetPos>}} is unloaded or out of the world.|fail}} | ||
{{Result table|The block at {{ | {{Result table|The block at {{MC/Code|<targetPos>}} is not a block entity.}} | ||
{{Result table|{{ | {{Result table|{{MC/Code|<target>}} (in {{MC/Cd|entity <target>}} mode) fails to resolve to a single entity (named player must be online).}} | ||
{{Result table|cmd=/data get ...|More than one tag is got.}} | {{Result table|cmd=/data get ...|More than one tag is got.}} | ||
{{Result table|cmd=/data get ... <path>|No tag exists at {{ | {{Result table|cmd=/data get ... <path>|No tag exists at {{MC/Code|<path>}}.}} | ||
{{Result table|cmd=/data get ... <path> <scale>|The obtained tag is not a numeric tag.}} | {{Result table|cmd=/data get ... <path> <scale>|The obtained tag is not a numeric tag.}} | ||
{{Result table|cmd=/data merge ...<br>/data remove ...<br>/data modify ...|Nothing is changed.}} | {{Result table|cmd=/data merge ...<br>/data remove ...<br>/data modify ...|Nothing is changed.}} | ||
{{Result table|Tries to edit a player's data.}} | {{Result table|Tries to edit a player's data.}} | ||
{{Result table|cmd=/data remove ...<br>/data modify ... set ...|{{ | {{Result table|cmd=/data remove ...<br>/data modify ... set ...|{{MC/Code|<path>}} selects the root compound tag.}} | ||
{{Result table|cmd=/data modify ... (from{{!}}string) block ...|{{ | {{Result table|cmd=/data modify ... (from{{!}}string) block ...|{{MC/Code|<sourcePos>}} is unloaded or out of the world.}} | ||
{{Result table|The block at {{ | {{Result table|The block at {{MC/Code|<sourcePos>}} is not a block entity.}} | ||
{{Result table|cmd=/data modify ... (from{{!}}string) entity ...|{{ | {{Result table|cmd=/data modify ... (from{{!}}string) entity ...|{{MC/Code|<source>}} fails to resolve to a single entity (named player must be online).}} | ||
{{Result table|cmd=/data modify ... (from{{!}}string) ... <sourcePath>|No tag exists at {{ | {{Result table|cmd=/data modify ... (from{{!}}string) ... <sourcePath>|No tag exists at {{MC/Code|<sourcePath>}}.}} | ||
{{Result table|cmd=/data modify ... string ... <sourcePath> <start> <end>|Any of the tags selected by {{ | {{Result table|cmd=/data modify ... string ... <sourcePath> <start> <end>|Any of the tags selected by {{MC/Code|<sourcePath>}} isn't string or numeric (will be converted to string) tag.}} | ||
{{Result table|{{ | {{Result table|{{MC/Cd|<start>}} or {{MC/Cd|<end>}} is out of valid index of any of the source strings.}} | ||
{{Result table|For any of the source strings, the character indexed by {{ | {{Result table|For any of the source strings, the character indexed by {{MC/Cd|<start>}} is behind of that indexed by {{MC/Cd|<end>}}.}} | ||
{{Result table|cmd=/data modify ... append ...<br>/data modify ... insert <index> ...<br>/data modify ... prepend ...|Any of the target tags isn't a list or array tag.}} | {{Result table|cmd=/data modify ... append ...<br>/data modify ... insert <index> ...<br>/data modify ... prepend ...|Any of the target tags isn't a list or array tag.}} | ||
{{Result table|All of the source tags aren't of the appropriate type for all of the target lists or arrays.}} | {{Result table|All of the source tags aren't of the appropriate type for all of the target lists or arrays.}} | ||
| Line 299: | Line 299: | ||
== Output == | == Output == | ||
{{Output table}} | {{MC/Output table}} | ||
{{Output table|edition=je|On fail|0|0|0}} | {{MC/Output table|edition=je|On fail|0|0|0}} | ||
{{Output table|cmd=/data get ...|On success|1|1|1}} | {{MC/Output table|cmd=/data get ...|On success|1|1|1}} | ||
{{Output table|cmd=/data get ... <path>|A numeric tag is got|1|1|The obtained value after rounding down<ref>double n = (double)value;<br>int output = n < (int)n ? (int)n - 1 :(int)n;<br>See also {{bug|MC-259032}}</ref>}} | {{Output table|cmd=/data get ... <path>|A numeric tag is got|1|1|The obtained value after rounding down<ref>double n = (double)value;<br>int output = n < (int)n ? (int)n - 1 :(int)n;<br>See also {{bug|MC-259032}}</ref>}} | ||
{{Output table|A list or array tag is got|1|1|The number of elements in this list or array}} | {{MC/Output table|A list or array tag is got|1|1|The number of elements in this list or array}} | ||
{{Output table|A string tag is got|1|1|The length of the string}} | {{MC/Output table|A string tag is got|1|1|The length of the string}} | ||
{{Output table|A compound tag is got|1|1|The number of tags that are direct children of that compound}} | {{MC/Output table|A compound tag is got|1|1|The number of tags that are direct children of that compound}} | ||
{{Output table|cmd=/data get ... <path> <scale>|On success|1|1|The obtained value multiplied by {{ | {{Output table|cmd=/data get ... <path> <scale>|On success|1|1|The obtained value multiplied by {{MC/Code|<scale>}}, then rounded down<ref>double n = (double)value * scale;<br>int output = n < (int)n ? (int)n - 1 :(int)n;<br>See also {{bug|MC-259032}}</ref>}} | ||
{{Output table|cmd=/data merge ...|On success|1|1|1}} | {{MC/Output table|cmd=/data merge ...|On success|1|1|1}} | ||
{{Output table|cmd=/data remove ...|On success|1|1|1}} | {{MC/Output table|cmd=/data remove ...|On success|1|1|1}} | ||
{{Output table|cmd=/data modify ... append ...<br>/data modify ... insert <index> ...<br>/data modify ... prepend ...|On success|1|1|The number of lists or arrays into which new elements are added}} | {{MC/Output table|cmd=/data modify ... append ...<br>/data modify ... insert <index> ...<br>/data modify ... prepend ...|On success|1|1|The number of lists or arrays into which new elements are added}} | ||
{{Output table|cmd=/data modify ... set ...|On success|1|1|The number of target tags that was successfully modified}} | {{MC/Output table|cmd=/data modify ... set ...|On success|1|1|The number of target tags that was successfully modified}} | ||
{{Output table|cmd=/data modify ... merge ...|On success|1|1|The number of target compound tags that was successfully modified}} | {{MC/Output table|cmd=/data modify ... merge ...|On success|1|1|The number of target compound tags that was successfully modified}} | ||
{{Output table}} | {{MC/Output table}} | ||
== Examples == | == Examples == | ||
* To view the NBT data of the player's held item: | * To view the NBT data of the player's held item: | ||
*: {{ | *: {{MC/Code|/data get entity @s SelectedItem}} | ||
* To get the saturation level of the current player: | * To get the saturation level of the current player: | ||
*: {{ | *: {{MC/Code|/data get entity @s foodSaturationLevel}} | ||
* To make the nearest item within 10 blocks unable to be picked up by players: | * To make the nearest item within 10 blocks unable to be picked up by players: | ||
*: {{ | *: {{MC/Code|1=/data modify entity @n[type=item,distance=..10] PickupDelay set value -1s}} | ||
* To get the Y-position of a random item: | * To get the Y-position of a random item: | ||
*: {{ | *: {{MC/Code|1=/data get entity @e[type=item,limit=1,sort=random] Pos[1]}} | ||
* To get the item ID of the item in the first hotbar slot of the nearest player: | * To get the item ID of the item in the first hotbar slot of the nearest player: | ||
*: <code>/data get entity @p Inventory[{Slot:0b}].id</code> | *: <code>/data get entity @p Inventory[{Slot:0b}].id</code> | ||
* To change the first item in a chest located at coordinates (1, 64, 1) into a diamond block, keeping all NBT data: | * To change the first item in a chest located at coordinates (1, 64, 1) into a diamond block, keeping all NBT data: | ||
*: {{ | *: {{MC/Code|/data modify block 1 64 1 Items[0].id set value "minecraft:diamond_block"}} | ||
* To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, and never drop items in the main hand: | * To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, and never drop items in the main hand: | ||
*: <code>/data merge entity @n[type=zombie] {drop_chances:{mainhand:0f,offhand:0.8f}}</code> | *: <code>/data merge entity @n[type=zombie] {drop_chances:{mainhand:0f,offhand:0.8f}}</code> | ||
* To make the nearest zombie have an 80% chance to drop items in its off-hand when it dies, without affecting the chance for the main hand: | * To make the nearest zombie have an 80% chance to drop items in its off-hand when it dies, without affecting the chance for the main hand: | ||
*: {{ | *: {{MC/Code|1=/data modify entity @n[type=zombie] drop_chances.offhand set value 0.8f}} | ||
=== List, array and string length === | === List, array and string length === | ||
With {{ | With {{MC/Cmd|data get|link=none}}, it is possible to get the length of lists or arrays and the number of characters in strings, since its return value is the length of the string, list, or arrays being referenced. This value can then be stored using {{MC/Cmd|execute store}}, if necessary. | ||
;List example | ;List example | ||
| Line 342: | Line 342: | ||
Then, running the following returns <code>6</code>, the length of the list: | Then, running the following returns <code>6</code>, the length of the list: | ||
:{{ | :{{MC/Cmd|link=none|data get storage wiki:example List}} | ||
;String example | ;String example | ||
| Line 351: | Line 351: | ||
Then, running the following returns <code>43</code>, the length of the string: | Then, running the following returns <code>43</code>, the length of the string: | ||
:{{ | :{{MC/Cmd|link=none|data get storage wiki:example String}} | ||
== History == | == History == | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|java}} | |{{MC/HistoryLine|java}} | ||
|{{HistoryLine||1.13|dev=17w45b|Added {{ | |{{HistoryLine||1.13|dev=17w45b|Added {{MC/Cmd|data|link=none}}.}} | ||
|{{HistoryLine|||dev=17w47a|Commands {{ | |{{HistoryLine|||dev=17w47a|Commands {{MC/Cmd|blockdata}} and {{MC/Cmd|entitydata}} have been removed as their features are merged into {{MC/Cmd|data|link=none}}.}} | ||
|{{HistoryLine|||dev=18w03a|Using {{ | |{{HistoryLine|||dev=18w03a|Using {{MC/Cmd|data get|link=none}} with a path now works on non-numeric values.}} | ||
|{{HistoryLine||1.14|dev=18w43a|Added {{ | |{{HistoryLine||1.14|dev=18w43a|Added {{MC/Cmd|data modify|link=none}}.}} | ||
|{{HistoryLine||1.15|dev=19w38a|Added {{ | |{{HistoryLine||1.15|dev=19w38a|Added {{MC/Cd|storage <''resource location''>}} as a source or target.}} | ||
|{{HistoryLine||1.19.4|dev=23w03a|Added {{ | |{{HistoryLine||1.19.4|dev=23w03a|Added {{MC/Cd|string}} source.}} | ||
|{{HistoryLine||1.20|dev=Pre-release 1|Now {{ | |{{HistoryLine||1.20|dev=Pre-release 1|Now {{MC/Cd|<start>}} or {{MC/Cd|<end>}} in {{MC/Cd|string}} source accept negative boundaries, which are interpreted as index counted from the end of the string.}} | ||
|{{HistoryLine|||dev=Pre-release 2|Now invalid {{ | |{{HistoryLine|||dev=Pre-release 2|Now invalid {{MC/Cd|<start>}} or {{MC/Cd|<end>}} in {{MC/Cd|string}} source result in command failure instead of unhandaled error.<ref>{{bug|MC-260602||/data modify from string index failure does not return 0 for /execute store success.|Fixed}}</ref>}} | ||
|{{HistoryLine||1.21.5|dev=25w09a|Can now create and modify heterogeneous lists transparently.|Can no longer traverse paths with an empty key.}} | |{{MC/HistoryLine||1.21.5|dev=25w09a|Can now create and modify heterogeneous lists transparently.|Can no longer traverse paths with an empty key.}} | ||
}} | }} | ||
| Line 371: | Line 371: | ||
== Navigation == | == Navigation == | ||
{{Navbox commands}} | {{MC/Navbox commands}} | ||
de:Befehl/data | |||
es:Comandos/data | |||
ja:コマンド/data | |||
pt:Comandos/data | |||
ru:Команды консоли/data | |||
uk:Команди консолі/data | |||
zh:命令/data | |||
Latest revision as of 20:09, 9 April 2026
Template:Hatnote Script error: No such module "Exclusive". Template:Infobox command
Allows the user to get, merge, modify, and remove NBT data of a Minecraft:block entity, entity, or Command NBT storage.
Syntax
There are four instructions for /data (get, merge, modify, remove), and the targets/sources referenced by each instruction command may be either block <targetPos>, entity <target>, or
- REDIRECT Template:Code
/data ......
REDIRECT Template:Visible anchor
- Template:Code
- Read off the entire NBT data or the subsection of the NBT data from the targeted block position or entity to the executor with syntax highlighting, scaled by
<scale>if specified.
- Read off the entire NBT data or the subsection of the NBT data from the targeted block position or entity to the executor with syntax highlighting, scaled by
- Template:Code
...
REDIRECT Template:Visible anchor
- Template:Code
- Merge the NBT data from the target block position or entity with the specified
<nbt>data.
- Merge the NBT data from the target block position or entity with the specified
- Template:Code
...
REDIRECT Template:Visible anchor (block <targetPos>|entity <target>|storage <target>) <targetPath> ...
- Template:Code
- Template:Code
... append value <value>- Append the source data or direct value data onto the end of the pointed-to list or array.
- Template:Code
- Template:Code
... insert <index> value <value>- Insert the source data or direct value data into the pointed-to list or array as element
<index>, then shift higher elements one position upward.
- Insert the source data or direct value data into the pointed-to list or array as element
- Template:Code
- Template:Code
... merge value <value>- Merge the source data or direct value data into the pointed-to object.
- Template:Code
- Template:Code
... prepend value <value>- Prepend the source data or direct value data onto the beginning of the pointed-to list or array.
- Template:Code
- Template:Code
... set value <value>- Set the tag specified by
<targetPath>to the source data or direct value data.
- Set the tag specified by
...
REDIRECT Template:Visible anchor
- Template:Code
- Removes NBT data at
<path>from the targeted block position or entity. Player NBT data cannot be removed.
- Removes NBT data at
- Template:Code
Syntax displayed in various ways
Simplified tree: /data- where substituted arguments are:
<TARGET>= Template:Code<MODIFICATION>= Template:Code<SOURCE>= Template:Code
Squished tree: /data- Template:Code
- Template:Code
- Template:Code
- Template:Code
- Template:Code
… value <value>
- Template:Code
Maximised: data get block <targetPos> [<path>] [<scale>]data get entity <target> [<path>] [<scale>]data get storage <target> [<path>] [<scale>]data merge block <targetPos> <nbt>data merge entity <target> <nbt>data merge storage <target> <nbt>data modify block <targetPos> <targetPath> append from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> append from entity <source> <sourcePath>data modify block <targetPos> <targetPath> append from storage <source> <sourcePath>data modify block <targetPos> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> append string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> append string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> append value <value>data modify block <targetPos> <targetPath> insert <index> from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> insert <index> from entity <source> <sourcePath>data modify block <targetPos> <targetPath> insert <index> from storage <source> <sourcePath>data modify block <targetPos> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> insert <index> value <value>data modify block <targetPos> <targetPath> merge from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> merge from entity <source> <sourcePath>data modify block <targetPos> <targetPath> merge from storage <source> <sourcePath>data modify block <targetPos> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> merge string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> merge string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> merge value <value>data modify block <targetPos> <targetPath> prepend from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> prepend from entity <source> <sourcePath>data modify block <targetPos> <targetPath> prepend from storage <source> <sourcePath>data modify block <targetPos> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> prepend string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> prepend string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> prepend value <value>data modify block <targetPos> <targetPath> set from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> set from entity <source> <sourcePath>data modify block <targetPos> <targetPath> set from storage <source> <sourcePath>data modify block <targetPos> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> set string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> set string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> set value <value>data modify entity <target> <targetPath> append from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> append from entity <source> <sourcePath>data modify entity <target> <targetPath> append from storage <source> <sourcePath>data modify entity <target> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> append string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> append string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> append value <value>data modify entity <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> insert <index> from entity <source> <sourcePath>data modify entity <target> <targetPath> insert <index> from storage <source> <sourcePath>data modify entity <target> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> insert <index> value <value>data modify entity <target> <targetPath> merge from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> merge from entity <source> <sourcePath>data modify entity <target> <targetPath> merge from storage <source> <sourcePath>data modify entity <target> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> merge string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> merge value <value>data modify entity <target> <targetPath> prepend from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> prepend from entity <source> <sourcePath>data modify entity <target> <targetPath> prepend from storage <source> <sourcePath>data modify entity <target> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> prepend string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> prepend value <value>data modify entity <target> <targetPath> set from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> set from entity <source> <sourcePath>data modify entity <target> <targetPath> set from storage <source> <sourcePath>data modify entity <target> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> set string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> set string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> set value <value>data modify storage <target> <targetPath> append from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> append from entity <source> <sourcePath>data modify storage <target> <targetPath> append from storage <source> <sourcePath>data modify storage <target> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> append string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> append string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> append value <value>data modify storage <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> insert <index> from entity <source> <sourcePath>data modify storage <target> <targetPath> insert <index> from storage <source> <sourcePath>data modify storage <target> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> insert <index> value <value>data modify storage <target> <targetPath> merge from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> merge from entity <source> <sourcePath>data modify storage <target> <targetPath> merge from storage <source> <sourcePath>data modify storage <target> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> merge string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> merge value <value>data modify storage <target> <targetPath> prepend from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> prepend from entity <source> <sourcePath>data modify storage <target> <targetPath> prepend from storage <source> <sourcePath>data modify storage <target> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> prepend string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> prepend value <value>data modify storage <target> <targetPath> set from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> set from entity <source> <sourcePath>data modify storage <target> <targetPath> set from storage <source> <sourcePath>data modify storage <target> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> set string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> set string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> set value <value>data remove block <targetPos> <path>data remove entity <target> <path>data remove storage <target> <path>
Arguments
<targetPos>: block_pos
- The position of the target Minecraft:block entity whose NBT is to be operated on.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<target>: entity (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies an entity whose NBT is to be operated on.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<target>: resource_location (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies a storage to be operated on.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
- Specifies the NBT to retrieve or remove.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<scale>: double
- Scalar for the command's output value.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|double}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<nbt>: nbt_compound_tag
- Specifies a compound tag to be merged into somewhere.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_compound_tag}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<targetPath>: nbt_path
- Specifies target NBT to modify.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<index>: integer
- Specifies an item's index within a list.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<sourcePos>: block_pos
- The position of the target Minecraft:block entity whose NBT is to be used.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<source>: entity (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies an entity whose NBT is to be used by
modify. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<source>: resource_location (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies a storage to be used by
modify. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<sourcePath>: nbt_path
- Specifies the source NBT to be used by
modify. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<start>: integer
- Specifies the index of first character to include at the start of the string. Negative values are interpreted as index counted from the end of the string.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<end>: integer
- Specifies the index of the first character to exclude at the end of the string. Negative values are interpreted as index counted from the end of the string.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<value>: nbt_tag
- Value used in modifying the target NBT.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_tag}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
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 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}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#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}}|je}}{{#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}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|1}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data get ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
Template:Output table
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|A list or array tag is got}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of elements in this list or array}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#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}}|A string tag is got}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The length of the string}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#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}}|A compound tag is got}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of tags that are direct children of that compound}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
Template:Output table
{{#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}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|1}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data merge ...}}{{#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}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|1}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data remove ...}}{{#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}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of lists or arrays into which new elements are added}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data modify ... append ...}}{{#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}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of target tags that was successfully modified}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|
/data modify ... insert <index> ...
/data modify ... prepend .../data modify ... set ...}}{{#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}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of target compound tags that was successfully modified}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data modify ... merge ...}}{{#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 view the NBT data of the player's held item:
/data get entity @s SelectedItem
- To get the saturation level of the current player:
/data get entity @s foodSaturationLevel
- To make the nearest item within 10 blocks unable to be picked up by players:
/data modify entity @n[type=item,distance=..10] PickupDelay set value -1s
- To get the Y-position of a random item:
/data get entity @e[type=item,limit=1,sort=random] Pos[1]
- To get the item ID of the item in the first hotbar slot of the nearest player:
/data get entity @p Inventory[{Slot:0b}].id
- To change the first item in a chest located at coordinates (1, 64, 1) into a diamond block, keeping all NBT data:
/data modify block 1 64 1 Items[0].id set value "minecraft:diamond_block"
- To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, and never drop items in the main hand:
/data merge entity @n[type=zombie] {drop_chances:{mainhand:0f,offhand:0.8f}}
- To make the nearest zombie have an 80% chance to drop items in its off-hand when it dies, without affecting the chance for the main hand:
/data modify entity @n[type=zombie] drop_chances.offhand set value 0.8f
List, array and string length
With
- REDIRECT Template:Command
Template:Redr, it is possible to get the length of lists or arrays and the number of characters in strings, since its return value is the length of the string, list, or arrays being referenced. This value can then be stored using
- REDIRECT Template:Command
Template:Redr, if necessary.
- List example
Suppose a list is stored using the following command:
Then, running the following returns 6, the length of the list:
- REDIRECT Template:Command
- String example
Suppose a string is stored using the following command:
Then, running the following returns 43, the length of the string:
- REDIRECT Template:Command
History
References
<references/>
de:Befehl/data es:Comandos/data ja:コマンド/data pt:Comandos/data ru:Команды консоли/data uk:Команди консолі/data zh:命令/data