How do I get the Player Entity that the client is playing as?

Started by Mecho on

Topic category: Help with Minecraft modding (Java Edition)

Active 7 months ago
Joined Feb 2023
Points:
329

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 31
How do I get the Player Entity that the client is playing as?

Title

I'm making an entity that is only visible to one player, by setting the texture to blank on the client side when they are not the target.

And while in testing it is most certainly possible to hide the entity by using a logic custom nbt tag, I've run into a dead end when trying to find the player entity that the client is playing as, as I need it to match the client's player to the player the entity is targeting.

Any help would be appreciated :)

Active 4 days ago
Joined May 2023
Points:
229

User statistics:

  • Modifications: 0
  • Forum topics: 2
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 10
Hey, not sure if this is…
Thu, 07/31/2025 - 03:08

Hey, not sure if this is exactly what you needed, or if you still even need it anymore, but I have found how to get the player entity associated with the client. (I wish there was just a procedure block for checking if the player entity is, but oh well.)

 

I just did this test, so I can't be 100% sure it works, but I'm very confident it does. I figured out that your game client always loads your player entity first. So when your client-sided instance of "On player tick update" goes through all players that are on the server, yours will be first. Now, because your player always gets executed first, we can abuse this with the following procedure: