Skip to content

Commit

Permalink
feat(docs): Update data storage section
Browse files Browse the repository at this point in the history
  • Loading branch information
ChampionAsh5357 committed Oct 15, 2024
1 parent 5785aa4 commit cf39971
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions docs/datastorage/saveddata.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `./<level_folder>/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
Expand Down

1 comment on commit cf39971

@neoforged-pages-deployments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying with Cloudflare Pages

Name Result
Last commit: cf39971d1a66f760412b402dd9b001f30a2b756e
Status: ✅ Deploy successful!
Preview URL: https://d493dce3.neoforged-docs-previews.pages.dev
PR Preview URL: https://pr-178.neoforged-docs-previews.pages.dev

Please sign in to comment.