Jump to content

[1.7.10][SOLVED] Get player entity from it UUID


Destructor

Recommended Posts

Hi all! I have creature entity. When player interacts with it then it gets and holds player entity.

        @Override
public boolean interact(EntityPlayer playerEnt) {
	this.playerEnt = playerEnt;
        }

When entity writes nbt it saves player UUID to nbt.

        @Override
public void writeEntityToNBT(NBTTagCompound var1) {
	super.writeEntityToNBT(var1);
                
                var1.setString("playerId", playerEnt.getGameProfile().getId().toString());
        }

And when it reading nbt, it also reads a player UUID and tries to get player entity from UUID

@Override
public void readEntityFromNBT(NBTTagCompound var1) {
	super.readEntityFromNBT(var1);

                playerEnt = this.worldObj.func_152378_a(UUID.fromString(var1.getString("playerId")));
        }

 

My problem is that after save and load 'playerEnt' always is null  :-\

Where I made a mistake?

Link to comment
Share on other sites

And just so you know what exactly is a WeakReference, here is the Java Documentation for it:

 

http://docs.oracle.com/javase/7/docs/api/java/lang/ref/WeakReference.html and an article about it https://weblogs.java.net/blog/2006/05/04/understanding-weak-references

 

TL;DR: Garbage Collector Friendly Object :P

I require Java, both the coffee and the code :)

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.