How to teleport a player to a nearby entity?

Started by xerox929 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to teleport a player to a nearby entity?

I have this enchantment in a mod I'm working on that on a keybind press, it will teleport the player to the nearest entity in a radius of the enchantment level + 2 (the enchantment level max is 3). I don't have a lot of ideas but one I had was to check for the nearest entity data block, storing the x y and z coordinates then moving the player there (but changing the coordinates slightly to make the player appear behind the entity). The issue is, when I check for the nearest entity, it always returns the player. Can I make it not do this, besides avoiding player entites completely? (I still want this to work on other players)