How to teleport a player to a nearby entity?

Started by yoyo_yoko 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)

Joined Jan 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Try a procedure what…
Tue, 01/07/2025 - 19:27

Try a procedure what executes: "/execute as @p run tp @s @e[type=!player, r=(local:TravelRaidius), x=~, y=~, z=~]"

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm gonna assume I need to…
Mon, 01/13/2025 - 00:48

I'm gonna assume I need to make a variable for it, probably the same name and a number variable? Sorry I just got to this lol

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
But also, isn't it not…
Mon, 01/13/2025 - 00:53

But also, isn't it not possible to tp to @e? I'm doing this on 1.20.1 Forge if that helps.