Minecraft:Commands/data
More actions
Template:Hatnote Script error: No such module "Exclusive". Template:Infobox command
Allows the user to get, merge, modify, and remove NBT data of a Minecraft:block entity, entity, or Command NBT storage.
Syntax
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
- REDIRECT Template:Code
/data ......
REDIRECT Template:Visible anchor
- Template:Code
- 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.
- 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
- Template:Code
...
REDIRECT Template:Visible anchor
- Template:Code
- Merge the NBT data from the target block position or entity with the specified
<nbt>data.
- Merge the NBT data from the target block position or entity with the specified
- Template:Code
...
REDIRECT Template:Visible anchor (block <targetPos>|entity <target>|storage <target>) <targetPath> ...
- Template:Code
- Template:Code
... append value <value>- Append the source data or direct value data onto the end of the pointed-to list or array.
- Template:Code
- Template:Code
... insert <index> value <value>- Insert the source data or direct value data into the pointed-to list or array as element
<index>, then shift higher elements one position upward.
- Insert the source data or direct value data into the pointed-to list or array as element
- Template:Code
- Template:Code
... merge value <value>- Merge the source data or direct value data into the pointed-to object.
- Template:Code
- Template:Code
... prepend value <value>- Prepend the source data or direct value data onto the beginning of the pointed-to list or array.
- Template:Code
- Template:Code
... set value <value>- Set the tag specified by
<targetPath>to the source data or direct value data.
- Set the tag specified by
...
REDIRECT Template:Visible anchor
- Template:Code
- Removes NBT data at
<path>from the targeted block position or entity. Player NBT data cannot be removed.
- Removes NBT data at
- Template:Code
Syntax displayed in various ways
Simplified tree: /data- where substituted arguments are:
<TARGET>= Template:Code<MODIFICATION>= Template:Code<SOURCE>= Template:Code
Squished tree: /data- Template:Code
- Template:Code
- Template:Code
- Template:Code
- Template:Code
… value <value>
- Template:Code
Maximised: 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 from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> append from entity <source> <sourcePath>data modify block <targetPos> <targetPath> append from storage <source> <sourcePath>data modify block <targetPos> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> append string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> append string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> append value <value>data modify block <targetPos> <targetPath> insert <index> from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> insert <index> from entity <source> <sourcePath>data modify block <targetPos> <targetPath> insert <index> from storage <source> <sourcePath>data modify block <targetPos> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> insert <index> value <value>data modify block <targetPos> <targetPath> merge from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> merge from entity <source> <sourcePath>data modify block <targetPos> <targetPath> merge from storage <source> <sourcePath>data modify block <targetPos> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> merge string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> merge string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> merge value <value>data modify block <targetPos> <targetPath> prepend from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> prepend from entity <source> <sourcePath>data modify block <targetPos> <targetPath> prepend from storage <source> <sourcePath>data modify block <targetPos> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> prepend string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> prepend string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> prepend value <value>data modify block <targetPos> <targetPath> set from block <sourcePos> <sourcePath>data modify block <targetPos> <targetPath> set from entity <source> <sourcePath>data modify block <targetPos> <targetPath> set from storage <source> <sourcePath>data modify block <targetPos> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> set string entity <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> set string storage <source> <sourcePath> <start> <end>data modify block <targetPos> <targetPath> set value <value>data modify entity <target> <targetPath> append from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> append from entity <source> <sourcePath>data modify entity <target> <targetPath> append from storage <source> <sourcePath>data modify entity <target> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> append string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> append string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> append value <value>data modify entity <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> insert <index> from entity <source> <sourcePath>data modify entity <target> <targetPath> insert <index> from storage <source> <sourcePath>data modify entity <target> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> insert <index> value <value>data modify entity <target> <targetPath> merge from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> merge from entity <source> <sourcePath>data modify entity <target> <targetPath> merge from storage <source> <sourcePath>data modify entity <target> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> merge string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> merge value <value>data modify entity <target> <targetPath> prepend from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> prepend from entity <source> <sourcePath>data modify entity <target> <targetPath> prepend from storage <source> <sourcePath>data modify entity <target> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> prepend string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> prepend value <value>data modify entity <target> <targetPath> set from block <sourcePos> <sourcePath>data modify entity <target> <targetPath> set from entity <source> <sourcePath>data modify entity <target> <targetPath> set from storage <source> <sourcePath>data modify entity <target> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>data modify entity <target> <targetPath> set string entity <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> set string storage <source> <sourcePath> <start> <end>data modify entity <target> <targetPath> set value <value>data modify storage <target> <targetPath> append from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> append from entity <source> <sourcePath>data modify storage <target> <targetPath> append from storage <source> <sourcePath>data modify storage <target> <targetPath> append string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> append string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> append string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> append value <value>data modify storage <target> <targetPath> insert <index> from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> insert <index> from entity <source> <sourcePath>data modify storage <target> <targetPath> insert <index> from storage <source> <sourcePath>data modify storage <target> <targetPath> insert <index> string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> insert <index> string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> insert <index> string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> insert <index> value <value>data modify storage <target> <targetPath> merge from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> merge from entity <source> <sourcePath>data modify storage <target> <targetPath> merge from storage <source> <sourcePath>data modify storage <target> <targetPath> merge string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> merge string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> merge string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> merge value <value>data modify storage <target> <targetPath> prepend from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> prepend from entity <source> <sourcePath>data modify storage <target> <targetPath> prepend from storage <source> <sourcePath>data modify storage <target> <targetPath> prepend string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> prepend string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> prepend string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> prepend value <value>data modify storage <target> <targetPath> set from block <sourcePos> <sourcePath>data modify storage <target> <targetPath> set from entity <source> <sourcePath>data modify storage <target> <targetPath> set from storage <source> <sourcePath>data modify storage <target> <targetPath> set string block <sourcePos> <sourcePath> <start> <end>data modify storage <target> <targetPath> set string entity <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> set string storage <source> <sourcePath> <start> <end>data modify storage <target> <targetPath> set value <value>data remove block <targetPos> <path>data remove entity <target> <path>data remove storage <target> <path>
Arguments
<targetPos>: block_pos
- The position of the target Minecraft:block entity whose NBT is to be operated on.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<target>: entity (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies an entity whose NBT is to be operated on.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<target>: resource_location (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies a storage to be operated on.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<path>: nbt_path
- Specifies the NBT to retrieve or remove.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<scale>: double
- Scalar for the command's output value.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|double}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<nbt>: nbt_compound_tag
- Specifies a compound tag to be merged into somewhere.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_compound_tag}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<targetPath>: nbt_path
- Specifies target NBT to modify.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<index>: integer
- Specifies an item's index within a list.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<sourcePos>: block_pos
- The position of the target Minecraft:block entity whose NBT is to be used.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<source>: entity (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies an entity whose NBT is to be used by
modify. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<source>: resource_location (in
- REDIRECT Template:Code
Template:Redr mode)
- Specifies a storage to be used by
modify. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<sourcePath>: nbt_path
- Specifies the source NBT to be used by
modify. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<start>: integer
- 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.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<end>: integer
- 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.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<value>: nbt_tag
- Value used in modifying the target NBT.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_tag}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table
Output
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|je}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|1}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data get ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
Template:Output table
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|A list or array tag is got}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of elements in this list or array}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|A string tag is got}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The length of the string}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|A compound tag is got}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of tags that are direct children of that compound}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
Template:Output table
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|1}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data merge ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|1}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data remove ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of lists or arrays into which new elements are added}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data modify ... append ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of target tags that was successfully modified}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|
/data modify ... insert <index> ...
/data modify ... prepend .../data modify ... set ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|The number of target compound tags that was successfully modified}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/data modify ... merge ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
Examples
- To view the NBT data of the player's held item:
/data get entity @s SelectedItem
- To get the saturation level of the current player:
/data get entity @s foodSaturationLevel
- To make the nearest item within 10 blocks unable to be picked up by players:
/data modify entity @n[type=item,distance=..10] PickupDelay set value -1s
- 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 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"
- 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 @n[type=zombie] {drop_chances:{mainhand:0f,offhand:0.8f}}
- To make the nearest zombie have an 80% chance to drop items in its off-hand when it dies, without affecting the chance for the main hand:
/data modify entity @n[type=zombie] drop_chances.offhand set value 0.8f
List, array and string length
With
- REDIRECT Template:Command
Template:Redr, it is possible to get the length of lists or arrays and the number of characters in strings, since its return value is the length of the string, list, or arrays being referenced. This value can then be stored using
- REDIRECT Template:Command
Template:Redr, if necessary.
- List example
Suppose a list is stored using the following command:
Then, running the following returns 6, the length of the list:
- REDIRECT Template:Command
- String example
Suppose a string is stored using the following command:
Then, running the following returns 43, the length of the string:
- REDIRECT Template:Command
History
References
<references/>
de:Befehl/data es:Comandos/data ja:コマンド/data pt:Comandos/data ru:Команды консоли/data uk:Команди консолі/data zh:命令/data