Views
Actions
Saved Data
World Saved Data is an alternative to capabilities that stores data per dimension or globally depending on how the context is passed.
Class Structure
The class can be broken down into three important methods:
-read
: Read the stored nbt data. -write
: Write the object to nbt. -markDirty
: Tell the object to save the data to file.
The read
and write
methods need to be implemented while markDirty
should be called whenever the data is going to be manipulated. As the class is abstract, it should be subclassed with these three methods implemented.
The super call requires a String
argument. This is used to denote the name of the data file within the dimension itself. For example, if the argument was "pipes", then a file would be created within each dimension folder called data/pipes.dat
.
Attaching to a Dimension
To attach a World Saved Data to a particular dimension, you must have access to an instance of ServerWorld
or ServerChunkProvider
. From there, you can call the method #getSavedData
which will give you an instance of the DimensionSavedDataManager
: the class that stores all saved data for that particular dimension. You can attach an instance or get the current instance of the data using DimensionSavedDataManager#getOrCreate
. This should be used in most cases to get an instance of the specified data or create a new one if not available. From there, you can operate on your saved data as if it was a capability.
Global attachments are the same by either synchronizing the data between the three worlds or using the same object reference stored in each world.