Changes

1,623 bytes added ,  07:45, 10 June 2022
Copy Saved Data to MC1.18 archive
<code>SavedData</code> 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 two important methods:
- <code>save</code>: Write the data to nbt.
- <code>setDirty</code>: Tell the game that the data has changed and needs to be saved to file.

The <code>save</code> method need to be implemented while <code>setDirty</code> 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.

==Attaching to a Level ==

To attach a Saved Data to a particular level, you must have access to an instance of <code>ServerLevel</code> or <code>ServerChunkCache</code>. From there, you can call the method <code>#getSavedData</code> which will give you an instance of the <code>DimensionDataStorage</code>: 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 <code>DimensionDataStorage#computeIfAbsent</code>. This takes in three arguments: the first to construct a saved data with data already existing in some <code>CompoundTag</code>, the second to construct a saved data with no existing data, and the third to specify the name of the file to save the data to within the <code>data</code> folder in the overworld or in the specific dimension of the save.

Global attachments are the same except that they should only be attached to the overworld as that level will always persist.


[[Category:Data Storage/1.18|Category:Data Storage]]
372

edits