Jump to content

Recommended Posts

Posted

I wrote a mod that creates a system of levels, but it does not properly retains NBT data

I go to the game, I Level 5 (https://www.dropbox.com/s/ahsy2bqqai7uvb5/2014-02-15_14.52.11.png)

I used the command to get XP, and my level is a 19 (https://www.dropbox.com/s/yb6h6z91nv12o2u/2014-02-15_14.52.25.png)

Relogin and... failure! my level is not 19, only 6! (https://www.dropbox.com/s/ms49a7a489jgf5b/2014-02-15_14.52.34.png)

 

this is my code:

a class that includes the login and logout events - http://pastebin.com/g7dXxHCa

DataPlayer, which contains details of the player, and some methods - http://pastebin.com/B9PD2J5k

And method from StatsUtil that check exp and call levelUp if need. http://pastebin.com/j8uxui2D

Posted

As it turned out, writes NBT date correctly. However reads not correctly. Probably a mistake in NBTTagList nbtListStats = nbtPlayer.getTagList("Stats", 9); , because there was no 1.6.4 2nd parameter, and now I have taken it at random.

Posted

The types are defined in the NBTBase class:

public static final String[] NBTTypes = new String[] {"END", "BYTE", "SHORT", "INT", "LONG", "FLOAT", "DOUBLE", "BYTE[]", "STRING", "LIST", "COMPOUND", "INT[]"};

Either count to the position of the type that you need, starting at zero (END is 0, BYTE is 1, etc.), or if you have an NBTBase of any type you can use nbtbase.getId() to return the correct id.

 

@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
// here is use the compound.getId(), but I could just write '10' instead
// since I know that I stored NBTTagCompounds in this particular NBTTagList
NBTTagList items = compound.getTagList("Items", compound.getId());
// etc.

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.