Jump to content

[1.7.10] Get EntityPlayer by name on client side


RedEnergy

Recommended Posts

Hello, i need to get EntityPlayer representation of player in the world. To do it i am using this line of code

EntityPlayer player = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(playerName);

It works fine but only for players who already loaded in client world, if player far from client it will return null. Why do i need it? I am currently making party mod for and i need to sync players from party on server and client. Here is this part of code

Link to comment
Share on other sites

I am currently making party mod for and i need to sync players from party on server and client

 

That doesn't explain why you need an EntityPlayer reference at all.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I need to get player with the specified name. If you look at the code, to which I have reference, you will see that i am storing all parties and players in it on the server side. If something changes in party (for example new player joined) i am sending SyncPartyPacket to all players in party, in which i am sending only player names. After receiving packet by client it must search for player with the given name in it's client world and form new client party. But if player doesn't loaded it doesn't exists in client party, so client cannot deserialize party successfuly.

Link to comment
Share on other sites

Client only has objects of loaded entities. End of story. Only way to achieve this would be to hack EntityTracker (server stuff that handles sending data about entites to given client) to add Entites that should not be loaded by given client. I do not recommend it as when I personally tried to do so - it is breaking almost everything - you have to add, handle and remove manually and make sure vanilla won't suddenly remove it for you. My experience with it says simple "NO".

 

What can be done (a trick) is to create client sided (@SideOnly(Side.CLIENT)) HashMap that would contain custom virtual storage.

e.g: "FakePlayerData.class" that would have double x/y/z and any other values.

That map you can hold either only for your client (inside client proxy) or inside IExtendedEntityProperties - recommended if you also want to know about paries that you personally don't belong to (so HashMap per-player).

Syncing would be totally up to you.

 

Notes about @SideOnly - when using it on fields, the filed CANNOT be initialized in class, it has to be pure:

@SideOnly(Side.CLIENT)
double lastKnownPosX;

And updated only later.

Why? JVM will try to init it on server or whatever - you can't do that.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.