Updated:
Read data (data get)
| Goal | Command |
|---|---|
| Your position | /data get entity @s Pos |
| Health of the nearest zombie | /data get entity @e[type=minecraft:zombie,limit=1,sort=nearest] Health |
| The item in your hand | /data get entity @s SelectedItem |
| Chest contents | /data get block 100 64 100 Items |
Leave out the last name to print everything. The output is long, so asking for one field is easier to read.
Change data (data merge)
/data merge entity @e[type=minecraft:villager,limit=1,sort=nearest] {NoAI:1b,Invulnerable:1b}
This makes the nearest villager stand still and take no damage. Only the fields inside { } change; everything else stays.
| Field | Effect |
|---|---|
NoAI:1b | Does not move or attack |
Invulnerable:1b | Takes no damage |
Silent:1b | Makes no sounds |
PersistenceRequired:1b | Does not despawn |
Glowing:1b | Outline visible through walls |
To undo, merge the same field with 0b.
Copy values (data modify)
/data modify entity @e[type=minecraft:armor_stand,limit=1,sort=nearest] HandItems[0] set from entity @s SelectedItem
This copies the item in your hand to the nearest armor stand's hand (1.21.4 and earlier). From 1.21.5, mob gear lives in equipment, so the path is equipment.mainhand. Use set value … to write a value directly.
Put a value into a scoreboard
/scoreboard objectives add hp dummy
/execute store result score @s hp run data get entity @s Health 1
execute store saves the number that data get returns into a score, which you can then show in the sidebar or compare with execute if score. The last number is a scale: Health is a decimal such as 17.5, so use 10 instead of 1 to keep one decimal place (175).
Remove a tag (data remove)
/data remove entity @e[type=minecraft:villager,limit=1,sort=nearest] CustomName
This deletes the name from the nearest villager. data remove works on any field you could set with merge or modify.
Keep values in storage
/data modify storage mypack:temp round set value 1
/data get storage mypack:temp round
Storage is a place to keep data that does not belong to any entity or block. It is saved with the world, which makes it useful for datapack settings and counters. The name before the colon is your own namespace.
Players cannot be edited
/data get works on players, but merge and modify do not. To change players use dedicated commands such as /attribute, /item and /effect.
Common problems
- Too many targets: add
limit=1. /data handles one target at a time. - The change reverts: it does not work on players, and some mob fields are rewritten every tick.
- Unknown field name: print all data with
/data getfirst and copy the name. Names can change between versions. - Bedrock Edition: there is no /data.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.