Commands/data

The  command 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 , and the targets/sources referenced by each instruction command may be either  ,  , or.


 * 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 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 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 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 if specified.


 * Merge the NBT data from the sourced block position or entity with the specified  data.
 * Merge the NBT data from the sourced block position or entity with the specified  data.
 * Merge the NBT data from the sourced block position or entity with the specified  data.


 * Append the source data onto the end of the pointed-to list.
 * Insert the source data into the pointed-to list as element, then shift higher elements one position upwards.
 * Merge the source data into the pointed-to object.
 * Prepend the source data onto the beginning of the pointed-to list.
 * Set the tag specified by  to the source data.
 * Insert the source data into the pointed-to list as element, then shift higher elements one position upwards.
 * Merge the source data into the pointed-to object.
 * Prepend the source data onto the beginning of the pointed-to list.
 * Set the tag specified by  to the source data.
 * Merge the source data into the pointed-to object.
 * Prepend the source data onto the beginning of the pointed-to list.
 * Set the tag specified by  to the source data.
 * Prepend the source data onto the beginning of the pointed-to list.
 * Set the tag specified by  to the source data.
 * Set the tag specified by  to the source data.
 * Set the tag specified by  to the source data.


 * Removes NBT data at  from the targeted block position or entity. Player NBT data cannot be removed.
 * Removes NBT data at  from the targeted block position or entity. Player NBT data cannot be removed.
 * Removes NBT data at  from the targeted block position or entity. Player NBT data cannot be removed.

Syntax displayed in various ways
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"

! style="text-align:left" | Simplified tree:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:
 * where substituted arguments are:


 * }
 * {| class="collapsible collapsed collapse-button-none" data-description="squished_tree"

! style="text-align:left" | Squished tree:


 * }
 * {| class="collapsible collapsed collapse-button-none" data-description="tree_diagram"

! style="text-align:left" | Diagram:
 * }
 * {| class="collapsible collapsed collapse-button-none" data-description="one_line"

! style="text-align:left" | Maximised:


 * }

Arguments

 * The position of the target block entity whose NBT is to be operated on.

(in mode)
 * Specifies an entity whose NBT is to be operated on.

(in mode)
 * Specifies a storage to be operated on.


 * Specifies the NBT to retrieve or remove.


 * Scalar for the command's return value.


 * Specifies a compound tag to be merged into somewhere.


 * Specifies target NBT to modify.


 * Specifies an item's index within a list.


 * The position of the target block entity whose NBT is to be used.


 * Speciafies an entity whose NBT is to be used by.


 * Specifies a storage to be used by.


 * Specifies the source NBT to be used by.


 * Value used in modifying the target NBT. Should match its data type.

Examples

 * To get the saturation level of the current player:
 * To make the nearest item within 10 blocks unable to be picked up by players:
 * To get the Y-position of a random item:
 * To get the item ID of the item in the first hotbar slot of the nearest player:
 * To set the armor attribute of the dolphin closest to coordinates (0, 64, 0) to 20:
 * To change the first item in a chest located at coordinates (1, 64, 1) into a diamond block, keeping all NBT data:
 * To make the closest zombie drop the second item it is holding when it dies 80% of the time, but never the first:
 * /data merge entity @e[type=zombie,limit=1,sort=nearest] {HandDropChances: [0f, 0.8f]}
 * To make the nearest zombie drop the second item it is holding (the first in the array being 0) when it dies 80% of the time, without affecting the first:
 * /data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f
 * To change the first item in a chest located at coordinates (1, 64, 1) into a diamond block, keeping all NBT data:
 * To make the closest zombie drop the second item it is holding when it dies 80% of the time, but never the first:
 * /data merge entity @e[type=zombie,limit=1,sort=nearest] {HandDropChances: [0f, 0.8f]}
 * To make the nearest zombie drop the second item it is holding (the first in the array being 0) when it dies 80% of the time, without affecting the first:
 * /data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f
 * /data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f

Storage
The command storage of NBT data is an efficient way for commands to access or save NBT data without an overhead for block entities or entities reading from or writing to the NBT data.

Each command storage is a general purpose, key-value storage, identified by a namespaced ID to prevent unintentional conflicts.

and can read from the storage, while, , , and  can write to the storage.

The command storage is accessible with JSON text as well.