Batch 4 of the API review: api and host artifacts, ModuleLoadException

- Split into Gradle subprojects api (com.volmit:iris-api) and host
  (com.volmit:iris-host). ExposedPackages never exposes com.volmit.host.
- One unchecked ModuleLoadException(moduleId, origin, message, cause)
  for every load error; messages unchanged.
- PlacementAccess.set(x, y, z, state) next to set(PlacedBlock).
- BlockState: precompiled patterns, withProperty copies once.
- Mantle and layer views are made once per invocation.
- Hunk getters are width(), height(), depth().
- Held types and host types are deprecated for removal at the cut-over.
- Docs: artifacts, one-or-more modules per jar, no option shorthand.
This commit is contained in:
piexel committed 2026-10-24 04:19:39 +02:00
1 parent 3a307b5b8e
commit b6c2992752
309 files changed
+547 -178

No files matched your search

@@ -0,0 +1,26 @@
package com.volmit.mantle;
import java.util.Objects;
/** Block bounds, minimum inclusive and maximum exclusive. Empty boxes are valid. X and Z are world coordinates;
* Y is the height above the dimension's bottom (0 = bottom). Boxes of local volumes, such as an object's
* bounds, use that volume's own coordinates.
*/
public record BlockBox(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
public BlockBox {
if (minX > maxX || minY > maxY || minZ > maxZ) {
throw new IllegalArgumentException("Inverted block bounds");
}
}
public boolean contains(int x, int y, int z) {
return x >= minX && x < maxX && y >= minY && y < maxY && z >= minZ && z < maxZ;
}
public boolean contains(BlockBox area) {
Objects.requireNonNull(area, "area");
return area.minX >= minX && area.maxX <= maxX
&& area.minY >= minY && area.maxY <= maxY
&& area.minZ >= minZ && area.maxZ <= maxZ;
}
}
@@ -0,0 +1,45 @@
package com.volmit.mantle;
import com.volmit.block.BlockState;
/**
* Invocation-scoped access to typed mantle data. X and Z are world block coordinates; Y is
* the height above the dimension's bottom (0 = bottom), so it is never negative. The host translates
* them to storage coordinates.
*
* <p>The host owns chunk acquisition, release, persistence and the permitted access area.
* Out-of-area access throws IndexOutOfBoundsException. Access after the invocation ends
* throws IllegalStateException. Do not retain this interface or use it from detached tasks.
* Concurrent use of one instance is not supported unless the host explicitly permits it.
*
* <p>Only registered layers are supported. Unknown IDs or mismatched registered types throw
* IllegalArgumentException. Null arguments are rejected. Layer views share this view's lifetime.
*
* <p>Writes affect generation storage, not necessarily the current chunk Hunk or live world.
* Direct writes have no rollback guarantee. Use edit() to buffer multi-layer changes.
* The host must serialize overlapping writes; read-modify-write is not independently atomic.
*/
public interface Mantle {
BlockBox bounds();
<T> MantleLayer<T> layer(MantleKey<T> key);
/** The blocks the mantle holds for chunks to take over: what placements wrote, such as objects and structures.
* A chunk stage copies them into its chunk (Iris's {@code iris:matter}); absent positions read null, and air a
* placement wrote is a block like any other. The host owns this layer, so it needs no registration. Stages read
* it only, and writes throw UnsupportedOperationException: placements write blocks with
* {@link com.volmit.placement.PlacementAccess#set}. A dimension that keeps no mantle holds none.
*/
MantleLayer<BlockState> blocks();
/** Whether the mantle holds a carved void at the position for the chunk to take over: a cave's air or fluid, planned
* before the chunks were generated. Also true where the chunk's own blocks show no void, such as under a dimension
* stacked above. The host owns the carving; stages only ask. A dimension that keeps no mantle carves nothing.
*/
boolean isCarved(int x, int y, int z);
/** Only one edit may be active per view. Parent reads remain allowed, but parent
* mutations are prohibited until the edit ends (IllegalStateException).
*/
MantleEdit edit();
}
@@ -0,0 +1,18 @@
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<T> {
/** 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;
}
@@ -0,0 +1,19 @@
package com.volmit.mantle;
/** Buffered changes across layers, with the parent's bounds and registrations.
* Reads and visits include buffered replacements/removals over the unchanged parent.
* Nested edits are unsupported: edit() throws UnsupportedOperationException.
* The host excludes competing writers; this is not a concurrent or disk transaction.
*/
public interface MantleEdit extends Mantle, AutoCloseable {
/** Publishes all changes to the parent or leaves it unchanged on failure.
* Successful commit ends the edit and invalidates its layer views. On failure the
* edit can only be closed. Repeated commit throws IllegalStateException.
* This guarantee applies to generation storage, not crash recovery or world writes.
*/
void commit();
/** Discards uncommitted changes and invalidates edit views. Idempotent after commit/close. */
@Override
void close();
}
@@ -0,0 +1,17 @@
package com.volmit.mantle;
import java.util.Objects;
/** Stable storage identity. Different IDs may use the same value class without sharing data. */
public record MantleKey<T>(String id, Class<T> type) {
public MantleKey {
Objects.requireNonNull(id, "id");
Objects.requireNonNull(type, "type");
if (!id.matches("[a-z0-9_.-]+:[a-z0-9_./-]+")) {
throw new IllegalArgumentException("Expected a namespaced mantle ID: " + id);
}
if (type.isPrimitive()) {
throw new IllegalArgumentException("Mantle values require a reference type");
}
}
}
@@ -0,0 +1,25 @@
package com.volmit.mantle;
/** A registered layer bounded by its owning Mantle view and sharing its lifetime.
* Values must be non-null and treated as immutable. Wrong value types are rejected with
* IllegalArgumentException; null arguments with NullPointerException.
*/
public interface MantleLayer<T> {
/** Returns null on absence, without allocating a storage section. */
T get(int x, int y, int z);
void set(int x, int y, int z, T value);
/** Removing an absent entry is a no-op. */
void remove(int x, int y, int z);
/** Visits stored entries only, in ascending x, then y, then z order.
* Area must be fully within bounds (no silent clipping). Callbacks must not mutate
* this layer directly. An edit may buffer changes while visiting its parent layer.
* Callback exceptions propagate and stop traversal. No snapshot allocation is required.
*/
void visit(BlockBox area, MantleVisitor<T> visitor);
/** Removes all entries in the fully bounded area; other layers are untouched. */
void clear(BlockBox area);
}
@@ -0,0 +1,8 @@
package com.volmit.mantle;
public enum MantleLifetime {
/** May be removed only after all generation consumers, including neighbors, finish. */
GENERATION,
/** Survives generation cleanup; explicit removal is still permitted. */
PERSISTENT
}
@@ -0,0 +1,6 @@
package com.volmit.mantle;
@FunctionalInterface
public interface MantleVisitor<T> {
void accept(int x, int y, int z, T value);
}