Posted January 11, 201411 yr 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: package ninjapancakes87.civilwar; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class ExtendedProperties implements IExtendedEntityProperties{ /**The number of soldiers hired by the player*/ private int armySize; /**Whether the player has hired a Union or Confederate soldier*/ private boolean isUnion; public int getArmySize(){ return this.armySize; } public void setArmySize(int par1){ this.armySize = par1; } public boolean getIsUnion(){ return this.isUnion; } public void setIsUnion(boolean par1){ this.isUnion = par1; } @Override public void saveNBTData(NBTTagCompound compound) { compound.setBoolean("isUnion", isUnion); compound.setInteger("armySize", armySize); } @Override public void loadNBTData(NBTTagCompound compound) { this.isUnion = compound.getBoolean("isUnion"); this.armySize = compound.getInteger("armySize"); } @Override public void init(Entity entity, World world) { if(entity instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer)entity; } } } I previously had it work by calling EntityPlayer.getEntityData(), but that doesn't vary between worlds like I want it to.
January 12, 201411 yr 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 http://i.imgur.com/NdrFdld.png[/img]
January 12, 201411 yr Author 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?
January 12, 201411 yr You can add datawatcher in either the init or in the constructor, doesn't really matter since init is called during class construction anyway. http://i.imgur.com/NdrFdld.png[/img]
January 12, 201411 yr Author 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?
January 12, 201411 yr 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. http://i.imgur.com/NdrFdld.png[/img]
January 12, 201411 yr Author 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
January 12, 201411 yr Author Do I still need to call NBTTagCompound in my load and read methods? It seems redundant.
January 12, 201411 yr 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 http://i.imgur.com/NdrFdld.png[/img]
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.