Jump to content

[1.8] World NBT data not saving


Recommended Posts

I forgot to register the event


Edit: Only problem is, when a world is first loaded, my code is creating four town tag compounds when there should only be one, and every time I load up the world again, that amount multiplies and it's at 60 now. I think there is something seriously wrong with how I have coded this.


Edit: Ok...I fixed the duplication by clearing the TownManager towns ArrayList every time the world is loaded, right before I populate the list. I am still not sure if this is the best way to do this, I am not a very good programmer. Is the TownManager code supposed to be run on serverside only?

Link to comment
Share on other sites

Ok, I refactored a bit and fixed my previous issues. But, my WorldSavedData is only being saved to the overworld dimension data, not to the nether or end.




Why is this happening? Each dimension is its own World class, and therefore should be getting its own WorldSavedData, right?


Here is the class where I load up the WorldSavedData whenever a dimension loads



Link to comment
Share on other sites

If you use World.mapStorage (which you implicitly do if you use the methods directly in world) your data is global for the whole save file. It will be stored in the overworld folder but will be available to all dimensions as one instance.


If you use World.perWorldStorage instead there will be one instance of your data per dimension.



Perfect, thanks

Link to comment
Share on other sites

Ok, I am puzzled once again.


Relevant classes

Town.java: A data structure representing a town



CivilizationWorldData.java: Manages an ArrayList of Towns and loads/writes Town NBT from/to disk



WorldLoadEventHandler.java: Tells worlds to load CivilizationWorldData whenever a world is loaded



ItemFoundingBook.java: Attempts to create a world when right clicked by calling CivilizationWorldData.addTown(Town town)



Description of the intent of the code and the problem encountered

When a world is loaded, WorldLoadEventHandler will tell the world to load CivilizationWorldData, causing it to read relevant town NBT and create and add Town objects to its internal ArrayList<Town> towns.


Upon creating a new town via ItemFoundingBook, everything works properly at first. You use it once, and the Town object is created and added to the ArrayList<Town> towns. It is also saved to disk when pausing the game. You are unable to create another town of the same name, because it is already in the ArrayList<Town> towns.


HOWEVER, when exiting out of the world and then entering it again, it is reset back to square one. You are able to create another town of the same name again, even though it is already on disk.


It is as if the ArrayList<Town> towns is not being initialized up when a world loads, even though the code for doing that exists in CivilizationWorldData.readFromNBT(NBTTagCompound nbt).


The code is there, why isn't it reading the NBT from the world and filling out the ArrayList<Town> towns when the world is told to load the CivilizationWorldData?

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.

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.