From 7cc3302c32f57a70ed84dbd5568b0f266e9cbfbe Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 11:22:29 +0100 Subject: [PATCH] Move MantleCodec to com.volmit.data.Codec Saved world state stores values with the same contract, so the codec no longer belongs to the mantle package or says mantle in its doc. --- .../main/java/com/volmit/FeatureRegistry.java | 4 ++-- api/src/main/java/com/volmit/data/Codec.java | 19 +++++++++++++++++++ .../java/com/volmit/mantle/MantleCodec.java | 18 ------------------ .../com/volmit/host/MantleRegistration.java | 4 ++-- .../java/com/volmit/host/ModuleRegistry.java | 4 ++-- .../com/volmit/example/chunk/VeinModule.java | 4 ++-- .../com/volmit/host/ModuleRegistryTest.java | 5 +++-- .../java/com/volmit/host/StageGraphTest.java | 6 +++--- 8 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 api/src/main/java/com/volmit/data/Codec.java delete mode 100644 api/src/main/java/com/volmit/mantle/MantleCodec.java diff --git a/api/src/main/java/com/volmit/FeatureRegistry.java b/api/src/main/java/com/volmit/FeatureRegistry.java index a7775cc7d..d56b3724d 100644 --- a/api/src/main/java/com/volmit/FeatureRegistry.java +++ b/api/src/main/java/com/volmit/FeatureRegistry.java @@ -1,6 +1,6 @@ package com.volmit; -import com.volmit.mantle.MantleCodec; +import com.volmit.data.Codec; import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLifetime; import com.volmit.resource.ResourceKind; @@ -21,7 +21,7 @@ public interface FeatureRegistry { * preserve unknown persisted layers or fail explicitly, never silently discard them. * GENERATION layers also require codecs. */ - void registerMantle(MantleKey key, MantleLifetime lifetime, MantleCodec codec); + void registerMantle(MantleKey key, MantleLifetime lifetime, Codec codec); /** Catalogs a settings type that no stage names in {@code when(...)}, such as one read only * through {@link com.volmit.config.FeatureSettings#at}, so the host decodes it and studio diff --git a/api/src/main/java/com/volmit/data/Codec.java b/api/src/main/java/com/volmit/data/Codec.java new file mode 100644 index 000000000..38bb10259 --- /dev/null +++ b/api/src/main/java/com/volmit/data/Codec.java @@ -0,0 +1,19 @@ +package com.volmit.data; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +/** Value serialization for data the host stores for a module: mantle layers ({@link com.volmit.mantle.MantleKey}) and + * saved world state ({@link com.volmit.world.SavedKey}). The host frames payloads and stores the key ID and version + * separately. Implementations must support concurrent calls, must not close streams, and must reject malformed data or + * unsupported stored versions with IOException. Values cannot be null. + */ +public interface Codec { + /** Nonnegative format version, stable for the registration lifetime. */ + int version(); + + void write(DataOutput output, T value) throws IOException; + + T read(DataInput input, int storedVersion) throws IOException; +} diff --git a/api/src/main/java/com/volmit/mantle/MantleCodec.java b/api/src/main/java/com/volmit/mantle/MantleCodec.java deleted file mode 100644 index 58ede92da..000000000 --- a/api/src/main/java/com/volmit/mantle/MantleCodec.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.volmit.mantle; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -/** Value serialization. Host frames payloads and stores key ID and version separately. - * Implementations must support concurrent calls, must not close streams, and must reject - * malformed data or unsupported stored versions with IOException. Values cannot be null. - */ -public interface MantleCodec { - /** Nonnegative format version, stable for the registration lifetime. */ - int version(); - - void write(DataOutput output, T value) throws IOException; - - T read(DataInput input, int storedVersion) throws IOException; -} diff --git a/host/src/main/java/com/volmit/host/MantleRegistration.java b/host/src/main/java/com/volmit/host/MantleRegistration.java index 399afdac9..303358093 100644 --- a/host/src/main/java/com/volmit/host/MantleRegistration.java +++ b/host/src/main/java/com/volmit/host/MantleRegistration.java @@ -1,6 +1,6 @@ package com.volmit.host; -import com.volmit.mantle.MantleCodec; +import com.volmit.data.Codec; import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLifetime; import java.util.Objects; @@ -8,7 +8,7 @@ import java.util.Objects; public record MantleRegistration( MantleKey key, MantleLifetime lifetime, - MantleCodec codec, + Codec codec, int version) { public MantleRegistration { Objects.requireNonNull(key, "key"); diff --git a/host/src/main/java/com/volmit/host/ModuleRegistry.java b/host/src/main/java/com/volmit/host/ModuleRegistry.java index fc6f29f29..99e7ece68 100644 --- a/host/src/main/java/com/volmit/host/ModuleRegistry.java +++ b/host/src/main/java/com/volmit/host/ModuleRegistry.java @@ -4,7 +4,7 @@ import com.volmit.FeatureRegistry; import com.volmit.IrisFeature; import com.volmit.ModuleLifecycle; import com.volmit.config.Level; -import com.volmit.mantle.MantleCodec; +import com.volmit.data.Codec; import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLifetime; import com.volmit.resource.ResourceId; @@ -84,7 +84,7 @@ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry { } @Override - public void registerMantle(MantleKey key, MantleLifetime lifetime, MantleCodec codec) { + public void registerMantle(MantleKey key, MantleLifetime lifetime, Codec codec) { checkOpen(); Objects.requireNonNull(key, "key"); Objects.requireNonNull(codec, "codec"); diff --git a/host/src/test/java/com/volmit/example/chunk/VeinModule.java b/host/src/test/java/com/volmit/example/chunk/VeinModule.java index 0e733f9a0..100f9f1b8 100644 --- a/host/src/test/java/com/volmit/example/chunk/VeinModule.java +++ b/host/src/test/java/com/volmit/example/chunk/VeinModule.java @@ -7,7 +7,7 @@ import com.volmit.block.BlockState; import com.volmit.config.PackSettings; import com.volmit.generation.ChunkContext; import com.volmit.geometry.BlockBox; -import com.volmit.mantle.MantleCodec; +import com.volmit.data.Codec; import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLifetime; import com.volmit.stage.ChunkStage; @@ -69,7 +69,7 @@ public final class VeinModule implements IrisModule { blocks.set(x - context.originX(), y, z - context.originZ(), ORE_BLOCK)); } - private static final class IntegerCodec implements MantleCodec { + private static final class IntegerCodec implements Codec { public int version() { return 0; } public void write(DataOutput output, Integer value) throws IOException { output.writeInt(value); } public Integer read(DataInput input, int storedVersion) throws IOException { return input.readInt(); } diff --git a/host/src/test/java/com/volmit/host/ModuleRegistryTest.java b/host/src/test/java/com/volmit/host/ModuleRegistryTest.java index e97ddadd1..fc9d1496c 100644 --- a/host/src/test/java/com/volmit/host/ModuleRegistryTest.java +++ b/host/src/test/java/com/volmit/host/ModuleRegistryTest.java @@ -3,6 +3,7 @@ package com.volmit.host; import com.volmit.*; import com.volmit.config.Feature; import com.volmit.config.Level; +import com.volmit.data.Codec; import com.volmit.mantle.*; import com.volmit.resource.ResourceKind; import com.volmit.service.Providers; @@ -591,8 +592,8 @@ class ModuleRegistryTest { assertEquals("test:alpha", registrations.getFirst().module().info().id().toString()); } - private static MantleCodec codec(int version) { - return new MantleCodec<>() { + private static Codec codec(int version) { + return new Codec<>() { public int version() { return version; } public void write(DataOutput output, String value) {} public String read(DataInput input, int storedVersion) { return ""; } diff --git a/host/src/test/java/com/volmit/host/StageGraphTest.java b/host/src/test/java/com/volmit/host/StageGraphTest.java index c41d64c4b..f49bc0b6f 100644 --- a/host/src/test/java/com/volmit/host/StageGraphTest.java +++ b/host/src/test/java/com/volmit/host/StageGraphTest.java @@ -11,7 +11,7 @@ import com.volmit.config.Feature; import com.volmit.config.FeatureSettings.Entry; import com.volmit.geometry.BlockBox; import com.volmit.geometry.BlockPosition; -import com.volmit.mantle.MantleCodec; +import com.volmit.data.Codec; import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLifetime; import com.volmit.object.GeneratedObject; @@ -694,8 +694,8 @@ class StageGraphTest { registry.registerMantle(layer, MantleLifetime.GENERATION, codec(layer)); } - private static MantleCodec codec(MantleKey layer) { - return new MantleCodec<>() { + private static Codec codec(MantleKey layer) { + return new Codec<>() { public int version() { return 0; } public void write(java.io.DataOutput output, T value) {} public T read(java.io.DataInput input, int storedVersion) { throw new UnsupportedOperationException(); }