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,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Human-readable documentation for a settings type or field. */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD})
public @interface Desc {
String value();
}
@@ -0,0 +1,28 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Identity and JSON attachment for an IrisFeature configuration class. The {@code id}, such as
* {@code "example:moss"}, is the feature's identity in the stage graph, logs and lookups by class. Packs write
* the settings under the short {@code key}, such as {@code "moss": {...}}, at each of the targets, the {@link Level}s
* of a pack's dimension, region, biome or object placement files.
*
* <p>The key is a plain JSON field name: not blank, no ':'. It is unique per target across all loaded modules
* and the JSON fields the host itself uses at that target, so it must not be a field of a biome, region or
* dimension; a clash refuses the pack load, naming both claimants.
*
* <p>The JSON under the key is an object of the class's options, unless {@code root} names an option. Then the
* key holds exactly that option's value, such as a list, and an object is not accepted: with
* {@code @Feature(id = "iris:deposit", key = "deposits", root = "generators", ...)} a pack writes
* {@code "deposits": [...]}. The class has no other option then, since nothing could set it.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Feature {
String id();
String name();
String key();
String root() default "";
/** The levels packs may write the settings at. */
Level[] targets();
}
@@ -0,0 +1,75 @@
package com.volmit.config;
import com.volmit.IrisFeature;
import com.volmit.generation.ChunkContext;
import com.volmit.resource.ResourceId;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
/** Invocation-scoped lookup of the settings that apply at one world column.
*
* <p>Every level that declares the settings contributes its own entry: the dimension, the region and
* the biome of the column, and in a placement the placement itself. Levels stack: nothing is merged or
* overridden, and a module decides what several entries mean, such as running a deposit once per
* entry. The biome is the column's surface biome; cave biomes are not a level. Values must be treated as
* read-only. Bounds and lifetime match the invocation's sampler.
*
* <p>Something that spans several columns, such as a chunk-wide pass or a placed object, reads the
* settings at one column it treats as its origin; per-chunk behaviour reads the chunk's centre column
* ({@link ChunkContext#centreX()}, {@link ChunkContext#centreZ()}).
*/
public interface FeatureSettings {
/** The entries of {@code featureType} at this column, in level order; empty when no level declares it. */
<F extends IrisFeature> SettingsStack<F> at(Class<F> featureType, int worldX, int worldZ);
/** Every distinct entry of {@code featureType} at the 16 by 16 columns of chunk {@code chunkX}, {@code chunkZ}, in
* level order; entries of one level in the order their first column was found, columns by X and then Z. Entries are
* distinct by level and source. The chunk and mantle runners decide with it whether a conditioned stage runs in a
* chunk. The default asks {@link #at} for every column; a host that knows which regions and biomes a chunk holds
* answers it from them.
*/
default <F extends IrisFeature> SettingsStack<F> declaredInChunk(Class<F> featureType, int chunkX, int chunkZ) {
var declarations = new HashSet<Declaration>();
var distinct = new ArrayList<Entry<F>>();
int originX = chunkX * ChunkContext.CHUNK_WIDTH;
int originZ = chunkZ * ChunkContext.CHUNK_WIDTH;
for (int x = 0; x < ChunkContext.CHUNK_WIDTH; x++) {
for (int z = 0; z < ChunkContext.CHUNK_WIDTH; z++) {
for (var entry : at(featureType, originX + x, originZ + z)) {
if (declarations.add(new Declaration(entry.level(), entry.source()))) {
distinct.add(entry);
}
}
}
}
return SettingsStack.of(distinct);
}
/** The settings {@code biome} declares itself, whichever column it is found at: for a biome that is not a column's
* surface biome, such as the cave biome of {@link com.volmit.world.BiomeSample#caveBiome()}, which is no level of
* {@link #at}. {@code biome} is an id as a {@code BiomeSample} gives it. Empty when the biome declares none, or the
* host knows no such biome.
*/
default <F extends IrisFeature> Optional<F> declaredBy(ResourceId biome, Class<F> featureType) {
return Optional.empty();
}
/** One level's declaration of the settings.
*
* @param level where the settings are declared: the dimension, a region, a biome or the placement
* @param source the resource that declares them, such as {@code overworld:biome/desert/dunes}
* @param value the decoded settings
*/
record Entry<F extends IrisFeature>(Level level, ResourceId source, F value) {
public Entry {
Objects.requireNonNull(level, "level");
Objects.requireNonNull(source, "source");
Objects.requireNonNull(value, "value");
}
}
}
/** What makes two entries of a chunk the same declaration. */
record Declaration(Level level, ResourceId source) {}
@@ -0,0 +1,7 @@
package com.volmit.config;
/** Where a pack declares settings, from the least to the most specific: the dimension, a region, a biome, and an
* object placement. {@link Feature#targets()} names the levels a feature may be written at, and every
* {@link FeatureSettings.Entry} carries the level that declared it. Settings stacks keep this order.
*/
public enum Level { DIMENSION, REGION, BIOME, PLACEMENT }
@@ -0,0 +1,39 @@
package com.volmit.config;
import com.volmit.IrisFeature;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import java.util.Collection;
import java.util.Set;
/**
* Implemented by settings that make pack biomes part of a pack's layout besides the ones its regions list: the biome
* that a cave band puts underground, or the target of a floating island. The host asks the settings of every dimension
* and biome it reaches, without knowing the module behind them, so such a biome is loaded, registered and given its own
* settings like any other. Biomes are named by their ids, {@link PackResources#idOf} of the keys the settings hold; ids
* naming no biome of the pack are ignored.
*/
public interface LinkedBiomes {
/**
* Biomes that join the biome tree of every region the owner is part of, like the owner's children: the host registers
* them with the region, so their terrain generators take part in the region's terrain.
*
* @param pack the pack the settings belong to, which turns their keys into ids
*/
default Set<ResourceId> treeBiomes(PackResources pack) {
return Set.of();
}
/**
* Biomes the settings use besides, which a dimension reaches (their objects, decorators and settings take part in
* generation) without joining the region's biome tree.
*
* @param pack the pack the settings belong to, which turns their keys into ids
* @param dimension the settings the owner's dimension declares, for settings that name something the dimension
* declares, such as a band of its caves
*/
default Set<ResourceId> usedBiomes(PackResources pack, Collection<IrisFeature> dimension) {
return Set.of();
}
}
@@ -0,0 +1,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Inclusive numeric upper bound. Enforcement belongs to the configuration loader. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MaxNumber {
double value();
}
@@ -0,0 +1,12 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Inclusive lower bound on the length of a list, set or array option, such as a palette that needs a block. Studio
* shows it ({@code minItems}); like {@link MinNumber}, enforcement belongs to the configuration loader.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MinItems {
int value();
}
@@ -0,0 +1,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Inclusive numeric lower bound. Enforcement belongs to the configuration loader. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MinNumber {
double value();
}
@@ -0,0 +1,28 @@
package com.volmit.config;
import com.volmit.IrisFeature;
import java.util.Optional;
/** Every settings declaration of the pack the host is loading, for what depends on the whole pack rather
* than one column, such as how far a mantle stage reaches ({@link com.volmit.stage.PackReach}).
*
* <p>The levels are those chunk and mantle stages see: the dimension being generated, and every region
* and biome it can reach. Placements are not a level here. Values must be treated as read-only and not
* retained.
*/
public interface PackSettings {
/** Every entry of {@code featureType} the pack declares, dimension first, then regions, then biomes;
* empty when nothing declares it.
*/
<F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType);
/**
* What the host offers for the pack it is loading beyond the API, as an object of {@code type}: empty when it offers
* no such thing. The same door as {@link com.volmit.world.PackWorld#extension}, for what is worked out from the
* settings before any world generates, such as a {@link com.volmit.stage.PackReach} that needs the size of the pack's
* objects from the host.
*/
default <T> Optional<T> extension(Class<T> type) {
return Optional.empty();
}
}
@@ -0,0 +1,68 @@
package com.volmit.config;
import com.volmit.random.WorldRandom;
import java.util.Objects;
/** A span of numbers from {@code min} to {@code max}, both included, as packs write it: {@code {"min": 0, "max": 15}},
* or a snippet under {@code snippet/range/}. An omitted bound keeps its default, so give a settings field its own
* default with {@link #of}. A value the host creates with the no-argument constructor and reads the JSON into.
*/
@Snippet("range")
@Desc("Represents a range")
public final class Range {
@Desc("The minimum value")
private double min = 16;
@Desc("The maximum value")
private double max = 32;
private Range() {
}
private Range(double min, double max) {
this.min = min;
this.max = max;
}
public static Range of(double min, double max) {
return new Range(min, max);
}
public double min() {
return min;
}
public double max() {
return max;
}
/** Whether {@code value} lies between the bounds, both included. */
public boolean contains(double value) {
return value >= min && value <= max;
}
/** A number between the bounds drawn from {@code random}: {@code min + nextDouble() * (max - min)}, one draw,
* or {@code min} without a draw when the bounds are equal.
*/
public double pick(WorldRandom random) {
if (min == max) {
return min;
}
return min + random.nextDouble() * (max - min);
}
@Override
public boolean equals(Object other) {
return other instanceof Range that && Double.compare(min, that.min) == 0 && Double.compare(max, that.max) == 0;
}
@Override
public int hashCode() {
return Objects.hash(min, max);
}
@Override
public String toString() {
return "Range[" + min + ".." + max + "]";
}
}
@@ -0,0 +1,13 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Says what an option's text names, such as {@code @Ref(Reference.BLOCK) String block}. Allowed on
* {@code String} and {@link com.volmit.resource.ResourceId} options and on lists, sets and arrays of
* them, where it applies to every element. Anywhere else it fails the pack load.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Ref {
Reference value();
}
@@ -0,0 +1,48 @@
package com.volmit.config;
/** What a text option names, so studio can offer the matching completion list. Platform kinds name
* entries of the server's registries, such as {@code minecraft:stone}, including those that data
* packs and mods add. Pack kinds name resources of the pack being edited. The set is closed: every
* kind is one the Iris host can list.
*/
public enum Reference {
/** A block type, such as {@code minecraft:stone}. {@link com.volmit.block.BlockState} options are block references without {@link Ref}. */
BLOCK,
/** An item type, such as {@code minecraft:stick}. */
ITEM,
/** An entity type, such as {@code minecraft:zombie}. */
ENTITY,
/** A platform biome, such as {@code minecraft:plains}; not a biome of the pack. */
BIOME,
/** A platform structure, such as {@code minecraft:village_plains}. */
STRUCTURE,
/** A platform structure or a prefix naming a family of them: {@code minecraft:village_plains},
* {@code minecraft:village} (every village) or {@code nova_structures:} (a whole namespace). */
STRUCTURE_PREFIX,
/** A platform structure set, such as {@code minecraft:villages}. */
STRUCTURE_SET,
/** A platform jigsaw template pool, such as {@code minecraft:village/plains/town_centers}. */
TEMPLATE_POOL,
/** A potion effect type, such as {@code minecraft:speed}. */
POTION_EFFECT,
/** An enchantment, such as {@code minecraft:sharpness}. */
ENCHANTMENT,
/** A loot table of the platform, such as {@code minecraft:chests/simple_dungeon}; not a loot table of the pack. */
LOOT_TABLE,
/** A mob of another plugin or content provider, such as {@code mythicmobs:skeleton_king}. */
SPECIAL_ENTITY,
/** A biome of the pack. */
PACK_BIOME,
/** A region of the pack. */
PACK_REGION,
/** An object of the pack. */
PACK_OBJECT,
/** One of the host's noise styles, such as {@code SIMPLEX}; see {@link com.volmit.noise.NoiseStyle}. */
NOISE_STYLE,
/** An expression of the pack. */
PACK_EXPRESSION,
/** An image map of the pack. */
PACK_IMAGE_MAP,
/** A jigsaw structure of the pack. */
PACK_STRUCTURE
}
@@ -0,0 +1,8 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Declares that a field must be supplied in configuration. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Required {}
@@ -0,0 +1,14 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Says that an option names a resource of the module resource kind read into {@code value}, by its key in the
* pack, such as {@code @ResourceRef(Pool.class) String startPool = "castle/start"}. Studio then offers the keys
* of that kind's files. Allowed on {@code String} options and lists, sets and arrays of them; the class must be
* the type of a resource kind some module of the pack registers. Anywhere else it fails the pack load.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ResourceRef {
Class<?> value();
}
@@ -0,0 +1,105 @@
package com.volmit.config;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/** The entries of one settings type that apply somewhere, in {@link Level} order: what a column stacks
* ({@link FeatureSettings#at}), what a chunk or a placement configures ({@link com.volmit.stage.StageContext#configured})
* or what a pack declares ({@link PackSettings#declared}). Levels stack and nothing is merged, so a module picks what it
* needs: every entry, the dimension's, the most specific one. Several entries may share a level, such as the biomes of
* a chunk or of a pack; they keep the order they were found in.
*
* <p>An immutable value; equal when the entries are equal. Hosts build it with {@link #of}.
*/
public final class SettingsStack<F extends IrisFeature> implements Iterable<Entry<F>> {
private static final SettingsStack<?> EMPTY = new SettingsStack<>(List.of());
private static final Comparator<Entry<?>> LEVEL_ORDER = Comparator.comparing(Entry::level);
private final List<Entry<F>> entries;
private final List<F> values;
private SettingsStack(List<Entry<F>> entries) {
this.entries = entries;
this.values = entries.stream().map(Entry::value).toList();
}
@SuppressWarnings("unchecked") // The empty stack holds no entry of any type.
public static <F extends IrisFeature> SettingsStack<F> empty() {
return (SettingsStack<F>) EMPTY;
}
/** These entries in level order; entries of one level keep the order given. */
public static <F extends IrisFeature> SettingsStack<F> of(List<? extends Entry<F>> entries) {
Objects.requireNonNull(entries, "entries");
if (entries.isEmpty()) {
return empty();
}
var sorted = new ArrayList<Entry<F>>(entries);
sorted.forEach(entry -> Objects.requireNonNull(entry, "entry"));
sorted.sort(LEVEL_ORDER);
return new SettingsStack<>(List.copyOf(sorted));
}
public boolean isEmpty() {
return entries.isEmpty();
}
/** Every entry, in level order. */
public List<Entry<F>> entries() {
return entries;
}
/** Every entry's value, in level order. */
public List<F> values() {
return values;
}
/** The dimension's value; empty when the dimension declares none. */
public Optional<F> dimension() {
return level(Level.DIMENSION);
}
/** The first value declared at {@code level}; empty when that level declares none. */
public Optional<F> level(Level level) {
Objects.requireNonNull(level, "level");
for (var entry : entries) {
if (entry.level() == level) {
return Optional.of(entry.value());
}
}
return Optional.empty();
}
/** The value of the last entry, the most specific level's (a placement before a biome before a region before the
* dimension); empty when the stack is.
*/
public Optional<F> mostSpecific() {
return entries.isEmpty() ? Optional.empty() : Optional.of(entries.getLast().value());
}
@Override
public Iterator<Entry<F>> iterator() {
return entries.iterator();
}
@Override
public boolean equals(Object other) {
return other instanceof SettingsStack<?> stack && entries.equals(stack.entries);
}
@Override
public int hashCode() {
return entries.hashCode();
}
@Override
public String toString() {
return "SettingsStack" + entries;
}
}
@@ -0,0 +1,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Identifies a reusable settings snippet. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Snippet {
String value();
}