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,18 @@
package com.volmit.noise;
/** Builds noise from styles a pack describes. Noise is the host's: modules describe it with {@link NoiseStyle} in
* their settings and get samplers from here ({@link com.volmit.resource.PackResources#noise()}), never the host's
* noise classes. Safe for concurrent calls.
*/
public interface NoiseFactory {
/** The noise {@code style} describes, seeded with {@code seed}. The same style and seed give the same values
* in every world of the pack, so derive the seed from the world seed ({@code context.world().seed()}), not from a
* stage's random stream, when the noise must line up across chunks. The host keeps what it builds for the pack
* snapshot, so asking again for the same style and seed is cheap.
*
* <p>A style name the host does not know samples as {@link NoiseStyle#FLAT}, and an expression the pack does not
* have falls back to the base style, as packs have always been read. An image map the pack does not have, or cannot
* use as noise, throws {@link IllegalArgumentException}.
*/
NoiseSampler sampler(NoiseStyle style, long seed);
}
@@ -0,0 +1,56 @@
package com.volmit.noise;
/** Immutable, seeded noise the host built from a {@link NoiseStyle} ({@link NoiseFactory#sampler}). X and Z are
* world coordinates; Y is the height above the dimension's bottom (0 = bottom). The host's own styles give values
* from 0 to 1; expressions and image maps give what they compute. Two-dimensional and three-dimensional samples
* are separate fields, so {@code sample(x, z)} is not {@code sample(x, 0, z)}. Safe for concurrent calls.
*/
public interface NoiseSampler {
double sample(double worldX, double worldZ);
double sample(double worldX, double y, double worldZ);
/** {@link #sample(double, double)} mapped from 0..1 to -1..1 ({@code sample * 2 - 1}), for noise that is added up
* and compared around zero. A host may answer a repeated read of the same coordinates from a per-thread memo, so a
* caller that samples the same field at the same points again and again (a carver testing densities) should read
* this instead of mapping {@link #sample(double, double)} itself.
*/
default double signed(double worldX, double worldZ) {
return sample(worldX, worldZ) * 2D - 1D;
}
/** The three-dimensional counterpart of {@link #signed(double, double)}. */
default double signed(double worldX, double y, double worldZ) {
return sample(worldX, y, worldZ) * 2D - 1D;
}
/** This noise with its coordinates multiplied by {@code factor}: a factor above 1 squeezes the pattern, below 1
* stretches it. A host folds the factor into the generator's own scale, so the result is the very noise the style
* would give with that extra scale (same values and float rounding), and builds it without touching this sampler.
* The default multiplies the coordinates before sampling, which may round differently.
*/
default NoiseSampler scaled(double factor) {
NoiseSampler source = this;
return new NoiseSampler() {
@Override
public double sample(double worldX, double worldZ) {
return source.sample(worldX * factor, worldZ * factor);
}
@Override
public double sample(double worldX, double y, double worldZ) {
return source.sample(worldX * factor, y * factor, worldZ * factor);
}
@Override
public double signed(double worldX, double worldZ) {
return source.signed(worldX * factor, worldZ * factor);
}
@Override
public double signed(double worldX, double y, double worldZ) {
return source.signed(worldX * factor, y * factor, worldZ * factor);
}
};
}
}
@@ -0,0 +1,164 @@
package com.volmit.noise;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.config.Ref;
import com.volmit.config.Reference;
import com.volmit.config.Snippet;
import java.util.Objects;
import java.util.Optional;
/** How noise is shaped, as packs write it: {@code {"style": "SIMPLEX", "zoom": 4}}, or a snippet under
* {@code snippet/style/}. The style names one of the host's noise generators ({@link Reference#NOISE_STYLE}); an
* expression or image map of the pack replaces it. A zoom stretches the noise, an exponent bends it, a fracture
* style distorts its coordinates and a cellular frequency turns it into cells.
*
* <p>A style is a description, not noise: the host builds the noise ({@link NoiseFactory#sampler}). It is a value
* the host creates with the no-argument constructor and reads the JSON into; nothing changes it afterwards.
*/
@Snippet("style")
@Desc("A noise style: one of the host's noise generators, or an expression or image map of the pack, shaped by zoom, exponent, fracture and cells")
public final class NoiseStyle {
/** The style without noise, the default. */
public static final String FLAT = "FLAT";
@Ref(Reference.NOISE_STYLE)
@Desc("The base noise style. Used when neither expression nor imageMap is set; a failed expression also falls back to this style.")
private String style = FLAT;
@Desc("If set above 0, this style will be cellularized")
private double cellularFrequency = 0;
@Desc("Cell zooms")
private double cellularZoom = 1;
@MinNumber(0.00001)
@Desc("The zoom of this style")
private double zoom = 1;
@Ref(Reference.PACK_EXPRESSION)
@Desc("Instead of using the style property, use a custom expression to represent this style.")
private String expression;
@Ref(Reference.PACK_IMAGE_MAP)
@Desc("Use an Image map instead of a generated value")
private String imageMap;
@MinNumber(0.00001)
@Desc("The Output multiplier. Only used if parent is fracture.")
private double multiplier = 1;
@Desc("Apply a generator to the coordinate field fed into this parent generator. I.e. Distort your generator with another generator.")
private NoiseStyle fracture;
@MinNumber(0.01562)
@MaxNumber(64)
@Desc("The exponent")
private double exponent = 1;
@MinNumber(0)
@MaxNumber(8192)
@Desc("If the cache size is set above 0, this generator will be cached")
private int cacheSize = 0;
private NoiseStyle() {
}
private NoiseStyle(NoiseStyle copy) {
style = copy.style;
cellularFrequency = copy.cellularFrequency;
cellularZoom = copy.cellularZoom;
zoom = copy.zoom;
expression = copy.expression;
imageMap = copy.imageMap;
multiplier = copy.multiplier;
fracture = copy.fracture;
exponent = copy.exponent;
cacheSize = copy.cacheSize;
}
/** The host's noise style {@code style}, such as {@code SIMPLEX}, with every other option at its default. */
public static NoiseStyle of(String style) {
var created = new NoiseStyle();
created.style = Objects.requireNonNull(style, "style");
return created;
}
/** This style with zoom {@code zoom}: above 1 stretches the noise, below 1 squeezes it. */
public NoiseStyle withZoom(double zoom) {
var changed = new NoiseStyle(this);
changed.zoom = zoom;
return changed;
}
/** The base style's name; {@link #FLAT} where the pack wrote none. */
public String style() {
return style == null ? FLAT : style;
}
public double cellularFrequency() {
return cellularFrequency;
}
public double cellularZoom() {
return cellularZoom;
}
public double zoom() {
return zoom;
}
/** The key of the pack expression that replaces the base style. */
public Optional<String> expression() {
return Optional.ofNullable(expression);
}
/** The key of the pack image map that replaces the base style when there is no expression. */
public Optional<String> imageMap() {
return Optional.ofNullable(imageMap);
}
public double multiplier() {
return multiplier;
}
public Optional<NoiseStyle> fracture() {
return Optional.ofNullable(fracture);
}
public double exponent() {
return exponent;
}
public int cacheSize() {
return cacheSize;
}
/** Whether the style gives no noise: the {@link #FLAT} base style without an expression or image map. */
public boolean isFlat() {
return FLAT.equals(style()) && expression == null && imageMap == null;
}
@Override
public boolean equals(Object other) {
return other instanceof NoiseStyle that && style().equals(that.style())
&& Double.compare(cellularFrequency, that.cellularFrequency) == 0
&& Double.compare(cellularZoom, that.cellularZoom) == 0 && Double.compare(zoom, that.zoom) == 0
&& Objects.equals(expression, that.expression) && Objects.equals(imageMap, that.imageMap)
&& Double.compare(multiplier, that.multiplier) == 0 && Objects.equals(fracture, that.fracture)
&& Double.compare(exponent, that.exponent) == 0 && cacheSize == that.cacheSize;
}
@Override
public int hashCode() {
return Objects.hash(style(), cellularFrequency, cellularZoom, zoom, expression, imageMap, multiplier, fracture,
exponent, cacheSize);
}
@Override
public String toString() {
return "NoiseStyle[" + style() + expression().map(key -> ", expression " + key).orElse("")
+ imageMap().map(key -> ", image map " + key).orElse("") + ", zoom " + zoom + "]";
}
}
@@ -0,0 +1,85 @@
package com.volmit.noise;
import com.volmit.config.Desc;
import com.volmit.config.Snippet;
import java.util.Objects;
/** A number between {@code min} and {@code max} that a noise style picks per column, as packs write it:
* {@code {"min": 4, "max": 12, "style": {"style": "SIMPLEX"}}}, or a snippet under {@code snippet/style-range/}.
* A value the host creates with the no-argument constructor and reads the JSON into.
*/
@Snippet("style-range")
@Desc("Represents a range styled with a custom generator")
public final class StyledRange {
private static final String DEFAULT_STYLE = "STATIC";
@Desc("The minimum value")
private double min = 16;
@Desc("The maximum value")
private double max = 32;
@Desc("The style to pick the range")
private NoiseStyle style = NoiseStyle.of(DEFAULT_STYLE);
private StyledRange() {
}
private StyledRange(double min, double max, NoiseStyle style) {
this.min = min;
this.max = max;
this.style = Objects.requireNonNull(style, "style");
}
public static StyledRange of(double min, double max, NoiseStyle style) {
return new StyledRange(min, max, style);
}
public double min() {
return min;
}
public double max() {
return max;
}
/** The style; {@link NoiseStyle#FLAT} where the pack wrote {@code null}. */
public NoiseStyle style() {
return style == null ? NoiseStyle.of(NoiseStyle.FLAT) : style;
}
/** Whether every column gets the same value: the bounds are equal or the style is flat. */
public boolean isFlat() {
return min == max || style().isFlat();
}
/** The value at column {@code worldX}, {@code worldZ}: {@code min} when the bounds are equal, halfway between
* them when the style is flat, otherwise {@code min + (max - min) * noise} of the style's noise seeded with
* {@code seed}.
*/
public double at(NoiseFactory noise, long seed, double worldX, double worldZ) {
if (min == max) {
return min;
}
if (style().isFlat()) {
return (min + max) / 2;
}
return min + (max - min) * noise.sampler(style(), seed).sample(worldX, worldZ);
}
@Override
public boolean equals(Object other) {
return other instanceof StyledRange that && Double.compare(min, that.min) == 0
&& Double.compare(max, that.max) == 0 && style().equals(that.style());
}
@Override
public int hashCode() {
return Objects.hash(min, max, style());
}
@Override
public String toString() {
return "StyledRange[" + min + ".." + max + ", " + style() + "]";
}
}