Commands/data

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

Command Details

 * Syntax

There are four instructions for , and the targets/sources referenced by each instruction command may be either   or  , so describing syntax takes a largely branching tree, organized here in several ways:


 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"
 * {| 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" | On one line: /data (get (block |entity ) [ ] [ ]|merge (block |entity ) |modify (block |entity ) (append|insert |merge|prepend|set) (from (block &#58;
 * &mdash;The  position of the target tile entity whose NBT is to be operated on
 * &mdash;Valid UUID, or target selector variable for an entity whose NBT is to be operated on


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


 * &#58;
 * &mdash;Compound tag. The simplest valid imput is.


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


 * &#58;
 * &mdash;Valid path name to the NBT to remove


 * See below: 


 * Results


 * Command 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.
 * 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.
 * Requires a numeric value to be at the end of the path&mdash;Return that numeric value, scaled by .
 * Requires a numeric value to be at the end of the path&mdash;Return that numeric value, scaled by .
 * Requires a numeric value to be at the end of the path&mdash;Return that numeric value, scaled by .


 * Merges 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 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 type, and the source data should be of an item type appropriate for the list.
 * Merge the source data with the pointed-to object.
 * must specify a tag of the TAG_list type, 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 type, and the source data should be of an item type appropriate for the list.
 * Set the tag specified by  to the source data.
 * must specify a tag of the TAG_list type, 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 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.

What is an NBT path?
An NBT data path is a descriptive label used to specify any particular element from an NBT data tree. A path has the general form, where   is the specified tag and   is one of the most superficial tags.

When defining an element from a list, brackets are used after the key of the list. The content of the brackets can be one of 3 things:


 * Blank space&mdash;This returns every element in the list.
 * An index number&mdash;For a nonnegative index n, this returns the (n + 1)th element in the list. For a negative index n, this returns the nth element from the end of the list.
 * An NBT compound. This returns all objects in the list that match the specifications of that compound.

The valid character set for a path seems to be all non-whitespace characters, as long as any opening brackets and braces ( and  ) are closed and at the end of each term (that is, followed by nothing but a period or the end of the path&mdash;  or  ). That being said, the reasonable character set for defining a data tag would be:  (To put this as a,  ) "Quoted strings" may be used if a name of a key needs to be escaped.

Fubar example:
These names have been arbitrarily picked, for demonstrative purposes.
 * &mdash;Specifies the top-level element named "foo"
 * &mdash;Specifies foo's child named "bar". Let's pretend this is a list.
 * &mdash;Specifies the 0th element of the list bar
 * &mdash;Specifies the child named "A [crazy name]!" under the that 0th element
 * &mdash;Specifies the child named "baz" under the that crazily named element

Book-in-a-chest example:
The player has written a book and placed it inside a chest at her feet. She's going to work up to the above command in stages.


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

! style="text-align:left" | Chat log * Alex jumps on top of a chest. * Alex runs the command: /data get block ~ ~ ~ 0 55 0 has the following block data: {{{TAG_number|x|0}},, , Items : [{{{TAG_number|Slot|0|b}}, , }, {{{TAG_number|Slot|9|b}}, , , tag : { pages : [ '{"text":"\'twas brillig and the slithy toves"}' , '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , }}], } ''* Alex only wants to look at the chest's inventory. She could search the Official Minecraft Wiki for what the name of that tag is, but because she understands how to read NBT format, she decides to figure it out from that last command's output.'' * Alex runs the command: /data get block ~ ~ ~ Items 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{{{TAG_number|Slot|0|b}},, }, {{{TAG_number|Slot|9|b}}, , , tag : { pages : [ '{"text":"\'twas brillig and the slithy toves"}' , '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , }}] , id: "chest"} ''* Alex wants to narrow this down to the second item in the chest. She starts counting from 0, so the second item would be element 1.'' * Alex runs the command: /data get block ~ ~ ~ Items[1] 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {{{TAG_number|Slot|9|b}},, , tag : { pages : [ '{"text":"\'twas brillig and the slithy toves"}' , '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , }} ], id: "chest"} * Alex wants just the "tag" tag. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: { pages : [ '{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , } }], id: "chest"} * Alex wants just the "pages" tag. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag.pages 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: [ '{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ] , author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} * Alex wants just the fourth element from this list. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag.pages[3]  0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}', '{"text":"And the mome raths outgrabe."}' ], author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} ''* Alex has what she needs now... She uses the paths she's gathered to edit the book from outside the chest.'' ''* Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.pages[3] set value '{"text":"And this pig here\'s named Babe."}' Modified block data of 0 55 0 ''* Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.pages prepend value '{"text":"Call me Ishmael."}' Modified block data of 0 55 0 ''* Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.author set value "Cthulhu the Sleeper"
 * }

History
命令/data