0

My goal is to place a command block at spawn that checks the age of every name-tagged mob. If the age of the entity is less than zero, then the command block sets the age to -999999999.

This should allow all animals, mobs, villagers, etc. which are name-tagged as babies to remain babies. All non-named entities should age normally.

I only have a very basic understanding of minecraft coding, so even though I've been researching and testing for about three hours, I haven't gotten very far.

I've tried naming an adult wolf Child and running this command to turn it into a child.

execute as @e[name='Child'] run data merge entity @s {age:-9999999}

Minecraft says that the date merge was successful, but I'm not seeing any change. The adult wolf remains an adult. (I've also tried to change a baby wolf into an adult using this same command without success.)

Since I'm unable to complete the first step, I'm not certain what the final command should look like. Could someone please help me understand how to write the final command. As explained earlier, I want to identify all name-tagged entities with an age lower than zero and then set their age to -9999999.

2 Answers 2

2

The reason why the command in your original post is not working is because NBT tags are case-sensitive, and you did not respect the casing of the Age tag.

You should have used {Age:-9999999}, not {age:-9999999}.

This is a very simple issue that is easily preventable. In the future, always check the Minecraft Wiki which displays a list of NBT tags with the correct capitalizations. You can also run /data get entity @e[type=wolf,limit=1,sort=nearest] to print off the data of the nearest entity (in this case, the nearest wolf).

You can also experiment with command generators like MCStacker. If you do it this way, I would recommend using their /summon generator to try what happens when you set a mob's age, and copy and paste the NBT into your own command.

1
  • Thank you so much! The original command is now working. I feel so silly that I struggled with that for so long. I definitely appreciate you pointing me in the right direction. I'm testing out MCStacker right now--and it is very useful! I'm still not certain how to select all named entities, but I'm doing some testing on MCStacker to see what I can come up with.
    – Megan
    Oct 30, 2022 at 22:15
2

I figured out a way to do this for my survival players and their pets!

From a player standpoint, it is very simple. A player uses a name tag to name an animal “Child.” This animal will now remain a child--even if it is renamed using a new name tag. If the player decides that they would like their animal to grow up, then they can use a name tag to name the animal “Adult.” The animal will now age normally until it becomes an adult--even if it is renamed using a new name tag.

Here is how to achieve this result:

Create two separate command blocks at spawn that are set to repeat, unconditional, always active. Here are the commands for each command block:

/tag @e[name='Child'] add child
/tag @e[name='Adult'] remove child

These command blocks search for any entities with the name “Child” or “Adult.” If an entity is named “Child” then the child tag is applied. If an entity is named “Adult” then the child tag is removed.

Create another command block at spawn that is set to repeat, unconditional, always active. Here is the command for that command block:

/execute as @e[tag=child] run data merge entity @s {Age:-24000}

This command block will check for any entity with the child tag and set the age to -24000. The entity will remain a child until the child tag is removed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .