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 target block position or entity with the specified  data.
 * Merge the NBT data from the target block position or entity with the specified  data.
 * Merge the NBT data from the target 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="maximised_tree"

! 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 nearest zombie have a 80% chance to drop items in its left hand when it dies, and never drop that in the main hand:
 * To make the nearest zombie have a 80% chance to drop items in its left hand when it dies, and never drop that in its main hand, without affecting the chance for main hand:
 * 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 nearest zombie have a 80% chance to drop items in its left hand when it dies, and never drop that in the main hand:
 * To make the nearest zombie have a 80% chance to drop items in its left hand when it dies, and never drop that in its main hand, without affecting the chance for main hand:
 * To make the nearest zombie have a 80% chance to drop items in its left hand when it dies, and never drop that in the main hand:
 * To make the nearest zombie have a 80% chance to drop items in its left hand when it dies, and never drop that in its main hand, without affecting the chance for main hand:
 * To make the nearest zombie have a 80% chance to drop items in its left hand when it dies, and never drop that in its main hand, without affecting the chance for main hand:

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.