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/data: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
Line 1: Line 1:
{{MC/Distinguish|Commands/datapack}}
{{distinguish|Commands/datapack}}
{{MC/Exclusive|java}}
{{exclusive|java}}
{{Infobox command
{{Infobox command
|name=data
|name=data
Line 6: Line 6:
}}
}}


Allows the user to get, merge, modify, and remove NBT data of a [[Minecraft:block entity]], entity, or Command NBT storage.
Allows the user to get, merge, modify, and remove [[Minecraft:NBT format|NBT data]] of a [[Minecraft:block entity]], [[Minecraft:entity]], or [[Minecraft:Command storage|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 {{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>}}.
There are four instructions for {{code|/data}} ({{code|[[#get|get]]}}, {{code|[[#merge|merge]]}}, {{code|[[#modify|modify]]}}, {{code|[[#remove|remove]]}}), and the targets/sources referenced by each instruction command may be either {{code|block <targetPos>}}, {{code|entity <target>}}, or {{cd|storage <target>}}.


; {{MC/Code|/'''data''' ...}}
; {{code|/'''data''' ...}}
: <code>... '''{{MC/Text anchor|get}}'''</code>
: <code>... '''{{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 {{MC/Code|<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 {{code|<scale>}} if specified.


: <code>... '''{{MC/Text anchor|merge}}'''</code>
: <code>... '''{{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 {{MC/Code|<nbt>}} data.
::: Merge the NBT data from the target block position or entity with the specified {{code|<nbt>}} data.


: <code>... '''{{MC/Text anchor|modify}}''' (block <targetPos>|entity <target>|storage <target>) <targetPath> ...</code>
: <code>... '''{{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>}}
:: {{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>}}
:: {{code|... '''insert <index>''' value <value>}}
::: 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.
::: Insert the source data or direct value data into the pointed-to list or array as element {{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>}}
:: {{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>}}
:: {{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>}}
:: {{code|... '''set''' value <value>}}
::: Set the tag specified by {{MC/Code|<targetPath>}} to the source data or direct value data.
::: Set the tag specified by {{code|<targetPath>}} to the source data or direct value data.


: <code>... '''{{MC/Text anchor|remove}}'''</code>
: <code>... '''{{Text anchor|remove}}'''</code>
:: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <path>}}
:: {{code|... (block <targetPos>{{!}}entity <target>{{!}}storage <target>) <path>}}
::: Removes NBT data at {{MC/Code|<path>}} from the targeted block position or entity. Player NBT data cannot be removed.
::: Removes NBT data at {{code|<path>}} from the targeted block position or entity. Player NBT data cannot be removed.




Line 54: Line 54:
|-
|-
|
|
: {{MC/Code|'''/data'''}}
: {{code|'''/data'''}}
:* {{MC/Code|… '''[[#get|get]]''' <''TARGET''> [<path>] [<scale>]}}
:* {{code|… '''[[#get|get]]''' <''TARGET''> [<path>] [<scale>]}}
:* {{MC/Code|… '''[[#merge|merge]]''' <''TARGET''> <nbt>}}
:* {{code|… '''[[#merge|merge]]''' <''TARGET''> <nbt>}}
:* {{MC/Code|… '''[[#modify|modify]]''' <''TARGET''> <targetPath> <''MODIFICATION''>}}
:* {{code|… '''[[#modify|modify]]''' <''TARGET''> <targetPath> <''MODIFICATION''>}}
:** {{MC/Code|… from <''SOURCE''> [<sourcePath>]}}
:** {{code|… from <''SOURCE''> [<sourcePath>]}}
:** {{MC/Code|… string <''SOURCE''> [<sourcePath>] [<start>] [<end>]}}
:** {{code|… string <''SOURCE''> [<sourcePath>] [<start>] [<end>]}}
:** {{MC/Code|… value <value>}}
:** {{code|… value <value>}}
:* {{MC/Code|… '''[[#remove|remove]]''' <TARGET> <path>}}
:* {{code|… '''[[#remove|remove]]''' <TARGET> <path>}}
: where substituted arguments are:
: where substituted arguments are:
:: {{MC/Code|<''TARGET''>}} = {{code|(block <targetPos> {{!}} entity <target> {{!}} storage <target>)}}
:: {{code|<''TARGET''>}} = {{code|(block <targetPos> {{!}} entity <target> {{!}} storage <target>)}}
:: {{MC/Code|<''MODIFICATION''>}} = {{code|('''[[#modify|append]]'''{{!}}'''[[#modify|insert <index>]]'''{{!}}'''[[#modify|merge]]'''{{!}}'''[[#modify|prepend]]'''{{!}}'''[[#modify|set]]''')}}
:: {{code|<''MODIFICATION''>}} = {{code|('''[[#modify|append]]'''{{!}}'''[[#modify|insert <index>]]'''{{!}}'''[[#modify|merge]]'''{{!}}'''[[#modify|prepend]]'''{{!}}'''[[#modify|set]]''')}}
:: {{MC/Code|<''SOURCE''>}} = {{code|(block <sourcePos> {{!}} entity <source> {{!}} storage <source>)}}
:: {{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|'''/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|… 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>]}}
: {{code|data '''[[#get|get]]''' block <targetPos> [<path>] [<scale>]}}
: {{MC/Code|data get entity <target> [<path>] [<scale>]}}
: {{code|data get entity <target> [<path>] [<scale>]}}
: {{MC/Code|data get storage <target> [<path>] [<scale>]}}
: {{code|data get storage <target> [<path>] [<scale>]}}
: {{MC/Code|data '''[[#merge|merge]]''' block <targetPos> <nbt>}}
: {{code|data '''[[#merge|merge]]''' block <targetPos> <nbt>}}
: {{MC/Code|data merge entity <target> <nbt>}}
: {{code|data merge entity <target> <nbt>}}
: {{MC/Code|data merge storage <target> <nbt>}}
: {{code|data merge storage <target> <nbt>}}
: {{MC/Code|data '''[[#modify|modify]]''' block <targetPos> <targetPath> '''[[#modify|append]]''' from block <sourcePos> <sourcePath>}}
: {{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>}}
: {{code|data modify block <targetPos> <targetPath> append from entity <source> <sourcePath>}}
: {{MC/Code|data modify block <targetPos> <targetPath> append from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify block <targetPos> <targetPath> append string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify block <targetPos> <targetPath> append value <value>}}
: {{code|data modify block <targetPos> <targetPath> append value <value>}}
: {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|insert <index>]]''' from block <sourcePos> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify block <targetPos> <targetPath> insert <index> value <value>}}
: {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|merge]]''' from block <sourcePos> <sourcePath>}}
: {{code|data modify block <targetPos> <targetPath> '''[[#modify|merge]]''' from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify block <targetPos> <targetPath> merge from entity <source> <sourcePath>}}
: {{code|data modify block <targetPos> <targetPath> merge from entity <source> <sourcePath>}}
: {{MC/Code|data modify block <targetPos> <targetPath> merge from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify block <targetPos> <targetPath> merge string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify block <targetPos> <targetPath> merge value <value>}}
: {{code|data modify block <targetPos> <targetPath> merge value <value>}}
: {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|prepend]]''' from block <sourcePos> <sourcePath>}}
: {{code|data modify block <targetPos> <targetPath> '''[[#modify|prepend]]''' from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify block <targetPos> <targetPath> prepend from entity <source> <sourcePath>}}
: {{code|data modify block <targetPos> <targetPath> prepend from entity <source> <sourcePath>}}
: {{MC/Code|data modify block <targetPos> <targetPath> prepend from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify block <targetPos> <targetPath> prepend string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify block <targetPos> <targetPath> prepend value <value>}}
: {{code|data modify block <targetPos> <targetPath> prepend value <value>}}
: {{MC/Code|data modify block <targetPos> <targetPath> '''[[#modify|set]]''' from block <sourcePos> <sourcePath>}}
: {{code|data modify block <targetPos> <targetPath> '''[[#modify|set]]''' from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify block <targetPos> <targetPath> set from entity <source> <sourcePath>}}
: {{code|data modify block <targetPos> <targetPath> set from entity <source> <sourcePath>}}
: {{MC/Code|data modify block <targetPos> <targetPath> set from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify block <targetPos> <targetPath> set string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify block <targetPos> <targetPath> set value <value>}}
: {{code|data modify block <targetPos> <targetPath> set value <value>}}
: {{MC/Code|data modify entity <target> <targetPath> append from block <sourcePos> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> append from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> append from entity <source> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> append from entity <source> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> append from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify entity <target> <targetPath> append string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify entity <target> <targetPath> append value <value>}}
: {{code|data modify entity <target> <targetPath> append value <value>}}
: {{MC/Code|data modify entity <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify entity <target> <targetPath> insert <index> value <value>}}
: {{MC/Code|data modify entity <target> <targetPath> merge from block <sourcePos> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> merge from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> merge from entity <source> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> merge from entity <source> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> merge from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify entity <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify entity <target> <targetPath> merge value <value>}}
: {{code|data modify entity <target> <targetPath> merge value <value>}}
: {{MC/Code|data modify entity <target> <targetPath> prepend from block <sourcePos> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> prepend from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> prepend from entity <source> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> prepend from entity <source> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> prepend from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify entity <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify entity <target> <targetPath> prepend value <value>}}
: {{code|data modify entity <target> <targetPath> prepend value <value>}}
: {{MC/Code|data modify entity <target> <targetPath> set from block <sourcePos> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> set from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> set from entity <source> <sourcePath>}}
: {{code|data modify entity <target> <targetPath> set from entity <source> <sourcePath>}}
: {{MC/Code|data modify entity <target> <targetPath> set from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify entity <target> <targetPath> set string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify entity <target> <targetPath> set value <value>}}
: {{code|data modify entity <target> <targetPath> set value <value>}}
: {{MC/Code|data modify storage <target> <targetPath> append from block <sourcePos> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> append from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> append from entity <source> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> append from entity <source> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> append from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify storage <target> <targetPath> append string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify storage <target> <targetPath> append value <value>}}
: {{code|data modify storage <target> <targetPath> append value <value>}}
: {{MC/Code|data modify storage <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify storage <target> <targetPath> insert <index> value <value>}}
: {{MC/Code|data modify storage <target> <targetPath> merge from block <sourcePos> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> merge from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> merge from entity <source> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> merge from entity <source> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> merge from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify storage <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify storage <target> <targetPath> merge value <value>}}
: {{code|data modify storage <target> <targetPath> merge value <value>}}
: {{MC/Code|data modify storage <target> <targetPath> prepend from block <sourcePos> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> prepend from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> prepend from entity <source> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> prepend from entity <source> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> prepend from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify storage <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify storage <target> <targetPath> prepend value <value>}}
: {{code|data modify storage <target> <targetPath> prepend value <value>}}
: {{MC/Code|data modify storage <target> <targetPath> set from block <sourcePos> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> set from block <sourcePos> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> set from entity <source> <sourcePath>}}
: {{code|data modify storage <target> <targetPath> set from entity <source> <sourcePath>}}
: {{MC/Code|data modify storage <target> <targetPath> set from storage <source> <sourcePath>}}
: {{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>}}
: {{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>}}
: {{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>}}
: {{code|data modify storage <target> <targetPath> set string storage <source> <sourcePath> <start> <end>}}
: {{MC/Code|data modify storage <target> <targetPath> set value <value>}}
: {{code|data modify storage <target> <targetPath> set value <value>}}
: {{MC/Code|data '''[[#remove|remove]]''' block <targetPos> <path>}}
: {{code|data '''[[#remove|remove]]''' block <targetPos> <path>}}
: {{MC/Code|data remove entity <target> <path>}}
: {{code|data remove entity <target> <path>}}
: {{MC/Code|data remove storage <target> <path>}}
: {{code|data remove storage <target> <path>}}
|}
|}


== Arguments ==
== Arguments ==


{{MC/Argument|targetPos|block_pos}}
{{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}}
: {{arg desc|je=block_pos}}


{{MC/Argument|target|entity}} (in {{MC/Cd|entity <target>}} mode)
{{argument|target|entity}} (in {{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}}
: {{arg desc|je=entity|amount=single|type=entities}}


{{MC/Argument|target|resource_location}} (in {{MC/Cd|storage <target>}} mode)
{{argument|target|resource_location}} (in {{cd|storage <target>}} mode)
: Specifies a storage to be operated on.
: Specifies a storage to be operated on.
: {{MC/Arg desc|je=resource_location}}
: {{arg desc|je=resource_location}}


{{MC/Argument|path|nbt_path}}
{{argument|path|nbt_path}}
: Specifies the NBT to retrieve or remove.
: Specifies the NBT to retrieve or remove.
: {{MC/Arg desc|je=nbt_path}}
: {{arg desc|je=nbt_path}}


{{MC/Argument|scale|double}}
{{argument|scale|double}}
: Scalar for the command's output value.
: Scalar for the command's output value.
: {{MC/Arg desc|je=double}}
: {{arg desc|je=double}}


{{MC/Argument|nbt|nbt_compound_tag}}
{{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}}
: {{arg desc|je=nbt_compound_tag}}


{{MC/Argument|targetPath|nbt_path}}
{{argument|targetPath|nbt_path}}
: Specifies target NBT to modify.
: Specifies target NBT to modify.
: {{MC/Arg desc|je=nbt_path}}
: {{arg desc|je=nbt_path}}


{{MC/Argument|index|integer}}
{{argument|index|integer}}
: Specifies an item's index within a list.
: Specifies an item's index within a list.
: {{MC/Arg desc|je=integer}}
: {{arg desc|je=integer}}


{{MC/Argument|sourcePos|block_pos}}
{{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}}
: {{arg desc|je=block_pos}}


{{MC/Argument|source|entity}} (in {{MC/Cd|entity <source>}} mode)
{{argument|source|entity}} (in {{cd|entity <source>}} mode)
: Specifies an entity whose NBT is to be used by {{MC/Code|modify}}.
: Specifies an entity whose NBT is to be used by {{code|modify}}.
: {{MC/Arg desc|je=entity|amount=single|type=entities}}
: {{arg desc|je=entity|amount=single|type=entities}}


{{MC/Argument|source|resource_location}} (in {{MC/Cd|storage <source>}} mode)
{{argument|source|resource_location}} (in {{cd|storage <source>}} mode)
: Specifies a storage to be used by {{MC/Code|modify}}.
: Specifies a storage to be used by {{code|modify}}.
: {{MC/Arg desc|je=resource_location}}
: {{arg desc|je=resource_location}}


{{MC/Argument|sourcePath|nbt_path}}
{{argument|sourcePath|nbt_path}}
: Specifies the source NBT to be used by {{MC/Code|modify}}.
: Specifies the source NBT to be used by {{code|modify}}.
: {{MC/Arg desc|je=nbt_path}}
: {{arg desc|je=nbt_path}}


{{MC/Argument|start|integer}}
{{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}}
: {{arg desc|je=integer}}


{{MC/Argument|end|integer}}
{{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}}
: {{arg desc|je=integer}}


{{MC/Argument|value|nbt_tag}}
{{argument|value|nbt_tag}}
: Value used in modifying the target NBT.
: Value used in modifying the target NBT.
: {{MC/Arg desc|je=nbt_tag}}
: {{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|{{MC/Code|<targetPos>}} is unloaded or out of the world.|fail}}
{{Result table|{{code|<targetPos>}} is unloaded or out of the world.|fail}}
{{Result table|The block at {{MC/Code|<targetPos>}} is not a block entity.}}
{{Result table|The block at {{code|<targetPos>}} is not a block entity.}}
{{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|{{code|<target>}} (in {{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 given.}}
{{Result table|cmd=/data get ... <path>|No tag exists at {{MC/Code|<path>}}.}}
{{Result table|cmd=/data get ... <path>|No tag exists at {{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 ...|{{MC/Code|<path>}} selects the root compound tag.}}
{{Result table|cmd=/data remove ...<br>/data modify ... set ...|{{code|<path>}} selects the root compound tag.}}
{{Result table|cmd=/data modify ... (from{{!}}string) block ...|{{MC/Code|<sourcePos>}} is unloaded or out of the world.}}
{{Result table|cmd=/data modify ... (from{{!}}string) block ...|{{code|<sourcePos>}} is unloaded or out of the world.}}
{{Result table|The block at {{MC/Code|<sourcePos>}} is not a block entity.}}
{{Result table|The block at {{code|<sourcePos>}} is not a block 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) entity ...|{{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 {{MC/Code|<sourcePath>}}.}}
{{Result table|cmd=/data modify ... (from{{!}}string) ... <sourcePath>|No tag exists at {{code|<sourcePath>}}.}}
{{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|cmd=/data modify ... string ... <sourcePath> <start> <end>|Any of the tags selected by {{code|<sourcePath>}} isn't string or numeric (will be converted to string) tag.}}
{{Result table|{{MC/Cd|<start>}} or {{MC/Cd|<end>}} is out of valid index of any of the source strings.}}
{{Result table|{{cd|<start>}} or {{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 {{MC/Cd|<start>}} is behind of that indexed by {{MC/Cd|<end>}}.}}
{{Result table|For any of the source strings, the character indexed by {{cd|<start>}} is behind of that indexed by {{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 ==
{{MC/Output table}}
{{Output table}}
{{MC/Output table|edition=je|On fail|0|0|0}}
{{Output table|edition=je|On fail|0|0|0}}
{{MC/Output table|cmd=/data get ...|On success|1|1|1}}
{{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>}}
{{MC/Output table|A list or array tag is got|1|1|The number of elements in this list or array}}
{{Output table|A list or array tag is got|1|1|The number of elements in this list or array}}
{{MC/Output table|A string tag is got|1|1|The length of the string}}
{{Output table|A string tag is got|1|1|The length of the string}}
{{MC/Output table|A compound tag is got|1|1|The number of tags that are direct children of that compound}}
{{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 {{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 get ... <path> <scale>|On success|1|1|The obtained value multiplied by {{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>}}
{{MC/Output table|cmd=/data merge ...|On success|1|1|1}}
{{Output table|cmd=/data merge ...|On success|1|1|1}}
{{MC/Output table|cmd=/data remove ...|On success|1|1|1}}
{{Output table|cmd=/data remove ...|On success|1|1|1}}
{{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 ... 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 ... set ...|On success|1|1|The number of target tags that was successfully modified}}
{{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 ... merge ...|On success|1|1|The number of target compound 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}}
{{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}}
*: {{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}}
*: {{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}}
*: {{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]}}
*: {{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"}}
*: {{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}}
*: {{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 {{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.
With {{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 {{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}}
:{{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}}
:{{cmd|link=none|data get storage wiki:example String}}


== History ==
== History ==
{{HistoryTable
{{HistoryTable
|{{MC/HistoryLine|java}}
|{{HistoryLine|java}}
|{{HistoryLine||1.13|dev=17w45b|Added {{MC/Cmd|data|link=none}}.}}
|{{HistoryLine||1.13|dev=17w45b|Added {{cmd|data|link=none}}.}}
|{{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=17w47a|Commands {{cmd|blockdata}} and {{cmd|entitydata}} have been removed as their features are merged into {{cmd|data|link=none}}.}}
|{{HistoryLine|||dev=18w03a|Using {{MC/Cmd|data get|link=none}} with a path now works on non-numeric values.}}
|{{HistoryLine|||dev=18w03a|Using {{cmd|data get|link=none}} with a path now works on non-numeric values.}}
|{{HistoryLine||1.14|dev=18w43a|Added {{MC/Cmd|data modify|link=none}}.}}
|{{HistoryLine||1.14|dev=18w43a|Added {{cmd|data modify|link=none}}.}}
|{{HistoryLine||1.15|dev=19w38a|Added {{MC/Cd|storage <''resource location''>}} as a source or target.}}
|{{HistoryLine||1.15|dev=19w38a|Added {{cd|storage <''[[Minecraft:resource location]]''>}} as a source or target.}}
|{{HistoryLine||1.19.4|dev=23w03a|Added {{MC/Cd|string}} source.}}
|{{HistoryLine||1.19.4|dev=23w03a|Added {{cd|string}} source.}}
|{{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||1.20|dev=Pre-release 1|Now {{cd|<start>}} or {{cd|<end>}} in {{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 {{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|||dev=Pre-release 2|Now invalid {{cd|<start>}} or {{cd|<end>}} in {{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>}}
|{{MC/HistoryLine||1.21.5|dev=25w09a|Can now create and modify heterogeneous lists transparently.|Can no longer traverse paths with an empty key.}}
|{{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 ==
{{MC/Navbox commands}}
{{Navbox commands}}


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

Latest revision as of 11:04, 29 May 2026

Template:Distinguish Template:Exclusive Template:Infobox command

Allows the user to get, merge, modify, and remove NBT data of a Minecraft:block entity, Minecraft:entity, or Command NBT storage.

Syntax

File:Data graph.svg
A graph that describes the syntax of this command.

There are four instructions for Template:Code (Template:Code, Template:Code, Template:Code, Template:Code), and the targets/sources referenced by each instruction command may be either Template:Code, Template:Code, or Template:Cd.

Template:Code
... Template:Text 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 Template:Code if specified.
... Template:Text anchor
Template:Code
Merge the NBT data from the target block position or entity with the specified Template:Code data.
... Template:Text anchor (block <targetPos>|entity <target>|storage <target>) <targetPath> ...
Template:Code
Template:Code
Template:Code
Append the source data or direct value data onto the end of the pointed-to list or array.
Template:Code
Template:Code
Template:Code
Insert the source data or direct value data into the pointed-to list or array as element Template:Code, then shift higher elements one position upward.
Template:Code
Template:Code
Template:Code
Merge the source data or direct value data into the pointed-to object.
Template:Code
Template:Code
Template:Code
Prepend the source data or direct value data onto the beginning of the pointed-to list or array.
Template:Code
Template:Code
Template:Code
Set the tag specified by Template:Code to the source data or direct value data.
... Template:Text anchor
Template:Code
Removes NBT data at Template:Code from the targeted block position or entity. Player NBT data cannot be removed.


Syntax displayed in various ways

Arguments

Template:Argument

The position of the target Minecraft:block entity whose NBT is to be operated on.
Template:Arg desc

Template:Argument (in Template:Cd mode)

Specifies an entity whose NBT is to be operated on.
Template:Arg desc

Template:Argument (in Template:Cd mode)

Specifies a storage to be operated on.
Template:Arg desc

Template:Argument

Specifies the NBT to retrieve or remove.
Template:Arg desc

Template:Argument

Scalar for the command's output value.
Template:Arg desc

Template:Argument

Specifies a compound tag to be merged into somewhere.
Template:Arg desc

Template:Argument

Specifies target NBT to modify.
Template:Arg desc

Template:Argument

Specifies an item's index within a list.
Template:Arg desc

Template:Argument

The position of the target Minecraft:block entity whose NBT is to be used.
Template:Arg desc

Template:Argument (in Template:Cd mode)

Specifies an entity whose NBT is to be used by Template:Code.
Template:Arg desc

Template:Argument (in Template:Cd mode)

Specifies a storage to be used by Template:Code.
Template:Arg desc

Template:Argument

Specifies the source NBT to be used by Template:Code.
Template:Arg desc

Template:Argument

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.
Template:Arg desc

Template:Argument

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.
Template:Arg desc

Template:Argument

Value used in modifying the target NBT.
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 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 Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table

Examples

  • To view the NBT data of the player's held item:
    Template:Code
  • To get the saturation level of the current player:
    Template:Code
  • To make the nearest item within 10 blocks unable to be picked up by players:
    Template:Code
  • To get the Y-position of a random item:
    Template:Code
  • 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:
    Template:Code
  • 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:
    Template:Code

List, array and string length

With Template:Cmd, 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 Template:Cmd, if necessary.

List example

Suppose a list is stored using the following command:

Template:Cmd

Then, running the following returns 6, the length of the list:

Template:Cmd
String example

Suppose a string is stored using the following command:

Template:Cmd

Then, running the following returns 43, the length of the string:

Template:Cmd

History

Template:HistoryTable

References

<references/>

Navigation

Template:Navbox commands

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