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.

  • Why do you build farms if you use commands? Just do /execute at @e run summon cow and you have all the cows you would ever need. Jun 11 '19 at 19:51
  • Or give yourself a cow spawner that has the max spawned mobs set to your original cow count.
    – MBraedley
    Jun 11 '19 at 20:13
  • mostly i want to know if it's possible. But also it's like a kind of cheat survival word? if that makes sense? Like, i'm not gonna spawn infinite cows but also it would be nice to just real quick tp all the babies away from their parents so i don't have to cart them all around
    – taybugb
    Jun 11 '19 at 20:38

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.


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>
  • This should work, but it may require some more testing, please comment if there is a problem.
    – user232393
    Jun 11 '19 at 20:45
  • This works! Although be careful because it gets them all if the a in age is not capitalized. Thank you very much
    – taybugb
    Jun 11 '19 at 21:14
  • With "may need some testing" I basically meant that I´m not 100% sure that nothing can make the age go up to 1, which would break the command
    – user232393
    Jun 11 '19 at 21:17
  • it seems that after they are bred their nbt tag changes somehow. In testing, I can use spawn eggs to create babies off the big ones and teleport those without the adults. If they are bred with wheat, however, they all go with the teleport until they can breed again.
    – taybugb
    Jun 15 '19 at 21:51
  • I edited the answer now
    – user232393
    Jun 15 '19 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.