The Gamepedia and Fandom account systems have now been merged. If your username is incorrect, you have accounts on both platforms that weren't merged, or you have trouble signing in, please submit a support ticket.

Commands/data

From Minecraft Wiki
< Commands(Redirected from Command storage)
Jump to: navigation, search
data
Restrictions

Operator

First introduced

Java Edition 1.13 (17w45a)

Information icon.svg
This feature is exclusive to Java Edition.

The /data command allows the user to get, merge, modify, and remove NBT data of a block entity, entity, or Command NBT storage.

Syntax[edit]

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> [<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|insert <index>|merge|prepend|set) from block <sourcePos> <sourcePath>
data modify block <targetPos> <targetPath> (append|insert <index>|merge|prepend|set) from entity <source> <sourcePath>
data modify block <targetPos> <targetPath> (append|insert <index>|merge|prepend|set) from storage <source> <sourcePath>
data modify block <targetPos> <targetPath> (append|insert <index>|merge|prepend|set) value <nbt>
data modify entity <target> <targetPath> (append|insert <index>|merge|prepend|set) from block <sourcePos> <sourcePath>
data modify entity <target> <targetPath> (append|insert <index>|merge|prepend|set) from entity <source> <sourcePath>
data modify entity <target> <targetPath> (append|insert <index>|merge|prepend|set) from storage <source> <sourcePath>
data modify entity <target> <targetPath> (append|insert <index>|merge|prepend|set) value <value>
data modify storage <target> <targetPath> (append|insert <index>|merge|prepend|set) from block <sourcePos> <sourcePath>
data modify storage <target> <targetPath> (append|insert <index>|merge|prepend|set) from entity <source> <sourcePath>
data modify storage <target> <targetPath> (append|insert <index>|merge|prepend|set) from storage <source> <sourcePath>
data modify storage <target> <targetPath> (append|insert <index>|merge|prepend|set) value <value>
data remove block <targetPos> <path>
data remove entity <target> <path>
data remove storage <target> <path>

Syntax displayed in various ways

Arguments[edit]

(block <targetPos>|entity <target>|storage <target>)
  • <targetPos>—The <x> <y> <z> position of the target block entity whose NBT is to be operated on
  • <target>—Valid a UUID, or a target selector variable for an entity whose NBT is to be operated on
  • <target>—Valid namespaced ID for a storage to be operated on
get ... [<path>] [<scale>]
  • <path>—Valid a NBT path defining the specific NBT to retrieve
  • <scale>—Scalar for the command's return value
merge ... <nbt>
  • <nbt>—Compound tag. The simplest valid input is {}.
modify ... <targetPath> (append|insert <index>|merge|prepend|set)
  • <targetPath>—Valid a NBT path defining the specific target NBT to modify
  • <index>—Valid integer specifying an item's index within a list
… from (block <sourcePos>|entity <sourceEntity>|storage <sourceStorage>) <sourcePath>:
  • <sourcePos>—The <x> <y> <z> position of the source block entity whose NBT is to be used
  • <sourceEntity>—Valid player name, UUID, or target selector variable of a source entity whose NBT is to be used
  • <sourceStorage>—Valid storage namespace whose NBT is to be used
  • <sourcePath>—Valid a NBT path defining the specific source NBT to be used by modify
… value <value>:
  • <value>—Value to use in modifying the target NBT. Must match in data type
remove ... <path>
  • <path>—Valid a NBT path to the NBT to remove

Results[edit]

Fails if the arguments are not specified correctly.

On success:

/data get
/data get ...
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.
/data get ... <path>
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.
/data get ... <path> <scale>
Return the value of the tag, scaled by <scale>.
<path> needs to specify a numeric tag—TAG_byte, TAG_short, TAG_int, TAG_long, TAG_float, or TAG_double.
/data merge
Merge the NBT data from the sourced block position or entity with the specified <nbt> data.
If applicable, returns 1 on success.
/data modify
append
Append the source data onto the end of the pointed-to list.
<targetPath> 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 <index>
Insert the source data into the pointed-to list as element <index>, then shift higher elements one position upwards.
<targetPath> 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
Merge the source data into the pointed-to object.
Both <targetPath> and source data must be of the TAG_compound type.
prepend
Prepend the source data onto the beginning of the pointed-to list.
<targetPath> 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
Set the tag specified by <targetPath> to the source data.
/data remove
Removes NBT data at <path> from the targeted block position or entity. Player NBT data cannot be removed.
If applicable, returns 1 on success.

NBT path[edit]

Examples[edit]

  • To make all items within 10 blocks unable to be picked up by players:
    /data modify entity @e[type=item,distance=..10] 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:"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"

Storage[edit]

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.

/data get and /data modify can read from the storage, while /data merge, /data modify, /data remove, and /execute store can write to the storage.

The command storage is accessible with JSON text as well.

History[edit]

Java Edition
1.1317w45bAdded /data.
17w47aCommands /blockdata and /entitydata have been removed as their features are merged into /data.
18w03aUsing /data get with a path now works on non-numeric values.
1.1418w43aAdded /data modify.
1.1519w38aAdded command storage.
Added storage <namespaced ID> as a source or target.
19w39aAdded NBT storage chat component.

Trivia[edit]

  • Players can get the message "The target is not a block entity" when trying to lock a chest while standing directly above. The reason for this is because the chest is not fully 1 block and can cause wrong altitude-reading, due to the altitude was indicate as the player's foot level. To solve this problem, simply plus 1 unit into the Y value when trying to targeting the chest from above.