Jump to content

Custom NBT data for player doesn't save [Solved]


Spaceboy Ross

Recommended Posts

You can't do this client-side only

if(button.id == this.btnNewtype.id) this.nt.setHumantype(EHumantypes.NEWTYPE);
if(button.id == this.btnOldtype.id) this.nt.setHumantype(EHumantypes.OLDTYPE);

This only sets your data on the client(and that data won't be persistent as one might guess). You need to send a packet to the server and set the data there.

 

https://github.com/SpaceboyRoss01/MSGundamMod/blob/master/src/main/java/com/spaceboyross/gundam/capabilities/providers/NewtypeProvider.java

The generic type for ICapabilitySerializable is either NBTBase or any of it's children. If you are using NBTTagCompound to begin with you should just use it as your generic type rather than casting all over the place.

And why are you introducing a HANDLER generic type You do not need it as far as I am concerned.

This makes absolutely zero sense. A capability of NBTBase? The generic constraint there is your capability interface, not the type it is serialized into. I have no idea how it is even working and not crashing you completely.

 

This line is useless. It just creates a final field that is assigned to null. If you want your capability to be injected there you need to add the annotation.

 

root.setInteger("humantype",instance.getHumantype() == EHumantypes.OLDTYPE ? 0 : (instance.getHumantype() == EHumantypes.CYBER_NEWTYPE ? 1 : 2));

=>

root.setInteger("humantype",instance.getHumantype().ordinal()));

 

instance.setHumantype((new EHumantypes[] {
					EHumantypes.OLDTYPE,
					EHumantypes.CYBER_NEWTYPE,
					EHumantypes.NEWTYPE
				})[root.getInteger("humantype")]);

=>

instance.setHumantype(EHumantype.values()[root.getInteger("humantype")]);

 

You also must copy the data from the old capability to the new capability upon PlayerEvent.Clone, otherwise your capability data will reset to defaults every time the player is cloned(respawns for example)

 

ResourceLocations should be all lower-case. In 1.13 the "should" turns into "must" as an exception will be thrown on non-lower-case ResourceLocations.

 

TL;DR: I think that your problem is not serialization but 

a) The fact that you only ever set the values on the client

b) That your capability provider is broken.

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.



×
×
  • Create New...

Important Information

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