With players, you can teleport player1 to the closest nearby player with:

/execute at player1 run tp @p

But can the same be done with an entity?


First of all, I suggest reading this post's answer because it will likely have a lot of information which is helpful to you.

Secondly, in it's simplest form the /tp command takes two entity arguments, or one entity and one location argument. /tp <entity> <entity> or /tp <entity> [<Pos>].

If you wanted to teleport the nearest sheep to the nearest villager, relative to your location, you would do /tp @e[type=sheep,sort=nearest,limit=1] @e[type=villager,sort=nearest,limit=1].

All entities selected by the first argument will be teleported to the entity selected by the second argument. Keep in mind that the second selector must only select one entity, or otherwise you will get an error.

For more information, see the links provided in Robbie's answer.


You can use @e to target all entities so if you wanted to teleport all cows near by you would use

/tp @e[type=cow]

to teleport the cows to the nearest player it would be

/tp @e[type=cow] @p

I don't believe there is a way to teleport a single entity.




To teleport an entity (such as an entity tagged cow1, for example), to the nearest entity that is not itself, use this command:

tp @s @e[tag=!cow1,sort=nearest,limit=1]

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.