Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/data

From SAS Gaming Wiki
Revision as of 21:30, 13 March 2026 by imported>LauraFii (Revert edits by ~2026-DiamondGolemMeadow5739 (talk))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

File:Data graph.svg
A graph that describes the syntax of this command.

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:Text anchor
Template:Code
Merge the NBT data from the target block position or entity with the specified Template:Code data.
... 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.


Syntax displayed in various ways

Arguments

Template:Argument

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

Template:Argument

Specifies the NBT to retrieve or remove.
Template:Arg desc

Template:Argument

Scalar for the command's output value.
Template:Arg desc

Template:Argument

Specifies a compound tag to be merged into somewhere.
Template:Arg desc

Template:Argument

Specifies target NBT to modify.
Template:Arg desc

Template:Argument

Specifies an item's index within a list.
Template:Arg desc

Template:Argument

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

Template:Argument

Specifies the source NBT to be used by Template:Code.
Template:Arg desc

Template:Argument

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

Template:Argument

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

Template:Argument

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:
    Template:Code
  • To get the saturation level of the current player:
    Template:Code
  • To make the nearest item within 10 blocks unable to be picked up by players:
    Template:Code
  • To get the Y-position of a random item:
    Template:Code
  • 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:
    Template:Code
  • 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:
    Template:Code

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:

Template:Cmd

Then, running the following returns 6, the length of the list:

Template:Cmd
String example

Suppose a string is stored using the following command:

Template:Cmd

Then, running the following returns 43, the length of the string:

Template:Cmd

History

Template:HistoryTable

References

<references/>

Navigation

Template:Navbox commands

Minecraft:de:Befehl/data Minecraft:es:Comandos/data Minecraft:ja:コマンド/data Minecraft:pt:Comandos/data Minecraft:ru:Команды консоли/data Minecraft:uk:Команди консолі/data Minecraft:zh:命令/data