From cf39971d1a66f760412b402dd9b001f30a2b756e Mon Sep 17 00:00:00 2001 From: ChampionAsh5357 Date: Tue, 15 Oct 2024 13:23:41 -0400 Subject: [PATCH] feat(docs): Update data storage section --- docs/datastorage/saveddata.md | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/docs/datastorage/saveddata.md b/docs/datastorage/saveddata.md index f747197a..37f1a6bb 100644 --- a/docs/datastorage/saveddata.md +++ b/docs/datastorage/saveddata.md @@ -25,15 +25,32 @@ Any `SavedData` is loaded and/or attached to a level dynamically. As such, if on For example, if a SD was named "example" within the Nether, then a file would be created at `.//DIM-1/data/example.dat` and would be implemented like so: ```java -// In some class -public ExampleSavedData create() { - return new ExampleSavedData(); -} - -public ExampleSavedData load(CompoundTag tag, HolderLookup.Provider lookupProvider) { - ExampleSavedData data = this.create(); - // Load saved data - return data; +// In some saved data implementation +public class ExampleSavedData extends SavedData { + + // Create new instance of saved data + public ExampleSavedData create() { + return new ExampleSavedData(); + } + + // Load existing instance of saved data + public ExampleSavedData load(CompoundTag tag, HolderLookup.Provider lookupProvider) { + ExampleSavedData data = this.create(); + // Load saved data + return data; + } + + @Override + public CompoundTag save(CompoundTag tag, HolderLookup.Provider registries) { + // Write data to tag + return tag; + } + + public void foo() { + // Change data in saved data + // Call set dirty if data changes + this.setDirty(); + } } // In some method within the class