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.



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="complete_tree"

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


 * }
 * {| 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" | Minimised: /data (get (block |entity |storage ) [ ] [ ]|merge (block |entity |storage ) |modify (block |entity |storage ) (append|insert |merge|prepend|set) (from (block


 * }

Arguments

 * &#58;
 * —The  position of the target block entity whose NBT is to be operated on
 * —Valid a UUID, or a target selector variable for an entity whose NBT is to be operated on
 * —Valid namespaced ID for a storage to be operated on


 * &#58;
 * —Valid a NBT path defining the specific NBT to retrieve
 * —Scalar for the command's return value


 * &#58;
 * —Compound tag. The simplest valid input is.


 * &#58;
 * —Valid a NBT path defining the specific target NBT to modify
 * —Valid integer specifying an item's index within a list
 * &#58;
 * —The  position of the source block entity whose NBT is to be used
 * —Valid player name, UUID, or target selector variable of a source entity whose NBT is to be used
 * —Valid a NBT path defining the specific source NBT to be used by
 * &#58;
 * —Value to use in modifying the target NBT. Must match in data type


 * &#58;
 * —Valid a NBT path to the NBT to remove

Results
Fails if the arguments are not specified correctly.

On success:
 * Read off the entire NBT data from the targeted block position or entity to the executor with syntax highlighting.
 * If applicable, returns 1 on success.
 * Send the subsection of the NBT data from the targeted block position or entity to the executor without syntax highlighting.
 * Return value depends on the type of the NBT element:
 * Retrieving a number returns that number.
 * Retrieving a string returns the length of the string.
 * Retrieving a list returns the number of elements in that list.
 * Retrieving a compound returns the number of tags that are direct children of that compound.
 * Return the value of the tag, scaled by.
 * needs to specify a numeric tag—TAG_byte, TAG_short, TAG_int, TAG_long, TAG_float, or TAG_double.
 * Retrieving a compound returns the number of tags that are direct children of that compound.
 * Return the value of the tag, scaled by.
 * needs to specify a numeric tag—TAG_byte, TAG_short, TAG_int, TAG_long, TAG_float, or TAG_double.
 * needs to specify a numeric tag—TAG_byte, TAG_short, TAG_int, TAG_long, TAG_float, or TAG_double.


 * Merge the NBT data from the sourced block position or entity with the specified data.
 * If applicable, returns 1 on success.
 * If applicable, returns 1 on success.


 * Append the source data onto the end of the pointed-to list.
 * must specify a tag of the TAG_List, TAG_Byte_Array, TAG_Int_Array, or TAG_Long_Array type, and the source data should be of an item type appropriate for the list.
 * Insert the source data into the pointed-to list as element, then shift higher elements one position upwards.
 * must specify a tag of the TAG_List, TAG_Byte_Array, TAG_Int_Array, or TAG_Long_Array type, and the source data should be of an item type appropriate for the list.
 * Merge the source data into the pointed-to object.
 * Both  and source data must be of the TAG_compound type.
 * Prepend the source data onto the beginning of the pointed-to list.
 * must specify a tag of the TAG_List, TAG_Byte_Array, TAG_Int_Array, or TAG_Long_Array type, and the source data should be of an item type appropriate for the list.
 * Set the tag specified by  to the source data.
 * Both  and source data must be of the TAG_compound type.
 * Prepend the source data onto the beginning of the pointed-to list.
 * must specify a tag of the TAG_List, TAG_Byte_Array, TAG_Int_Array, or TAG_Long_Array type, and the source data should be of an item type appropriate for the 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.
 * If applicable, returns 1 on success.
 * If applicable, returns 1 on success.

Examples

 * To make all items 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 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 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:

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.

History
Befehl/data Команды консоли/data Команди консолі/data 命令/data