/data
/data| Permission level required |
2 |
|---|---|
| Restrictions |
None |
{
"title": "<code>/data</code>",
"rows": [
{
"field": "2",
"label": "(link to Permission level article, displayed as Permission level<br>required)"
},
{
"field": "None",
"label": "(link to Commands#Restrictions article, displayed as Restrictions)"
}
],
"invimages": [],
"images": []
}
Allows the user to get, merge, modify, and remove NBT data of a 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 storage <target>.
/data ...... get... (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
<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
... merge... (block <targetPos>|entity <target>|storage <target>) <nbt>- 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
... modify (block <targetPos>|entity <target>|storage <target>) <targetPath> ...... append from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... append string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... append value <value>- Append the source data or direct value data onto the end of the pointed-to list or array.
... insert <index> from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... insert <index> string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... 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
... merge from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... merge string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... merge value <value>- Merge the source data or direct value data into the pointed-to object.
... prepend from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... prepend string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... prepend value <value>- Prepend the source data or direct value data onto the beginning of the pointed-to list or array.
... set from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... set string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... set value <value>- Set the tag specified by
<targetPath>to the source data or direct value data.
- Set the tag specified by
... remove... (block <targetPos>|entity <target>|storage <target>) <path>- Removes NBT data at
<path>from the targeted block position or entity. Player NBT data cannot be removed.
- Removes NBT data at
Syntax displayed in various ways
Simplified tree: /data- where substituted arguments are:
<TARGET>=(block <targetPos> | entity <target> | storage <target>)<MODIFICATION>=(append|insert <index>|merge|prepend|set)<SOURCE>=(block <sourcePos> | entity <source> | storage <source>)
Squished tree: /data… get (block <targetPos>|entity <target>|storage <target>) [<path>] [<scale>]… merge (block <targetPos>|entity <target>|storage <target>) <nbt>… modify (block <targetPos>|entity <target>|storage <target>) <targetPath> (append|insert <index>|merge|prepend|set)… from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]… string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]… value <value>
… remove (block <targetPos>|entity <target>|storage <target>) <path>
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 block entity whose NBT is to be operated on.
- Must be a block position composed of
<X>,<Y>and<Z>, each of which must be an integer or a tilde and caret notation.
<target>: entity (in entity <target> mode)
- Specifies an entity whose NBT is to be operated on.
- Must be a player name, a target selector or a UUID. And the target selector must be in single type.
<target>: resource_location (in storage <target> mode)
- Specifies a storage to be operated on.
- Must be a resource location for an unregistered content.
<path>: nbt_path
- Specifies the NBT to retrieve or remove.
- Must be an NBT path.
<scale>: double
- Scalar for the command's output value.
- Must be a [Double]Double-precision floating-point number (from -(2-2-52)×21023 (≈-1.8×10308) to (2-2-52)×21023 (≈1.8×10308) ).
<nbt>: nbt_compound_tag
- Specifies a compound tag to be merged into somewhere.
- Must be a [NBT Compound / JSON Object] compound NBT in SNBT format.
<targetPath>: nbt_path
- Specifies target NBT to modify.
- Must be an NBT path.
<index>: integer
- Specifies an item's index within a list.
- Must be a [Int]32-bit integer number (from -2147483648 (-231) to 2147483647 (231-1) ).
<sourcePos>: block_pos
- The position of the target block entity whose NBT is to be used.
- Must be a block position composed of
<X>,<Y>and<Z>, each of which must be an integer or a tilde and caret notation.
<source>: entity (in entity <source> mode)
- Specifies an entity whose NBT is to be used by
modify. - Must be a player name, a target selector or a UUID. And the target selector must be in single type.
<source>: resource_location (in storage <source> mode)
- Specifies a storage to be used by
modify. - Must be a resource location for an unregistered content.
<sourcePath>: nbt_path
- Specifies the source NBT to be used by
modify. - Must be an NBT path.
<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.
- Must be a [Int]32-bit integer number (from -2147483648 (-231) to 2147483647 (231-1) ).
<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.
- Must be a [Int]32-bit integer number (from -2147483648 (-231) to 2147483647 (231-1) ).
<value>: nbt_tag
- Value used in modifying the target NBT.
- Must be an NBT tag of any type in SNBT format.
Result
| Command | Trigger | Java Edition |
|---|---|---|
| Any | The command is incomplete, or any argument is not specified correctly. | Unparseable |
<targetPos> is unloaded or out of the world. | Failed | |
The block at <targetPos> is not a block entity. | ||
<target> (in entity <target> mode) fails to resolve to a single entity (named player must be online). | ||
/data get ... | More than one tag is got. | |
/data get ... <path> | No tag exists at <path>. | |
/data get ... <path> <scale> | The obtained tag is not a numeric tag. | |
/data merge ... | Nothing is changed. | |
| Tries to edit a player's data. | ||
/data remove ... | <path> selects the root compound tag. | |
/data modify ... (from|string) block ... | <sourcePos> is unloaded or out of the world. | |
The block at <sourcePos> is not a block entity. | ||
/data modify ... (from|string) entity ... | <source> fails to resolve to a single entity (named player must be online). | |
/data modify ... (from|string) ... <sourcePath> | No tag exists at <sourcePath>. | |
/data modify ... string ... <sourcePath> <start> <end> | Any of the tags selected by <sourcePath> isn't string or numeric (will be converted to string) tag. | |
<start> or <end> is out of valid index of any of the source strings. | ||
For any of the source strings, the character indexed by <start> is behind of that indexed by <end>. | ||
/data modify ... append ... | Any of the target tags isn't a list or array tag. | |
| All of the source tags aren't of the appropriate type for all of the target lists or arrays. | ||
/data modify ... insert <index> ... | The index is invalid for all of the target lists or arrays. | |
/data modify ... merge ... | Any of the target tags is not a compound tag. | |
| Any of the source tags is not a compound tag. | ||
| Any | Otherwise | Successful |
Output
| Command | Edition | Situation | Success Count | /execute store success ... | /execute store result ... |
|---|---|---|---|---|---|
| Any | Java Edition | On fail | 0 | 0 | 0 |
/data get ... | On success | 1 | 1 | 1 | |
/data get ... <path> | A numeric tag is got | 1 | 1 | The obtained value after rounding down[1] | |
| A list or array tag is got | 1 | 1 | The number of elements in this list or array | ||
| A string tag is got | 1 | 1 | The length of the string | ||
| A compound tag is got | 1 | 1 | The number of tags that are direct children of that compound | ||
/data get ... <path> <scale> | On success | 1 | 1 | The obtained value multiplied by <scale>, then rounded down[2] | |
/data merge ... | On success | 1 | 1 | 1 | |
/data remove ... | On success | 1 | 1 | 1 | |
/data modify ... append ... | On success | 1 | 1 | The number of lists or arrays into which new elements are added | |
/data modify ... set ... | On success | 1 | 1 | The number of target tags that was successfully modified | |
/data modify ... merge ... | On success | 1 | 1 | The number of target compound tags that was successfully modified |
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 @e[type=item,distance=..10,limit=1,sort=nearest] PickupDelay set value -1
- 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 set the armor attribute of the dolphin closest to coordinates (0, 64, 0) to 20:
/data modify entity @e[x=0,y=64,z=0,type=dolphin,limit=1] Attributes[{Name:"minecraft:generic.armor"}].Base set value 20
- 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 @e[type=zombie,limit=1,sort=nearest] {HandDropChances: [0f, 0.8f]}
- To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, without affecting the chance for the main hand:
/data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f
List, array and string length
With /data get, 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 /execute store, if necessary.
- List example
Suppose a list is stored using the following command:
/data merge storage wiki:example {List:[2,5,8,9,6,10]}
Then, running the following returns 6, the length of the list:
/data get storage wiki:example List
- String example
Suppose a string is stored using the following command:
/data merge storage wiki:example {String:"Example string with a character count of 43"}
Then, running the following returns 43, the length of the string:
/data get storage wiki:example String
History
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.13 | 17w45b | Added /data. | |||||
| 17w47a | Commands /blockdata and /entitydata have been removed as their features are merged into /data. | ||||||
| 18w03a | Using /data get with a path now works on non-numeric values. | ||||||
| 1.14 | 18w43a | Added /data modify. | |||||
| 1.15 | 19w38a | Added storage <resource location> as a source or target. | |||||
| 1.19.4 | 23w03a | Added string source. | |||||
| 1.20 | Pre-release 1 | Now <start> or <end> in string source accept negative boundaries, which are interpreted as index counted from the end of the string. | |||||
| Pre-release 2 | Now invalid <start> or <end> in string source result in command failure instead of unhandaled error.[3] | ||||||
| 1.21.5 | 25w09a | Can now create and modify heterogeneous lists transparently. | |||||
| Can no longer traverse paths with an empty key. | |||||||
References
- ↑ double n = (double)value;
int output = n < (int)n ? (int)n - 1 :(int)n;
See also MC-259032 - ↑ double n = (double)value * scale;
int output = n < (int)n ? (int)n - 1 :(int)n;
See also MC-259032 - ↑ MC-260602 — /data modify from string index failure does not return 0 for /execute store success. — resolved as "Fixed".