I'm trying to make a cow farm in which cows in one pen are manually bred, and then the babies are moved to a separate pen to grow up and be killed. The original cow count would stay the same, and the extras would get killed. What I would like to do is teleport only the babies and leave the adults in the main pen so that I don't have to lure all the babies through the one block gap every time.
I know the command for tping types of mobs: /tp @e[type=cow] (location)
What I'm wondering is if there's an argument to specify the age of the mob I want to teleport.
Best Answer
Skip to the edit for the best solution if you don´t care about technical details, or previous solutions, the edit has the best solution
Cows (And many other mobs) have an NBT-tag called Age, when the cow is born this tag has a value of -24000 and the cow grows up when it reaches 0 and it stays at 0.
When cows breed their age is set to 6000 and it counts down until it reaches 0 again. Cows can not breed unless their age is 0.
There is no way to check if the
Age
-tag is lower than 0, you can only check for specific values. This means that you can´t teleport all baby cows and no grown up cows, unless you use 24000 commands, one for every possible age of a baby.You can however use this command to teleport any cow that was born that tick:
You can use this command to teleport all baby cows and all cows that can´t breed yet:
Alternatively you can tag all your grown up cows with
/tag @e[nbt={Age:0},type=cow] add grownUp
, before you breed them and then you teleport all cows that don´t have that tag:This command would work, but it is too long for a command block, so there is no way to execute it in the game:
The command length in command blocks is capped at 32767, this command would have a length of about 180000.
Edit:
Set up a scoreboard objective:
Then you run this command in a repeating command block. It will set the score of every cow to whatever value the
Age
-tag currently has. (It would be enough to run this command once right before you want to teleport the babies, maybe in an impulse command block that triggers a chain command block with the/tp
command from further down)After using that command you can teleport all baby cows with this command, it teleports every cow with a
cowAge
-score of -1, or lower: