-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fedf19
commit 9d69a8e
Showing
6 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Accessing a Storage | ||
Storages can be accessed using the `StorageHolder#manasCore$getStorageOptional` method and your `StorageKey` instance you get when registering a storage. | ||
|
||
```java | ||
entity.manasCore$getStorageOptional(STORAGE_KEY); | ||
level.manasCore$getStorageOptional(STORAGE_KEY); | ||
chunk.manasCore$getStorageOptional(STORAGE_KEY); | ||
``` | ||
|
||
## Modifying Data | ||
To modify data inside of a storage you can just mutate the storage instance you get from the `StorageHolder#manasCore$getStorageOptional` method. | ||
|
||
It is recommended to create a getter and setter method for each field you want to modify within your storage to ensure that changes mark the storage as dirty: | ||
|
||
```java | ||
entity.manasCore$getStorageOptional(STORAGE_KEY).ifPresent(storage -> { | ||
storage.setExampleInt(420); | ||
}) | ||
``` | ||
It is also possible to directly modify the storage data without using a setter method, but you have to call `markDirty` manually to ensure that the storage is marked as dirty: | ||
|
||
```java | ||
entity.manasCore$getStorageOptional(STORAGE_KEY).ifPresent(storage -> { | ||
storage.exampleInt = 420; | ||
storage.markDirty(); | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Optimize update Package performance | ||
By default ManasCore Storages fully deserialize and serialize the data on every update. | ||
This can be a performance bottleneck if you have a lot of data in your storage. | ||
To optimize the performance, you can override the `Storage#saveOutdated` method in your custom Storage class to only apply the changed data to the update tag. | ||
|
||
```java | ||
public static class ExampleStorage extends Storage { | ||
private int exampleInt = 0; | ||
|
||
public ExampleStorage(StorageHolder holder) { | ||
super(holder); | ||
} | ||
|
||
@Override | ||
public void save(CompoundTag data) { | ||
data.putInt("exampleInt", exampleInt); | ||
} | ||
|
||
@Override | ||
public void load(CompoundTag data) { | ||
exampleInt = data.getInt("exampleInt"); | ||
} | ||
|
||
public int getExampleInt() { | ||
return exampleInt; | ||
} | ||
|
||
public void setExampleInt(int exampleInt) { | ||
this.exampleInt = exampleInt; | ||
markDirty(); // Tells the system that the storage has been modified | ||
} | ||
|
||
@Override | ||
public void saveOutdated(CompoundTag data) { | ||
data.putInt("exampleInt", exampleInt); | ||
} | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.