Jump to content

Recommended Posts

Posted

Hi all,

I'm trying to add some properties to the player, and it's not correctly working.  Through some system.out.println()'s, I know it is saving, loading, and initializing my properties, it's just not applying them to the player.  I remember reading something old about properties, and packets, but I can't find it anymore and I'm not sure. 

My properties code:

 

  Reveal hidden contents

 

I previously had it work by calling EntityPlayer.getEntityData(), but that doesn't vary between worlds like I want it to.

Posted

If everything is saving and loading properly, then you're fine. The problem is that the client-side data is not automatically synchronized, so you have to do it yourself.

 

Either:

a) send a packet to the client with the data and set it manually; this is best done from somewhere like the EntityJoinWorldEvent to avoid NPE of the client-side properties

 

b) use DataWatcher to store your data instead of class fields; advantage is that everything else is automatic; disadvantage is you are using an extremely limited resource (data watcher slots)

 

There are tutorials on the Forge wiki about both packets and data watcher, both of which are referenced on this list:

http://mazetar.com/mctuts/displayTutorials.php

 

Alternatively, you can check out my tutorial on IExtendedEntityProperties here:

http://www.minecraftforum.net/topic/1952901-eventhandler-and-iextendedentityproperties/#entry24051513

Posted
  On 1/12/2014 at 1:31 AM, coolAlias said:

If everything is saving and loading properly, then you're fine. The problem is that the client-side data is not automatically synchronized, so you have to do it yourself.

 

Either:

a) send a packet to the client with the data and set it manually; this is best done from somewhere like the EntityJoinWorldEvent to avoid NPE of the client-side properties

 

b) use DataWatcher to store your data instead of class fields; advantage is that everything else is automatic; disadvantage is you are using an extremely limited resource (data watcher slots)

 

There are tutorials on the Forge wiki about both packets and data watcher, both of which are referenced on this list:

http://mazetar.com/mctuts/displayTutorials.php

 

Alternatively, you can check out my tutorial on IExtendedEntityProperties here:

http://www.minecraftforum.net/topic/1952901-eventhandler-and-iextendedentityproperties/#entry24051513

I do know how to use datawatcher (never used packets, so I'm going to avoid that route), but thanks for the tip.  I looked at your tutorial, and the only question I have is should I add the watcher in the init method of my ExtendedProperties class?

Posted
  On 1/12/2014 at 2:02 AM, coolAlias said:

You can add datawatcher in either the init or in the constructor, doesn't really matter since init is called during class construction anyway.

Thanks!

 

But on a side note, in your tutorial it does say you haven't found a use for your Init method. You have figured out what that does, correct?

Posted
  On 1/12/2014 at 2:17 AM, ninjapancakes87 said:

But on a side note, in your tutorial it does say you haven't found a use for your Init method. You have figured out what that does, correct?

It's the same as entityInit in Entity classes; it gets called during entity construction, so you could put the exact same code in your constructor and it would have the same effect. The benefit of the init method in IExtendedEntityProperties is that it provides a world object, but I haven't found it (the extra world parameter) particularly useful because the entity itself isn't yet finished constructing.

Posted
  On 1/12/2014 at 2:40 AM, coolAlias said:

  Quote

But on a side note, in your tutorial it does say you haven't found a use for your Init method. You have figured out what that does, correct?

It's the same as entityInit in Entity classes; it gets called during entity construction, so you could put the exact same code in your constructor and it would have the same effect. The benefit of the init method in IExtendedEntityProperties is that it provides a world object, but I haven't found it (the extra world parameter) particularly useful because the entity itself isn't yet finished constructing.

I know, just wanted to make sure :P

Posted
  On 1/12/2014 at 2:54 AM, ninjapancakes87 said:

Do I still need to call NBTTagCompound in my load and read methods?  It seems redundant.

There are lots of things that can be streamlined; most of what I did I did that way on purpose to make it more clear as to what's going on. It's a tutorial, after all, not end-product polished code. You can do it however you want :P

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.