Minecraft – Would someone give an explanation of how to modify the data of a fox

minecraft-commandsminecraft-java-edition

Using Minecraft 1.14, I would like to use the /data command to change a baby fox's age. There are three other foxes in the world, and I would not like any of them changed or modified. I've been trying to figure this out for a while, and the closest I've gotten is:

/data merge entity @e[type=fox,limit=1,nbt={Age:-1}] {Age:1}

however that doesn't seek to work. It says on the wiki that when a fox is a baby, its age is negative, but when it's an adult, it's age is 0 or above. I tried to implement this, but I'm not sure exactly how to figure it out in detail. Can someone explain?

Best Answer

The Age tag represents how many ticks the mob has until it grows up (if it's a baby) or how many ticks until it can breed (if it's an adult). Therefore, baby foxes can have any less than 0, not just -1.

As you cannot directly check if an NBT tag is greater/less than a value, you need to store the Age in a scoreboard first:

/scoreboard objectives add age dummy
/execute as @e[type=fox] run store result score @s age run data get entity @s Age

Then you can select the first fox with an age ≤ -1:

execute as @e[type=fox,limit=1,scores={age=..-1}] run data merge entity @s {Age:1}