Minecraft 1.15 data command to edit entities [duplicate]
I have looked everywhere are the wiki is unusually hapless in this regard. I am trying to edit the data of a naturally-generated entity, for this example i will use a zombie.
/summon zombie ~ ~ ~ {HandItems:[{Count:1,id:iron_axe},{Count:1,id:iron_axe}],ArmorItems:[{},{},{},{Count:1,id:iron_helmet}],HandDropChances:[0.0f,0.0f],ArmorDropChances:[0.0f,0.0f,0.0f,0.0f]}
This command is simple enough to understand, but let's say I want all of the equipped items to be guaranteed drops (I instead want the items to drop upon the use of a specific item, but I doubt that's possible).
/data modify entity @e[type=minecraft:zombie,limit=1] ??? set value 1
Neither the wiki, nor anywhere else for that matter, goes into any detail whatsoever as to what I'm supposed to put there. I have tried a wide variety of variations on the {HandDropChances:[0.0f,0.0f]}
and it either comes back saying nothing has changed, or "Modified enttiy data of Zombie", without actually changing anything.
You should replace the ???
with a simple "path" of the value you want to change. For example to change the entire HandDropChances
value to [1f, 1f]
(which will guarantee drops from both hands), simply use
/data modify entity <entity> HandDropChances set value [1f, 1f]
The full path of the value we change is HandDropChances
as it's stored directly in the root object. To change a value that's stored in another object use dots as separators between parents and children elements (e.g the path of memories
object in the Brain
object will be Brain.memories
).
If you want to set the chances of the drops from the first hand only, you will need to add the array index of the HandDropChances
array in your path like this:
/data modify entity <entity> HandDropChances[0] set value 1f
Note that the first element of the array is 0
and not 1
.
/data merge
is also a decent alternative for the modify
command. It lets you simply merge a JSON element with the entity's JSON data. For example the following command will be an equivalent for the first modify
command I suggested:
/data merge entity <entity> {HandDropChances: [1f, 1f]}
That will add the HandDropChances
element if it's not present in the entity and will replace it otherwise.