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:
/tp @e[nbt={Age:-24000},type=cow] <destination>
You can use this command to teleport all baby cows and all cows that can´t breed yet:
/tp @e[nbt=!{Age:0},type=cow] <destination>
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:
/tp @e[type=cow,tag=!grownUp] <destination>
This command would work, but it is too long for a command block, so there is no way to execute it in the game:
/execute as @e[type=cow] unless data entity @s {Age:0} unless data entity @s {Age:1} unless data entity @s {Age:2} <continue this for a while> unless data entity @s {Age:5999} unless data entity @s {Age:6000} run tp <destination>
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:
/scoreboard objectives add cowAge dummy
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)
/execute as @e[type=cow] store result score @s cowAge run data get entity @s Age 1
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:
/tp @e[type=cow,scores={cowAge=..-1}] <destination>
/execute at @e run summon cow
and you have all the cows you would ever need.