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 <scale> if specified.
: ... 
:: 
::: Merge the NBT data from the target block position or entity with the specified data.
: ... (block <targetPos>|entity <target>|storage <target>) <targetPath> ...
:: 
:: 
:: 
::: Append the source data or direct value data onto the end of the pointed-to list.
:: 
:: 
:: 
::: Insert the source data or direct value data into the pointed-to list as element , then shift higher elements one position upward.
:: 
:: 
:: 
::: Merge the source data or direct value data into the pointed-to object.
:: 
:: 
:: 
::: Prepend the source data or direct value data onto the beginning of the pointed-to list.
:: 
:: 
:: 
::: Set the tag specified by to the source data or direct value data.
: ... 
:: 
::: Removes NBT data at from the targeted block position or entity. Player NBT data cannot be removed.
Syntax displayed in various ways
:
Simplified tree:
: 
:* 
:* 
:* 
:** 
:** 
:** 
:* 
: where substituted arguments are:
:: = 
:: = 
:: =
:
Squished tree:
: 
:* 
:* 
:* 
:** 
:** 
:** 
:*
:
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.
: 
 (in mode)
: Specifies an entity whose NBT is to be used by .
: 
 (in mode)
: Specifies a storage to be used by .
: 
: Specifies the source NBT to be used by .
: 
: 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 the first character to exclude at the end of the string. Negative values are interpreted as index counted from the end of the string.
: 
: Value used in modifying the target NBT. Should match its data type.
: 
== Result ==
== Output ==
== 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:
*: /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:
*: 
* 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:
*: 
== 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 resource location to prevent unintentional conflicts.
 and can read from the storage, while , , , and can write to the storage.
A storage array can hold up to 2304 objects before maxing out.
The command storage is accessible with JSON text as well.
== History ==
== References ==
de:Befehl/data
es:Comandos/data
ja:コマンド/data
pt:Comandos/data
ru:Команды консоли/data
uk:Команди консолі/data
zh:命令/data