How to teleport a player to a nearby entity?

Started by yoyo_yoko on

Topic category: Help with Minecraft modding (Java Edition)

Active 7 months ago
Joined Apr 2023
Points:
309

User statistics:

  • Modifications: 1
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 5
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)

Active 1 week ago
Joined Jan 2025
Points:
108

User statistics:

  • Modifications: 1
  • Forum topics: 6
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 63
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=~]"

Active 7 months ago
Joined Apr 2023
Points:
309

User statistics:

  • Modifications: 1
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 5
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

Active 7 months ago
Joined Apr 2023
Points:
309

User statistics:

  • Modifications: 1
  • Forum topics: 7
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 5
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.