Minecraft Java Edition Commands – How to Teleport an Entity to a Nearby Entity

minecraft-commandsminecraft-java-edition

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?

Best Answer

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.