Need help - How to get entity the player is looking at

Started by Always on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Need help - How to get entity the player is looking at

Ok, so I'm working on a mod and I don't rly know how to do this. I am making a food that swaps your position with the entity you are looking at when you eat it.

 

I was searching for forum posts and found this one:

https://mcreator.net/forum/61787/detect-entity-player-looking

 

It looked like its not possible with procedures to do this so I tried importing the code from the post. It did not work at all (cause im js noob)

If someone can walk me through on a way to make this work then that would be amazing because I am so lost right now. The version is 1.17

 

Joined Dec 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(Bearing in mind that this…
Thu, 02/19/2026 - 16:20

(Bearing in mind that this topic is 4 years old, I'm not sure if this will work or if it uses new additions to MCreator, but if my response helps then it helps. I also don't know if you still need this but I guess I'll keep this here if anyone else needs it.)

 

Using procedures, (to swap positions) you can probably use local variables to store the X, Y and Z coordinates of the player, then create a procedure for when the food is eaten that checks if an entity (of living entity type) exists at the 'look position' coordinate blocks. If there is an entity then you could set the 'player coordinates' local variables to the coords of the player, set the location of the player to the entity's coordinates and then set the location of the entity to the coords stored as local variables.