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?
Arqade is a question and answer site for passionate videogamers on all platforms. It only takes a minute to sign up.Sign up to join this community
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
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.