mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 19:22:08 +00:00
Register saved keys per module, key mantle and saved ids by ResourceId
SavedKey moves to com.volmit.data and Codec becomes StorageCodec, which ends the clash with JsonForms.Codec. SavedKey.id and MantleKey.id are ResourceIds, so the copied id regex is gone. Modules register saved keys in setup with FeatureRegistry.registerSaved, owned like mantle keys, and RunningWorld.saved rejects a key that is not the registered one.
This commit is contained in:
1 parent
6c8fa31a7b
commit
307b89c5fe
19 files changed
+156
-88
No files matched your search
@@ -355,10 +355,14 @@ static PlantedChunks planted(PackWorld world) {
|
||||
- A state that is `AutoCloseable` is closed after the world stops, once nothing generates with it.
|
||||
|
||||
The state store is in memory and ends with the world. What must outlive a restart, such as when a spawner last fired,
|
||||
a module keeps with `RunningWorld.saved`. Only a running world has a folder to save in, so a tool's world has none:
|
||||
a module keeps with `RunningWorld.saved`. Only a running world has a folder to save in, so a tool's world has none.
|
||||
The module registers the key in `setup` like a mantle layer, under its own id:
|
||||
|
||||
```java
|
||||
private static final SavedKey<LastWaves> WAVES = new SavedKey<>("example:waves/last", LastWaves.class, new LastWavesCodec(), LastWaves::new);
|
||||
private static final SavedKey<LastWaves> WAVES = new SavedKey<>(ResourceId.parse("example:waves/last"), LastWaves.class,
|
||||
new LastWavesCodec(), LastWaves::new);
|
||||
|
||||
registry.registerSaved(WAVES); // in setup
|
||||
|
||||
LastWaves waves = world.running().orElseThrow().saved(WAVES); // the world's one instance, read on first ask
|
||||
waves.record(now); // changed in place; the module owns its thread safety
|
||||
@@ -367,8 +371,10 @@ waves.record(now); // changed in pl
|
||||
- The host reads the value when it is first asked for (`initial` when none is stored), writes it when it saves the world
|
||||
and when the world stops, and hands a world started over the same storage, such as after a hotload, what the old
|
||||
one wrote.
|
||||
- `Codec.write` may run while module threads change the value, so it must read it safely. A stored payload the codec
|
||||
rejects is logged and replaced with `initial`.
|
||||
- `StorageCodec.write` may run while module threads change the value, so it must read it safely. A stored payload the
|
||||
codec rejects is logged and replaced with `initial`.
|
||||
- `saved` throws `IllegalArgumentException` for a key nobody registered, and for another key with the id of a
|
||||
registered one. The id is the module's id or starts with it and `/`, as a mantle key's does.
|
||||
- The id names the stored file, so none of its segments is empty, `.` or `..`.
|
||||
|
||||
A module that wants to act when the host loads a pack or starts or stops a world registers a `ModuleLifecycle`. Every
|
||||
@@ -1117,8 +1123,8 @@ Optional<Clock> clock = pack.catalog().service(Clock.class); // a Pro
|
||||
a block with a block entity goes through `access.set(PlacedBlock)`. `BlockState.withProperty` copies the properties once.
|
||||
- Invocation views (`ctx.mantle()`, its layers and blocks, a placement's `access().mantle()`) are made once per
|
||||
invocation, so asking again returns the same view.
|
||||
- The `mantle` package keeps namespaced typed layers, lifetimes and buffered edits; `com.volmit.data.Codec` stores
|
||||
their values, and the values of `RunningWorld.saved`.
|
||||
- The `mantle` package keeps namespaced typed layers, lifetimes and buffered edits; `com.volmit.data.StorageCodec` stores
|
||||
their values, and the values of `RunningWorld.saved` (`com.volmit.data.SavedKey`).
|
||||
- `IrisFeature`, `@Feature`, the config annotations (`@Desc`, `@Required`, `@MinNumber`,
|
||||
`@MaxNumber`, `@MinItems`, `@Snippet`, `@Ref`) describe settings; the host reads them with `OptionsMetadata`
|
||||
(`com.volmit.host`).
|
||||
|
||||
Reference in new issue
Block a user