Minecraft:Commands/data
More actions
Template:Distinguish Template:Exclusive Template:Infobox command
Allows the user to get, merge, modify, and remove NBT data of a Minecraft:block entity, Minecraft:entity, or Command NBT storage.
Syntax
There are four instructions for Template:Code (Template:Code, Template:Code, Template:Code, Template:Code), and the targets/sources referenced by each instruction command may be either Template:Code, Template:Code, or Template:Cd.
- Template:Code
... Template:Text 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 Template:Code if specified.
- Template:Code
... Template:Text anchor- Template:Code
- Merge the NBT data from the target block position or entity with the specified Template:Code data.
- Template:Code
... Template:Text anchor (block <targetPos>|entity <target>|storage <target>) <targetPath> ...- Template:Code
- Template:Code
- Template:Code
- Append the source data or direct value data onto the end of the pointed-to list or array.
- Template:Code
- Template:Code
- Template:Code
- Insert the source data or direct value data into the pointed-to list or array as element Template:Code, then shift higher elements one position upward.
- Template:Code
- Template:Code
- Template:Code
- Merge the source data or direct value data into the pointed-to object.
- Template:Code
- Template:Code
- Template:Code
- Prepend the source data or direct value data onto the beginning of the pointed-to list or array.
- Template:Code
- Template:Code
- Template:Code
- Set the tag specified by Template:Code to the source data or direct value data.
... Template:Text anchor- Template:Code
- Removes NBT data at Template:Code from the targeted block position or entity. Player NBT data cannot be removed.
- Template:Code
Syntax displayed in various ways
Simplified tree: - Template:Code
- where substituted arguments are:
Squished tree:
Arguments
- The position of the target Minecraft:block entity whose NBT is to be operated on.
- Template:Arg desc
Template:Argument (in Template:Cd mode)
- Specifies an entity whose NBT is to be operated on.
- Template:Arg desc
Template:Argument (in Template:Cd mode)
- Specifies a storage to be operated on.
- Template:Arg desc
- Specifies the NBT to retrieve or remove.
- Template:Arg desc
- Scalar for the command's output value.
- Template:Arg desc
- Specifies a compound tag to be merged into somewhere.
- Template:Arg desc
- Specifies target NBT to modify.
- Template:Arg desc
- Specifies an item's index within a list.
- Template:Arg desc
- The position of the target Minecraft:block entity whose NBT is to be used.
- Template:Arg desc
Template:Argument (in Template:Cd mode)
- Specifies an entity whose NBT is to be used by Template:Code.
- Template:Arg desc
Template:Argument (in Template:Cd mode)
- Specifies a storage to be used by Template:Code.
- Template:Arg desc
- Specifies the source NBT to be used by Template:Code.
- Template:Arg desc
- 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.
- Template:Arg desc
- 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.
- Template:Arg desc
- Value used in modifying the target NBT.
- Template:Arg desc
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
Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table
Examples
- To view the NBT data of the player's held item:
- 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 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 @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:
List, array and string length
With Template:Cmd, 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 Template:Cmd, if necessary.
- List example
Suppose a list is stored using the following command:
Then, running the following returns 6, the length of the list:
- String example
Suppose a string is stored using the following command:
Then, running the following returns 43, the length of the string:
History
References
<references/>
Minecraft:de:Befehl/data Minecraft:es:Comandos/data Minecraft:ja:コマンド/data Minecraft:pt:Comandos/data Minecraft:ru:Команды консоли/data Minecraft:uk:Команди консолі/data Minecraft:zh:命令/data