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,34 @@
package com.volmit.object;
import com.volmit.resource.ResourceId;
import java.util.Arrays;
import java.util.Objects;
/** Immutable versioned payload. The host's adapter owns interpretation and size limits.
* Unsupported formats/versions fail explicitly; native objects and mutable buffers never escape.
*/
public final class BlockEntityData {
private final ResourceId format;
private final int version;
private final byte[] payload;
public BlockEntityData(ResourceId format, int version, byte[] payload) {
this.format = Objects.requireNonNull(format, "format");
if (version < 0) throw new IllegalArgumentException("Negative block entity format version");
this.version = version;
this.payload = Objects.requireNonNull(payload, "payload").clone();
}
public ResourceId format() { return format; }
public int version() { return version; }
public byte[] payload() { return payload.clone(); }
@Override
public boolean equals(Object other) {
return other instanceof BlockEntityData data && format.equals(data.format)
&& version == data.version && Arrays.equals(payload, data.payload);
}
@Override
public int hashCode() { return 31 * Objects.hash(format, version) + Arrays.hashCode(payload); }
}
@@ -0,0 +1,36 @@
package com.volmit.object;
import com.volmit.mantle.BlockBox;
import com.volmit.world.BlockPosition;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
/** Immutable sparse geometry, safe to cache per pack snapshot.
* Bounds are local, minima inclusive/maxima exclusive, and include blocks and markers.
* The anchor may lie outside the bounds. Placement aligns it with a requested world position.
* Blocks are sorted by x/y/z; duplicates fail. Marker order at an equal position is declaration
* order. This value contains no placement settings, random state, or native platform objects.
*/
public record GeneratedObject(BlockBox bounds, BlockPosition anchor,
List<ObjectBlock> blocks, List<ObjectMarker> markers) {
public GeneratedObject {
Objects.requireNonNull(bounds, "bounds");
Objects.requireNonNull(anchor, "anchor");
blocks = List.copyOf(blocks).stream().sorted(Comparator.comparing(ObjectBlock::position)).toList();
markers = List.copyOf(markers).stream().sorted(Comparator.comparing(ObjectMarker::position)).toList();
var positions = new HashSet<BlockPosition>();
for (var block : blocks) {
checkPosition(bounds, block.position());
if (!positions.add(block.position())) throw new IllegalArgumentException("Duplicate object block: " + block.position());
}
for (var marker : markers) checkPosition(bounds, marker.position());
}
private static void checkPosition(BlockBox bounds, BlockPosition position) {
if (!bounds.contains(position.x(), position.y(), position.z())) {
throw new IllegalArgumentException("Object entry outside bounds: " + position);
}
}
}
@@ -0,0 +1,17 @@
package com.volmit.object;
import com.volmit.block.BlockState;
import com.volmit.world.BlockPosition;
import java.util.Objects;
import java.util.Optional;
/** One sparse block in object-local coordinates. Absence is distinct from an explicit air block. */
public record ObjectBlock(BlockPosition position, BlockState state, Optional<BlockEntityData> blockEntity) {
public ObjectBlock {
Objects.requireNonNull(position, "position");
Objects.requireNonNull(state, "state");
Objects.requireNonNull(blockEntity, "blockEntity");
}
public ObjectBlock(BlockPosition position, BlockState state) { this(position, state, Optional.empty()); }
}
@@ -0,0 +1,12 @@
package com.volmit.object;
import com.volmit.generation.InvocationContext;
import com.volmit.random.WorldRandom;
/** Geometry-only invocation. The host chooses the variant seed and enforces size limits.
* Placement and terrain adaptation happen later; generators return reusable local geometry.
*/
public interface ObjectGenerationContext extends InvocationContext {
/** This generation's stream, seeded from the variant seed the host chose. Do not retain it. */
WorldRandom random();
}
@@ -0,0 +1,9 @@
package com.volmit.object;
/** Configured geometry generator. Snapshot settings; concurrent calls use only invocation-local
* state. Return a non-null object. The host owns variant selection and snapshot-scoped caching.
*/
@FunctionalInterface
public interface ObjectGenerator {
GeneratedObject generate(ObjectGenerationContext context);
}
@@ -0,0 +1,8 @@
package com.volmit.object;
import com.volmit.IrisFeature;
@FunctionalInterface
public interface ObjectGeneratorFactory<F extends IrisFeature> {
ObjectGenerator create(F feature);
}
@@ -0,0 +1,15 @@
package com.volmit.object;
import com.volmit.resource.ResourceId;
import com.volmit.world.BlockPosition;
import java.util.Map;
import java.util.Objects;
/** Immutable, named metadata in object-local coordinates. The registered host/module owns meaning. */
public record ObjectMarker(BlockPosition position, ResourceId type, Map<String, String> attributes) {
public ObjectMarker {
Objects.requireNonNull(position, "position");
Objects.requireNonNull(type, "type");
attributes = Map.copyOf(attributes);
}
}
@@ -0,0 +1,20 @@
package com.volmit.object;
/** Requested transform. The host owns rasterization, property orientation and interpolation.
* Rotation is in degrees about the object's anchor; mirrors precede scale, then X/Y/Z rotation.
* Unsupported transformations fail rather than silently changing the request.
*/
public record ObjectTransform(double rotationX, double rotationY, double rotationZ,
double scaleX, double scaleY, double scaleZ,
boolean mirrorX, boolean mirrorY, boolean mirrorZ) {
public ObjectTransform {
for (double angle : new double[]{rotationX, rotationY, rotationZ}) {
if (!Double.isFinite(angle)) throw new IllegalArgumentException("Non-finite rotation");
}
for (double scale : new double[]{scaleX, scaleY, scaleZ}) {
if (!Double.isFinite(scale) || scale <= 0) throw new IllegalArgumentException("Scale must be finite and positive");
}
}
public static ObjectTransform identity() { return new ObjectTransform(0, 0, 0, 1, 1, 1, false, false, false); }
}
@@ -0,0 +1,9 @@
package com.volmit.object;
/** Host adapter returning immutable transformed geometry with updated bounds, block properties,
* block entities and markers. Cache keys include pack snapshot, source geometry and transform.
*/
@FunctionalInterface
public interface ObjectTransformer {
GeneratedObject transform(GeneratedObject object, ObjectTransform transform);
}