Jump to content

[1.16.5] [(somewhat) SOLVED] How do you implement WorldSavedData in 1.16?


Recommended Posts

Posted (edited)

I'm currently developing one of my first mods and for the first time I have to store data for when players quit the game.
I've been at it for a couple of days now and it's getting hopeless. I've tried looking at the code to see what's going on. I've tried searching online for implementations. I've tried brute forcing it by trying all kinds of things to see what sticks..
My lead is starting to run dry and I don't know how to go forward.

When I try to search for it online I only find code from at least two years ago and Forge has changed this class quite a bit since then. I've tried to "recreate" how it was previously done but with the new methods and implementations but this hasn't been a succes.

I don't have any useful code to show you since it's just a mess of code and comments from things I have tried. When using the Override methods save and load (in my data class that extends WorldSavedData) I managed to set a boolean to true and remember it when I reload the world but won't remember it when I restart the game. I've tried making use of world#setMapData and world#getMapData and with this I got the game to remember mapdata even when closing the game but when doing this I'm unable to set the boolean to true. I've tried mixing these two things together but have failed. I've also tried setting the mapdata as well as the entire data class as dirty.

Does someone know how to implement this correctly in 1.16? Just an example or explanation on how to do it and I would be on my way. It would be very much appreciated! :)
The lack of any information about this online (for as far as my capabilities to search for it) has started to become frustrating..

Edit: See my first comment for more context

(Somewhat) SOLVED: I solved the problem thanks to some feedback in another thread that I made. I say somewhat solved because I still don't know how to implement WorldSavedData but that's okay because using the capability system is a much better way to save data. Even though saving is not the subject of this thread, it is one of the main talking points: 

 

Edited by Astro2202
Posted (edited)
2 hours ago, ChampionAsh5357 said:

You can check an updated resource here on the community docs.

What I already notice is that it's no longer markDirty() but setDirty(). I'll try to implement it as best as I can using these docs. Thank you very much! This wiki seems incredibly useful and I didn't even know it existed... If I still can't manage to let it work I'll post my current code.

Edit:

After having a closer look I soon found out that I have the same problems with this documentation. While it does give useful context about some of the uses and such of WorldSavedData, it's no longer up to date. The methods mentioned that you're supposed to use to make it work no longer exist and I can't seem to figure out what the new implementation is.

For added context for what I'm trying to achieve:
I'm trying to create a decay mod in which the blocks - And this is important - that are ONLY placed by the player are affected by the decay logic that I am trying to implement. I am not adding any extra blocks to the game, just adding behavior to existing ones. For example Stone Bricks will change into cracked or mossy stone brick depending on their situation after a certain amount of time. I'm very new to modding so the solution that I came up with is adding a DecayHandler class to every block placed by the player that keeps track of the block that is placed and applies decaying functionality to it. The problem is that when you close the game, these DecayHandlers are thrown out and all decaying simulation is lost when the world is reloaded. The reason that I'm giving this information is because I'd like to ask two things:
Is this a good way to do it and is WorldSavedData the best way to store my DecayHandlers?

Edited by Astro2202
Posted
1 hour ago, Astro2202 said:

The methods mentioned that you're supposed to use to make it work no longer exist and I can't seem to figure out what the new implementation is.

This statement is a bit incorrect. The methods still exist, they just use a different mapping set (MCP) than what forge ships with the mdk by default (mojmap). You can use forge-bot on the Forge Discord or Linkie on the Linkie Discord to translate from them.

1 hour ago, Astro2202 said:

Is this a good way to do it and is WorldSavedData the best way to store my DecayHandlers?

I would probably use a chunk capability instead and tick logic on loaded chunks since you'd have to check every block if it's loaded other than checking the loaded chunks. You could also use a world capability to store the chunks that have an active capability for more efficient usage.

  • Like 1
  • Astro2202 changed the title to [1.16.5] [(somewhat) SOLVED] How do you implement WorldSavedData in 1.16?

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.