Let every number that shapes a cave vary across the world

A cave value is a plain number, {min, max} that a smooth noise picks
from, or {min, max, style} where the pack's style picks. The noise's low
end gives min and its high end max. A plain number keeps the constant
path, and the carver checks for constants so they cost no more than
before. Each varying value has its own seed, named after its key, so
writing a range leaves every other field of the cave where it was.

The form covers fade, surfaceClearance and both ends of depth on the
cave; width, height, the coverage share and verticalWarp on tunnels;
size, height, coverage and roughness on caverns; spacing, thickness,
flare and vertical on pillars. Three constants become keys with
defaults that carve what they did: ceilingFade (8 blocks),
verticalWarp (0.5) and the coverage softness (0.3, an edge of 0.15).
Roughness (0.3) replaces the fixed wall detail. Tunnel coverage also
takes a plain number as the share.

Sizes do not stretch the noise, which sheared rooms into air pockets
and floating rock. A size or height that varies blends a field built at
min with one built at max, so each varying size doubles the fields read.
With size, height or roughness varying the coverage share is
approximate: a size range carves about 14% more than its ends average.

JsonForms codecs get Parts, which read a part of a form as the host
reads that type anywhere else. A cave value's style can then name a
pack's expression. A cave value is not a number to the host's bounds
check, so a validator reports values outside their key's range.

natureplanet's four cave files carve block for block what they carved
before, and the first pass's five pinned caves still match.
This commit is contained in:
piexel committed 2026-11-13 20:02:15 +01:00
1 parent 5695cf053e
commit 8e19a7ed63
26 files changed
+2028 -238

No files matched your search

@@ -28,6 +28,7 @@ import art.arcane.iris.builtin.carve.CaveLavaHeightSettings;
import art.arcane.iris.modules.carve.CaveList;
import art.arcane.iris.modules.carve.CaveResources;
import art.arcane.iris.modules.carve.CaveScenes;
import art.arcane.iris.modules.carve.CaveValidator;
import art.arcane.iris.modules.carve.UpperDimensionCarvingSettings;
import art.arcane.iris.modules.terrain.TerrainPalettes;
import art.arcane.iris.engine.mantle.components.CarveWorld;
@@ -77,6 +78,7 @@ public final class CarveModule implements IrisModule {
log = setup.log();
var registry = setup.registry();
registry.registerResourceKind(CaveResources.CAVES);
registry.registerValidator(new CaveValidator());
setup.tooling().registerView(new CaveScenes());
List.of(CaveList.class, CarvingSettings.class, CarvingEnabledSettings.class, CarvingBiomeSettings.class,
CaveDepthSettings.class, CaveLavaHeightSettings.class, UpperDimensionCarvingSettings.class)
@@ -224,7 +224,7 @@ public final class ProceduralValue {
private static final double DEFAULT_TO = 1;
@Override
public ProceduralValue read(Object json) {
public ProceduralValue read(Object json, JsonForms.Parts parts) {
return new ProceduralValue(json, formOf(json));
}
@@ -18,21 +18,28 @@
package art.arcane.iris.modules.carve;
import art.arcane.iris.modules.carve.CaveValue.Bounds;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.config.Range;
import com.volmit.config.ResourceRef;
import com.volmit.world.PackBiome;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* One kind of cave, a file of a pack's {@code caves/} folder that dimensions, regions and biomes list under {@code caves}.
* It carves tunnels, caverns or both, within a depth range and under the surface rules it sets.
* It carves tunnels, caverns or both, within a depth range and under the surface rules it sets. Every number that
* shapes the cave is a {@link CaveValue}, so it may vary across the world.
*/
@Desc("One kind of cave: tunnels, caverns or both, with where they may occur.")
public final class Cave {
/** Without a style, a value of the whole cave changes over about this many blocks. */
public static final int VALUE_CHANGE_BLOCKS = 256;
private static final Bounds FADE_BLOCKS = new Bounds(0, 128);
private static final Bounds SURFACE_CLEARANCE_BLOCKS = new Bounds(0, 128);
private static final Bounds CEILING_FADE_BLOCKS = new Bounds(0, 128);
@Desc("Winding tunnels. Leave out for a cave without tunnels.")
private CaveTunnel tunnel;
@@ -40,17 +47,19 @@ public final class Cave {
private CaveCavern cavern;
@Desc("World Y range this cave occurs in. Leave out to allow every height.")
private Range depth;
private CaveDepth depth;
@MinNumber(0)
@MaxNumber(128)
@Desc("Blocks over which the cave narrows to nothing at both ends of its depth range.")
private int fade = 12;
@Desc("Blocks over which the cave narrows to nothing at both ends of its depth range, 0 to 128. A range changes over about "
+ VALUE_CHANGE_BLOCKS + " blocks.")
private CaveValue fade = CaveValue.of(12);
@MinNumber(0)
@MaxNumber(128)
@Desc("Blocks of rock kept between the cave and the surface. Ignored when opensToSurface is set.")
private int surfaceClearance = 8;
@Desc("Blocks of rock kept between the cave and the surface, 0 to 128. Ignored when opensToSurface is set. A range changes over about "
+ VALUE_CHANGE_BLOCKS + " blocks.")
private CaveValue surfaceClearance = CaveValue.of(8);
@Desc("Blocks over which the cave closes under the rock it keeps, instead of ending in a flat ceiling, 0 to 128. Ignored where it opens to the surface. A range changes over about "
+ VALUE_CHANGE_BLOCKS + " blocks.")
private CaveValue ceilingFade = CaveValue.of(8);
@Desc("Let the cave cut through the surface, which makes entrances wherever it reaches the top.")
private boolean opensToSurface = false;
@@ -70,18 +79,22 @@ public final class Cave {
return Optional.ofNullable(cavern);
}
public Optional<Range> depth() {
public Optional<CaveDepth> depth() {
return Optional.ofNullable(depth);
}
public int fade() {
public CaveValue fade() {
return fade;
}
public int surfaceClearance() {
public CaveValue surfaceClearance() {
return surfaceClearance;
}
public CaveValue ceilingFade() {
return ceilingFade;
}
public boolean opensToSurface() {
return opensToSurface;
}
@@ -89,4 +102,15 @@ public final class Cave {
public String biome() {
return biome == null ? "" : biome;
}
/** Each value of the cave outside the numbers its key allows, such as {@code fade is 200; it must be at most 128}. */
public List<String> valuesOutOfBounds() {
List<String> problems = new ArrayList<>();
fade.requireWithin(FADE_BLOCKS, "fade", problems);
surfaceClearance.requireWithin(SURFACE_CLEARANCE_BLOCKS, "surfaceClearance", problems);
ceilingFade.requireWithin(CEILING_FADE_BLOCKS, "ceilingFade", problems);
tunnel().ifPresent(caveTunnel -> caveTunnel.requireValuesWithinBounds("tunnel", problems));
cavern().ifPresent(caveCavern -> caveCavern.requireValuesWithinBounds("cavern", problems));
return problems;
}
}
@@ -18,30 +18,36 @@
package art.arcane.iris.modules.carve;
import art.arcane.iris.modules.carve.CaveValue.Bounds;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.noise.NoiseStyle;
import java.util.List;
import java.util.Optional;
/** The caverns of a {@link Cave}: large open rooms, with pillars left standing in them where the cave asks for some. */
@Desc("Large open rooms.")
public final class CaveCavern {
@MinNumber(16)
@MaxNumber(512)
@Desc("Rough span of a room in blocks.")
private int size = 56;
/** Without a style, a value of the caverns or their pillars changes over this many room sizes. */
public static final int VALUE_CHANGE_SIZES = 4;
private static final Bounds SIZE_BLOCKS = new Bounds(16, 512);
private static final Bounds HEIGHT_BLOCKS = new Bounds(8, 256);
private static final Bounds COVERAGE_SHARE = new Bounds(0, 0.6);
private static final Bounds ROUGHNESS = new Bounds(0, 1);
@MinNumber(8)
@MaxNumber(256)
@Desc("Rough height of a room in blocks.")
private int height = 22;
@Desc("Rough span of a room in blocks, 16 to 512. A range changes over about " + VALUE_CHANGE_SIZES + " room sizes.")
private CaveValue size = CaveValue.of(56);
@MinNumber(0)
@MaxNumber(0.6)
@Desc("Share of the underground that is cavern. 0.1 gives scattered rooms, 0.3 joins them into halls.")
private double coverage = 0.1;
@Desc("Rough height of a room in blocks, 8 to 256. A range changes over about " + VALUE_CHANGE_SIZES + " room sizes.")
private CaveValue height = CaveValue.of(22);
@Desc("Share of the underground that is cavern, 0 to 0.6. 0.1 gives scattered rooms, 0.3 joins them into halls. A range changes over about "
+ VALUE_CHANGE_SIZES + " room sizes; a min of 0 leaves areas without rooms. A range in size, height or roughness makes the share approximate.")
private CaveValue coverage = CaveValue.of(0.1);
@Desc("Strength of the finer noise on room walls, 0 to 1. 0 gives smooth bubbles. Ignored with a style, and in rooms under about 20 blocks tall or across. A range changes over about "
+ VALUE_CHANGE_SIZES + " room sizes.")
private CaveValue roughness = CaveValue.of(0.3);
@Desc("Noise that shapes the rooms. Scaled to size and height, so its zoom has no effect; a fracture stays in blocks. Detail under about 12 blocks is lost. Leave out for smooth rooms with rough walls.")
private NoiseStyle style;
@@ -57,19 +63,31 @@ public final class CaveCavern {
return Optional.ofNullable(style);
}
public int size() {
public CaveValue size() {
return size;
}
public int height() {
public CaveValue height() {
return height;
}
public double coverage() {
public CaveValue coverage() {
return coverage;
}
public CaveValue roughness() {
return roughness;
}
public Optional<CavePillars> pillars() {
return Optional.ofNullable(pillars);
}
void requireValuesWithinBounds(String path, List<String> problems) {
size.requireWithin(SIZE_BLOCKS, path + ".size", problems);
height.requireWithin(HEIGHT_BLOCKS, path + ".height", problems);
coverage.requireWithin(COVERAGE_SHARE, path + ".coverage", problems);
roughness.requireWithin(ROUGHNESS, path + ".roughness", problems);
pillars().ifPresent(cavernPillars -> cavernPillars.requireValuesWithinBounds(path + ".pillars", problems));
}
}
@@ -0,0 +1,42 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modules.carve;
import com.volmit.config.Desc;
/** The world Y range a {@link Cave} occurs in. Either end may vary across the world. */
@Desc("World Y range a cave occurs in.")
public final class CaveDepth {
@Desc("Lowest world Y. A range changes over about " + Cave.VALUE_CHANGE_BLOCKS + " blocks.")
private CaveValue min = CaveValue.of(16);
@Desc("Highest world Y. A range changes over about " + Cave.VALUE_CHANGE_BLOCKS + " blocks.")
private CaveValue max = CaveValue.of(32);
public CaveDepth() {
}
public CaveValue min() {
return min;
}
public CaveValue max() {
return max;
}
}
@@ -18,36 +18,35 @@
package art.arcane.iris.modules.carve;
import art.arcane.iris.modules.carve.CaveValue.Bounds;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.noise.NoiseStyle;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
/** The pillars of a {@link CaveCavern}: columns of rock left standing from floor to ceiling. */
@Desc("Rock columns left standing inside caverns.")
public final class CavePillars {
@MinNumber(6)
@MaxNumber(256)
@Desc("Rough distance between pillars in blocks.")
private int spacing = 22;
private static final Bounds SPACING_BLOCKS = new Bounds(6, 256);
private static final Bounds THICKNESS_BLOCKS = new Bounds(1, 64);
private static final Bounds FLARE = new Bounds(1, 16);
private static final Bounds VERTICAL_BLOCKS = new Bounds(8, 512);
@MinNumber(1)
@MaxNumber(64)
@Desc("Rough thickness of a pillar at its middle, in blocks. Pillars widen towards floor and ceiling.")
private int thickness = 4;
@Desc("Rough distance between pillars in blocks, 6 to 256. A range changes over about " + CaveCavern.VALUE_CHANGE_SIZES + " room sizes.")
private CaveValue spacing = CaveValue.of(22);
@MinNumber(1)
@MaxNumber(16)
@Desc("How many times more ground a pillar covers at floor and ceiling than at its middle. 1 gives straight columns.")
private double flare = 4;
@Desc("Rough thickness of a pillar at its middle, in blocks, 1 to 64. Pillars widen towards floor and ceiling. A range changes over about "
+ CaveCavern.VALUE_CHANGE_SIZES + " room sizes.")
private CaveValue thickness = CaveValue.of(4);
@MinNumber(8)
@MaxNumber(512)
@Desc("Blocks over which the pillars change with height, so they lean, pinch and break off. Detail under about 12 blocks is lost. Leave out for columns that run straight from floor to ceiling.")
private Integer vertical;
@Desc("How many times more ground a pillar covers at floor and ceiling than at its middle, 1 to 16. 1 gives straight columns. A range changes over about "
+ CaveCavern.VALUE_CHANGE_SIZES + " room sizes.")
private CaveValue flare = CaveValue.of(4);
@Desc("Blocks over which the pillars change with height, 8 to 512, so they lean, pinch and break off. Detail under about 12 blocks is lost. A range changes over about "
+ CaveCavern.VALUE_CHANGE_SIZES + " room sizes. Leave out for columns that run straight from floor to ceiling.")
private CaveValue vertical;
@Desc("Noise that places the pillars. Scaled to spacing, so its zoom has no effect; a fracture stays in blocks. Leave out for evenly scattered pillars.")
private NoiseStyle style;
@@ -55,13 +54,13 @@ public final class CavePillars {
public CavePillars() {
}
public double flare() {
public CaveValue flare() {
return flare;
}
/** Blocks over which the pillars change with height; empty for pillars that run straight. */
public OptionalInt vertical() {
return vertical == null ? OptionalInt.empty() : OptionalInt.of(vertical);
public Optional<CaveValue> vertical() {
return Optional.ofNullable(vertical);
}
/** The noise that places the pillars; empty where the pack wrote none. */
@@ -69,11 +68,18 @@ public final class CavePillars {
return Optional.ofNullable(style);
}
public int spacing() {
public CaveValue spacing() {
return spacing;
}
public int thickness() {
public CaveValue thickness() {
return thickness;
}
void requireValuesWithinBounds(String path, List<String> problems) {
spacing.requireWithin(SPACING_BLOCKS, path + ".spacing", problems);
thickness.requireWithin(THICKNESS_BLOCKS, path + ".thickness", problems);
flare.requireWithin(FLARE, path + ".flare", problems);
vertical().ifPresent(blocks -> blocks.requireWithin(VERTICAL_BLOCKS, path + ".vertical", problems));
}
}
@@ -18,29 +18,30 @@
package art.arcane.iris.modules.carve;
import art.arcane.iris.modules.carve.CaveValue.Bounds;
import com.volmit.config.Desc;
import com.volmit.config.Range;
import com.volmit.config.Required;
import com.volmit.noise.NoiseStyle;
import com.volmit.noise.StyledRange;
import java.util.List;
import java.util.Optional;
/** The tunnels of a {@link Cave}: long winding passages. Thin ones link other caves together. */
@Desc("Long winding passages.")
public final class CaveTunnel {
private static final Range DEFAULT_WIDTH = Range.of(4, 7);
/**
* The style a styled range gets when the pack writes none: white noise, which would make a tunnel's width jump
* block by block. A width with this style follows the default width noise instead.
*/
private static final NoiseStyle STYLE_OF_A_RANGE_WRITTEN_WITHOUT_ONE = NoiseStyle.of("STATIC");
/** Without a style, the width changes over this many horizontal spacings. */
public static final double WIDTH_CHANGE_SPACINGS = 1.5D;
/** Without a style, any other value of the tunnels changes over this many horizontal spacings. */
public static final int VALUE_CHANGE_SPACINGS = 6;
private static final Bounds WIDTH_BLOCKS = new Bounds(1, 64);
private static final Bounds HEIGHT_BLOCKS = new Bounds(1, 64);
private static final Bounds VERTICAL_WARP_SHARE = new Bounds(0, 1);
@Desc("Tunnel width in blocks. The style picks where a tunnel is narrow or wide; leave it out for a slow change that scales with spacing.")
private StyledRange width;
@Desc("Tunnel width in blocks, 1 to 64. A range changes over about " + WIDTH_CHANGE_SPACINGS + " horizontal spacings.")
private CaveValue width = CaveValue.between(4, 7);
@Desc("Tunnel height in blocks, low where the tunnel is narrow and tall where it is wide. Leave out for round tunnels.")
private Range height;
@Desc("Tunnel height in blocks, 1 to 64. A range without a style follows the width: low where the tunnel is narrow, tall where it is wide. Leave out for round tunnels.")
private CaveValue height;
@Required
@Desc("Blocks between neighbouring tunnels.")
@@ -49,26 +50,23 @@ public final class CaveTunnel {
@Desc("Noise that bends the tunnels: zoom sets how often they turn, multiplier how many blocks they swing. A flat style keeps them straight. Leave out for a gentle bend that scales with spacing.")
private NoiseStyle warp;
@Desc("Where tunnels occur. Leave out to put them everywhere.")
@Desc("How far the warp moves tunnels up and down, as a share of how far it swings them sideways, 0 to 1. 0 adds no rise and fall. A range changes over about "
+ VALUE_CHANGE_SPACINGS + " horizontal spacings.")
private CaveValue verticalWarp = CaveValue.of(0.5);
@Desc("Where tunnels occur: a share of the underground from 0 to 1, or {share, softness, style}. Softness, 0 to 1, is how gradually tunnels thin out at the edge of an area, from abrupt dead ends to long tails; style is the noise that shapes the areas. Share and softness change over about "
+ VALUE_CHANGE_SPACINGS + " horizontal spacings as a range. Leave out to put tunnels everywhere.")
private CaveTunnelCoverage coverage;
public CaveTunnel() {
}
public Range width() {
return width == null ? DEFAULT_WIDTH : Range.of(width.min(), width.max());
public CaveValue width() {
return width;
}
/** The noise that picks the width along a tunnel; empty where the pack wrote none. */
public Optional<NoiseStyle> widthStyle() {
if (width == null || width.style().equals(STYLE_OF_A_RANGE_WRITTEN_WITHOUT_ONE)) {
return Optional.empty();
}
return Optional.of(width.style());
}
/** The height range of an oval tunnel; empty for a round one. */
public Optional<Range> height() {
/** The height of an oval tunnel; empty for a round one. */
public Optional<CaveValue> height() {
return Optional.ofNullable(height);
}
@@ -81,7 +79,18 @@ public final class CaveTunnel {
return Optional.ofNullable(warp);
}
public CaveValue verticalWarp() {
return verticalWarp;
}
public CaveTunnelCoverage coverage() {
return coverage == null ? new CaveTunnelCoverage() : coverage;
return coverage == null ? CaveTunnelCoverage.EVERYWHERE : coverage;
}
void requireValuesWithinBounds(String path, List<String> problems) {
width.requireWithin(WIDTH_BLOCKS, path + ".width", problems);
height().ifPresent(tunnelHeight -> tunnelHeight.requireWithin(HEIGHT_BLOCKS, path + ".height", problems));
verticalWarp.requireWithin(VERTICAL_WARP_SHARE, path + ".verticalWarp", problems);
coverage().requireValuesWithinBounds(path + ".coverage", problems);
}
}
@@ -18,33 +18,103 @@
package art.arcane.iris.modules.carve;
import art.arcane.iris.modules.carve.CaveValue.Bounds;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.config.JsonForms;
import com.volmit.noise.NoiseStyle;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/** Where the tunnels of a {@link CaveTunnel} occur: the share of the underground that has them, in patches a noise shapes. */
@Desc("Where tunnels occur.")
/**
* Where the tunnels of a {@link CaveTunnel} occur: the share of the underground that has them, in areas a noise shapes,
* and how gradually they thin out at the edge of an area. Written as the share alone, {@code 0.4}, or as
* {@code {"share": 0.4, "softness": 0.3, "style": {...}}} with each member optional.
*/
@Desc("Where tunnels occur: a share, or {share, softness, style}.")
@JsonForms(CaveTunnelCoverage.Forms.class)
public final class CaveTunnelCoverage {
@MinNumber(0)
@MaxNumber(1)
@Desc("Share of the underground that has tunnels. 1 puts them everywhere, lower leaves areas without any.")
private double share = 1;
/** The softness that thins tunnels out over the same stretch they always did before softness was a key. */
public static final double DEFAULT_SOFTNESS = 0.3D;
static final CaveTunnelCoverage EVERYWHERE = new CaveTunnelCoverage(1D, CaveValue.of(1), CaveValue.of(DEFAULT_SOFTNESS), null);
private static final Bounds SHARE = new Bounds(0, 1);
private static final Bounds SOFTNESS = new Bounds(0, 1);
@Desc("Noise that shapes the areas with tunnels. Leave out for patches that scale with spacing.")
private NoiseStyle style;
private final Object written;
private final CaveValue share;
private final CaveValue softness;
private final NoiseStyle style;
public CaveTunnelCoverage() {
private CaveTunnelCoverage(Object written, CaveValue share, CaveValue softness, NoiseStyle style) {
this.written = written;
this.share = share;
this.softness = softness;
this.style = style;
}
public double share() {
/** Share of the underground that has tunnels, from 0 to 1. */
public CaveValue share() {
return share;
}
/** How gradually tunnels thin out at the edge of an area, from 0 for abrupt ends to 1 for long tails. */
public CaveValue softness() {
return softness;
}
/** The noise that shapes the areas with tunnels; empty where the pack wrote none. */
public Optional<NoiseStyle> style() {
return Optional.ofNullable(style);
}
void requireValuesWithinBounds(String path, List<String> problems) {
share.requireWithin(SHARE, path + "." + Forms.SHARE, problems);
softness.requireWithin(SOFTNESS, path + "." + Forms.SOFTNESS, problems);
}
@Override
public String toString() {
return String.valueOf(written);
}
/** Reads the forms a pack writes and writes a coverage back exactly as it was read. */
static final class Forms implements JsonForms.Codec<CaveTunnelCoverage> {
static final String SHARE = "share";
static final String SOFTNESS = "softness";
static final String STYLE = "style";
private static final Set<String> MEMBERS = Set.of(SHARE, SOFTNESS, STYLE);
@Override
public CaveTunnelCoverage read(Object json, JsonForms.Parts parts) {
return switch (json) {
case Number number -> new CaveTunnelCoverage(json, CaveValue.of(number.doubleValue()), EVERYWHERE.softness, null);
case Map<?, ?> object -> spelledOut(object, parts);
default -> throw new IllegalArgumentException("A tunnel coverage is a share or {share, softness, style}, not " + json);
};
}
@Override
public Object write(CaveTunnelCoverage value) {
return value.written;
}
private static CaveTunnelCoverage spelledOut(Map<?, ?> object, JsonForms.Parts parts) {
for (Object member : object.keySet()) {
if (!MEMBERS.contains(member)) {
throw new IllegalArgumentException("A tunnel coverage has share, softness and style, not " + member);
}
}
CaveValue share = valueOrDefault(object.get(SHARE), EVERYWHERE.share, parts);
CaveValue softness = valueOrDefault(object.get(SOFTNESS), EVERYWHERE.softness, parts);
Object writtenStyle = object.get(STYLE);
NoiseStyle style = writtenStyle == null ? null : parts.read(writtenStyle, NoiseStyle.class);
return new CaveTunnelCoverage(object, share, softness, style);
}
private static CaveValue valueOrDefault(Object written, CaveValue fallback, JsonForms.Parts parts) {
return written == null ? fallback : parts.read(written, CaveValue.class);
}
}
}
@@ -0,0 +1,45 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modules.carve;
import com.volmit.resource.ResourceId;
import com.volmit.validation.Problem;
import com.volmit.validation.Subject;
import com.volmit.validation.ValidationContext;
import com.volmit.validation.Validator;
/**
* Module {@code iris:carve}'s check of a pack's caves: every value lies within the numbers its key allows. A
* {@link CaveValue} is not a plain number, so the host's own bounds check cannot see it.
*/
public final class CaveValidator implements Validator {
private static final String JSON_EXTENSION = ".json";
@Override
public void validate(ValidationContext pack) {
for (ResourceId id : pack.resources().ids(CaveResources.CAVES)) {
Cave cave = CaveResources.cave(pack.resources(), id);
if (cave == null) {
continue;
}
Subject file = Subject.file(CaveResources.CAVES.folder() + "/" + id.path() + JSON_EXTENSION);
cave.valuesOutOfBounds().forEach(problem -> pack.report(Problem.error(file, problem)));
}
}
}
@@ -0,0 +1,164 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modules.carve;
import com.volmit.config.Desc;
import com.volmit.config.JsonForms;
import com.volmit.noise.NoiseStyle;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* A number that shapes how a cave looks, which may vary across the world: {@code 5} everywhere,
* {@code {"min": 3, "max": 9}} picked by a smooth noise the cave chooses for the key, or
* {@code {"min": 3, "max": 9, "style": {...}}} picked by that style, its zoom as written. The noise's low end gives
* min and its high end max.
*/
@Desc("A number, or {min, max} that varies across the world; add a style to decide where.")
@JsonForms(CaveValue.Forms.class)
public final class CaveValue {
private final Object written;
private final double min;
private final double max;
private final NoiseStyle style;
private CaveValue(Object written, double min, double max, NoiseStyle style) {
this.written = written;
this.min = min;
this.max = max;
this.style = style;
}
public static CaveValue of(double value) {
return new CaveValue(value, value, value, null);
}
public static CaveValue between(double min, double max) {
return new CaveValue(Map.of(Forms.MIN, min, Forms.MAX, max), min, max, null);
}
/** Whether the value differs from place to place; a plain number, or a min equal to max, does not. */
public boolean varies() {
return min != max;
}
/** The value where the noise is lowest; the value everywhere when it does not vary. */
public double min() {
return min;
}
/** The value where the noise is highest. */
public double max() {
return max;
}
public double middle() {
return (min + max) / 2D;
}
public double lowest() {
return Math.min(min, max);
}
public double highest() {
return Math.max(min, max);
}
/** The noise the pack chose to pick the value; empty where it wrote none and the cave picks a smooth one. */
public Optional<NoiseStyle> style() {
return Optional.ofNullable(style);
}
/** Adds to {@code problems} each end of the value outside {@code bounds}, naming it {@code path} as written. */
void requireWithin(Bounds bounds, String path, List<String> problems) {
if (!varies()) {
requireWithin(bounds, path, min, problems);
return;
}
requireWithin(bounds, path + "." + Forms.MIN, min, problems);
requireWithin(bounds, path + "." + Forms.MAX, max, problems);
}
private static void requireWithin(Bounds bounds, String path, double value, List<String> problems) {
if (value < bounds.least()) {
problems.add(path + " is " + shortNumber(value) + "; it must be at least " + shortNumber(bounds.least()));
} else if (value > bounds.most()) {
problems.add(path + " is " + shortNumber(value) + "; it must be at most " + shortNumber(bounds.most()));
}
}
private static String shortNumber(double value) {
return value == Math.rint(value) ? Long.toString((long) value) : Double.toString(value);
}
@Override
public String toString() {
return String.valueOf(written);
}
/** The numbers a key allows, both included. */
record Bounds(double least, double most) {
}
/** Reads the forms a pack writes and writes a value back exactly as it was read. */
static final class Forms implements JsonForms.Codec<CaveValue> {
static final String MIN = "min";
static final String MAX = "max";
static final String STYLE = "style";
private static final Set<String> MEMBERS = Set.of(MIN, MAX, STYLE);
@Override
public CaveValue read(Object json, JsonForms.Parts parts) {
return switch (json) {
case Number number -> new CaveValue(json, number.doubleValue(), number.doubleValue(), null);
case Map<?, ?> object -> varying(object, parts);
default -> throw new IllegalArgumentException("A cave value is a number or {min, max} with an optional style, not " + json);
};
}
@Override
public Object write(CaveValue value) {
return value.written;
}
private static CaveValue varying(Map<?, ?> object, JsonForms.Parts parts) {
for (Object member : object.keySet()) {
if (!MEMBERS.contains(member)) {
throw new IllegalArgumentException("A varying cave value has min, max and style, not " + member);
}
}
if (!object.containsKey(MIN) || !object.containsKey(MAX)) {
throw new IllegalArgumentException("A varying cave value needs both min and max: " + object);
}
Object writtenStyle = object.get(STYLE);
NoiseStyle style = writtenStyle == null ? null : parts.read(writtenStyle, NoiseStyle.class);
return new CaveValue(object, number(object.get(MIN), MIN), number(object.get(MAX), MAX), style);
}
private static double number(Object written, String name) {
if (written instanceof Number number) {
return number.doubleValue();
}
throw new IllegalArgumentException(name + " needs a number, not " + written);
}
}
}
@@ -19,11 +19,14 @@
package art.arcane.iris.modules.carve.field;
import art.arcane.iris.modules.carve.Cave;
import com.volmit.config.Range;
import art.arcane.iris.modules.carve.CaveDepth;
import art.arcane.iris.modules.carve.CaveValue;
import art.arcane.iris.modules.carve.field.CaveLimits.Columns;
import com.volmit.noise.NoiseFactory;
import com.volmit.resource.ResourceId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -31,15 +34,17 @@ import java.util.List;
* the heights it may carve at. Heights count from the dimension's bottom. Safe to use from several threads at once.
*/
public final class CaveCarver {
private static final int CHUNK_COLUMNS = 256;
/** Caves stay this far above the dimension's bottom, clear of the bedrock floor. */
private static final int ROCK_KEPT_ABOVE_BOTTOM_BLOCKS = 5;
private final List<PartShape> shapes = new ArrayList<>();
private final int depthMinY;
private final int depthMaxY;
private final int fadeBlocks;
private final int surfaceClearance;
private final int worldBottomY;
private final int worldHeight;
private final ValueField depthMin;
private final ValueField depthMax;
private final ValueField fade;
private final ValueField surfaceClearance;
private final ValueField ceilingFade;
private final boolean opensToSurface;
/**
@@ -49,16 +54,21 @@ public final class CaveCarver {
*/
public CaveCarver(Cave cave, NoiseFactory noise, long seed, int worldBottomY, int worldHeight) {
CaveNoise caveNoise = new CaveNoise(noise, seed);
this.worldBottomY = worldBottomY;
this.worldHeight = worldHeight;
CaveDepth depth = cave.depth().orElse(null);
this.depthMin = depth == null ? ValueField.constant(worldBottomY) : caveValue(depth.min(), caveNoise, "depth.min");
this.depthMax = depth == null ? ValueField.constant(worldBottomY + worldHeight - 1) : caveValue(depth.max(), caveNoise, "depth.max");
this.fade = caveValue(cave.fade(), caveNoise, "fade");
this.surfaceClearance = caveValue(cave.surfaceClearance(), caveNoise, "surfaceClearance");
this.ceilingFade = caveValue(cave.ceilingFade(), caveNoise, "ceilingFade");
this.opensToSurface = cave.opensToSurface();
cave.tunnel().ifPresent(tunnel -> shapes.add(new PartShape(CavePart.TUNNEL, new TunnelShape(caveNoise, tunnel))));
cave.cavern().ifPresent(cavern -> shapes.add(new PartShape(CavePart.CAVERN, new CavernShape(caveNoise, cavern))));
Range depth = cave.depth().orElse(null);
int lowest = depth == null ? 0 : (int) Math.floor(Math.min(depth.min(), depth.max())) - worldBottomY;
int highest = depth == null ? worldHeight - 1 : (int) Math.ceil(Math.max(depth.min(), depth.max())) - worldBottomY;
this.depthMinY = Math.max(ROCK_KEPT_ABOVE_BOTTOM_BLOCKS, lowest);
this.depthMaxY = Math.min(worldHeight - 1, highest);
this.fadeBlocks = Math.max(0, cave.fade());
this.surfaceClearance = Math.max(0, cave.surfaceClearance());
this.opensToSurface = cave.opensToSurface();
}
private static ValueField caveValue(CaveValue value, CaveNoise caveNoise, String name) {
return ValueField.inColumns(value, caveNoise, name, Cave.VALUE_CHANGE_BLOCKS);
}
/** The seed the cave with id {@code cave} carves with in a world whose carve seed is {@code carveSeed}. */
@@ -77,10 +87,10 @@ public final class CaveCarver {
/** {@link #carve}, telling the sink which part carved each block. A block two parts carve is reported for each. */
public void carveByPart(int originX, int originZ, int[] surfaceY, double[] columnWeight, boolean[] sealed, PartSink sink) {
if (shapes.isEmpty() || depthMaxY < depthMinY) {
if (shapes.isEmpty()) {
return;
}
CaveLimits limits = limitsOf(surfaceY, columnWeight, sealed);
CaveLimits limits = limitsOf(originX, originZ, surfaceY, columnWeight, sealed);
if (limits.carvesNothing()) {
return;
}
@@ -111,13 +121,49 @@ public final class CaveCarver {
carveByPart(originX, originZ, surfaceY, columnWeight, sealed, (part, localX, y, localZ) -> sink.carve(localX, y, localZ));
}
private CaveLimits limitsOf(int[] surfaceY, double[] columnWeight, boolean[] sealed) {
int[] columnTopY = new int[CHUNK_COLUMNS];
boolean[] columnOpens = new boolean[CHUNK_COLUMNS];
for (int column = 0; column < CHUNK_COLUMNS; column++) {
columnOpens[column] = opensToSurface && !sealed[column];
columnTopY[column] = columnOpens[column] ? surfaceY[column] : surfaceY[column] - surfaceClearance;
private CaveLimits limitsOf(int originX, int originZ, int[] surfaceY, double[] columnWeight, boolean[] sealed) {
Columns columns = Columns.of(columnWeight);
fillBlocks(fade, originX, originZ, columns.fadeBlocks());
fillBlocks(ceilingFade, originX, originZ, columns.ceilingFadeBlocks());
boolean depthVaries = depthMin.varies() || depthMax.varies();
int constantClearance = surfaceClearanceAt(originX, originZ);
int constantDepthMinY = depthMinYAt(originX, originZ);
int constantDepthMaxY = depthMaxYAt(originX, originZ);
for (int column = 0; column < CaveLimits.CHUNK_COLUMNS; column++) {
double x = originX + (column >> 4);
double z = originZ + (column & 15);
columns.depthMinY()[column] = depthVaries ? depthMinYAt(x, z) : constantDepthMinY;
columns.depthMaxY()[column] = depthVaries ? depthMaxYAt(x, z) : constantDepthMaxY;
boolean opens = opensToSurface && !sealed[column];
columns.opensToSurface()[column] = opens;
int clearance = surfaceClearance.varies() ? surfaceClearanceAt(x, z) : constantClearance;
columns.topY()[column] = opens ? surfaceY[column] : surfaceY[column] - clearance;
}
return new CaveLimits(depthMinY, depthMaxY, fadeBlocks, columnTopY, columnOpens, columnWeight);
return new CaveLimits(columns);
}
/** Fills {@code blocks} with the value in each column of the chunk, at least 0. */
private static void fillBlocks(ValueField value, int originX, int originZ, double[] blocks) {
if (!value.varies()) {
Arrays.fill(blocks, Math.max(0D, value.min()));
return;
}
for (int column = 0; column < CaveLimits.CHUNK_COLUMNS; column++) {
blocks[column] = Math.max(0D, value.at(originX + (column >> 4), originZ + (column & 15)));
}
}
private int depthMinYAt(double x, double z) {
double lowest = Math.min(depthMin.at(x, z), depthMax.at(x, z));
return Math.max(ROCK_KEPT_ABOVE_BOTTOM_BLOCKS, (int) Math.floor(lowest) - worldBottomY);
}
private int depthMaxYAt(double x, double z) {
double highest = Math.max(depthMin.at(x, z), depthMax.at(x, z));
return Math.min(worldHeight - 1, (int) Math.ceil(highest) - worldBottomY);
}
private int surfaceClearanceAt(double x, double z) {
return (int) Math.round(Math.max(0D, surfaceClearance.at(x, z)));
}
}
@@ -18,72 +18,99 @@
package art.arcane.iris.modules.carve.field;
import java.util.Arrays;
/**
* Where one cave may carve in one chunk, and how freely: fully inside its depth range and well under the surface,
* narrowing to nothing towards the ends of the range, towards the rock it keeps under the surface and towards columns
* that do not list it. Columns are indexed as {@code (localX << 4) | localZ}; heights count from the dimension's bottom.
*/
public final class CaveLimits {
private static final int CHUNK_COLUMNS = 256;
final class CaveLimits {
static final int CHUNK_COLUMNS = 256;
private static final int CELL_COLUMNS = ChunkLattice.CELLS_PER_CHUNK_AXIS * ChunkLattice.CELLS_PER_CHUNK_AXIS;
/** A cave that keeps rock above it closes over this many blocks instead of ending in a flat ceiling. */
private static final int CEILING_FADE_BLOCKS = 8;
private final int lowestY;
private final int highestY;
private final int[] depthMinYs;
private final int[] depthMaxYs;
private final double[] fadeBlocks;
private final double[] ceilingFadeBlocks;
private final int[] topY;
private final boolean[] opensToSurface;
private final double[] weight;
/** Whether depth and fades are the same in every column, as they are for plain numbers; then they are read once. */
private final boolean sameRangeInEveryColumn;
private final int depthMinY;
private final int depthMaxY;
private final int fadeBlocks;
private final int[] columnTopY;
private final boolean[] columnOpensToSurface;
private final double[] columnWeight;
private final double fade;
private final double ceilingFade;
private final int lowestY;
private final int highestY;
private final int[] cellTopY = new int[CELL_COLUMNS];
private final boolean[] cellHasWeight = new boolean[CELL_COLUMNS];
/**
* @param depthMinY lowest height of the cave's depth range
* @param depthMaxY highest height of the cave's depth range
* @param fadeBlocks blocks over which the cave narrows at both ends of the range
* @param columnTopY highest height the cave may carve in each column
* @param columnOpensToSurface whether the cave reaches its top at full width in each column, instead of closing under it
* @param columnWeight how much each column lists the cave, from 0 to 1
* What the cave allows in each column of the chunk.
*
* @param depthMinY lowest height of the cave's depth range
* @param depthMaxY highest height of the cave's depth range
* @param fadeBlocks blocks over which the cave narrows at both ends of the range
* @param topY highest height the cave may carve
* @param opensToSurface whether the cave reaches its top at full width, instead of closing under it
* @param ceilingFadeBlocks blocks over which a cave that does not open to the surface closes under its top
* @param weight how much the column lists the cave, from 0 to 1
*/
public CaveLimits(int depthMinY, int depthMaxY, int fadeBlocks, int[] columnTopY, boolean[] columnOpensToSurface, double[] columnWeight) {
this.depthMinY = depthMinY;
this.depthMaxY = depthMaxY;
this.fadeBlocks = fadeBlocks;
this.columnTopY = columnTopY;
this.columnOpensToSurface = columnOpensToSurface;
this.columnWeight = columnWeight;
java.util.Arrays.fill(cellTopY, Integer.MIN_VALUE);
int highestTopY = Integer.MIN_VALUE;
record Columns(int[] depthMinY, int[] depthMaxY, double[] fadeBlocks, int[] topY, boolean[] opensToSurface,
double[] ceilingFadeBlocks, double[] weight) {
static Columns of(double[] weight) {
return new Columns(new int[CHUNK_COLUMNS], new int[CHUNK_COLUMNS], new double[CHUNK_COLUMNS], new int[CHUNK_COLUMNS],
new boolean[CHUNK_COLUMNS], new double[CHUNK_COLUMNS], weight);
}
}
CaveLimits(Columns columns) {
this.depthMinYs = columns.depthMinY();
this.depthMaxYs = columns.depthMaxY();
this.fadeBlocks = columns.fadeBlocks();
this.ceilingFadeBlocks = columns.ceilingFadeBlocks();
this.topY = columns.topY();
this.opensToSurface = columns.opensToSurface();
this.weight = columns.weight();
this.sameRangeInEveryColumn = isTheSameInEveryColumn(depthMinYs) && isTheSameInEveryColumn(depthMaxYs)
&& isTheSameInEveryColumn(fadeBlocks) && isTheSameInEveryColumn(ceilingFadeBlocks);
this.depthMinY = depthMinYs[0];
this.depthMaxY = depthMaxYs[0];
this.fade = fadeBlocks[0];
this.ceilingFade = ceilingFadeBlocks[0];
Arrays.fill(cellTopY, Integer.MIN_VALUE);
int lowest = Integer.MAX_VALUE;
int highest = Integer.MIN_VALUE;
for (int column = 0; column < CHUNK_COLUMNS; column++) {
if (columnWeight[column] <= 0D) {
if (columns.weight()[column] <= 0D) {
continue;
}
int cell = cellOf(column >> 4, column & 15);
cellHasWeight[cell] = true;
cellTopY[cell] = Math.max(cellTopY[cell], columnTopY[column]);
highestTopY = Math.max(highestTopY, columnTopY[column]);
cellTopY[cell] = Math.max(cellTopY[cell], topY[column]);
lowest = Math.min(lowest, depthMinYs[column]);
highest = Math.max(highest, Math.min(depthMaxYs[column], topY[column]));
}
this.lowestY = depthMinY;
this.highestY = Math.min(depthMaxY, highestTopY);
this.lowestY = lowest;
this.highestY = highest;
}
private static int cellOf(int localX, int localZ) {
return ((localX / ChunkLattice.CELL_BLOCKS) * ChunkLattice.CELLS_PER_CHUNK_AXIS) + (localZ / ChunkLattice.CELL_BLOCKS);
}
public int lowestY() {
int lowestY() {
return lowestY;
}
public int highestY() {
int highestY() {
return highestY;
}
/** Whether the cave carves nothing in this chunk. */
public boolean carvesNothing() {
boolean carvesNothing() {
return highestY < lowestY;
}
@@ -95,26 +122,51 @@ public final class CaveLimits {
/** How freely the cave carves the block, from 0 (not at all) to 1 (at its full size). */
double openness(int column, int y) {
double weight = columnWeight[column];
if (weight <= 0D || y < depthMinY || y > depthMaxY) {
if (sameRangeInEveryColumn) {
return openness(column, y, depthMinY, depthMaxY, fade, ceilingFade);
}
return openness(column, y, depthMinYs[column], depthMaxYs[column], fadeBlocks[column], ceilingFadeBlocks[column]);
}
private double openness(int column, int y, int columnDepthMinY, int columnDepthMaxY, double columnFade, double columnCeilingFade) {
double columnWeight = weight[column];
if (columnWeight <= 0D || y < columnDepthMinY || y > columnDepthMaxY) {
return 0D;
}
int belowTop = columnTopY[column] - y;
int belowTop = topY[column] - y;
if (belowTop < 0) {
return 0D;
}
double openness = weight * easeIn(Math.min(y - depthMinY, depthMaxY - y), fadeBlocks);
if (!columnOpensToSurface[column]) {
openness *= easeIn(belowTop, CEILING_FADE_BLOCKS);
double openness = columnWeight * easeIn(Math.min(y - columnDepthMinY, columnDepthMaxY - y), columnFade);
if (!opensToSurface[column]) {
openness *= easeIn(belowTop, columnCeilingFade);
}
return openness;
}
private static double easeIn(int distance, int fadeBlocks) {
if (fadeBlocks <= 0 || distance >= fadeBlocks) {
private static boolean isTheSameInEveryColumn(int[] values) {
for (int column = 1; column < values.length; column++) {
if (values[column] != values[0]) {
return false;
}
}
return true;
}
private static boolean isTheSameInEveryColumn(double[] values) {
for (int column = 1; column < values.length; column++) {
if (values[column] != values[0]) {
return false;
}
}
return true;
}
private static double easeIn(int distance, double fadeBlocks) {
if (fadeBlocks <= 0D || distance >= fadeBlocks) {
return 1D;
}
double share = distance / (double) fadeBlocks;
double share = distance / fadeBlocks;
return share * share * (3D - (2D * share));
}
}
@@ -40,6 +40,7 @@ final class CaveNoise {
/** A pack style is rescaled until its measured feature spacing is within this share of the one asked for. */
private static final double SCALING_TOLERANCE = 0.1D;
private static final int MOST_SCALING_ROUNDS = 6;
private static final long NAME_SEED_MIX = 0x9E3779B97F4A7C15L;
private static final Field3 LEVEL = (x, y, z) -> 0D;
private final NoiseFactory noise;
@@ -51,6 +52,14 @@ final class CaveNoise {
this.seed = seed;
}
/**
* The fields of one named value of the cave, seeded by the name: a value that varies takes no seed from the
* cave's own fields, so writing a range anywhere leaves every other field of the cave where it was.
*/
CaveNoise named(String name) {
return new CaveNoise(noise, seed ^ (name.hashCode() * NAME_SEED_MIX));
}
/** How much a field with this spacing typically changes over one block. */
static double typicalSlope(double spacing) {
return SIMPLEX_SLOPE_TIMES_SPACING / spacing;
@@ -77,6 +86,24 @@ final class CaveNoise {
return (x, y, z) -> (base.at(x, y, z) + (detail.at(x, y, z) * detailWeight)) * normalization;
}
/** {@link #detailed} with a detail weight that may vary from place to place. */
Field3 detailed(double spacing, double verticalSpacing, ValueField detailWeight) {
if (!detailWeight.varies()) {
return detailed(spacing, verticalSpacing, detailWeight.min());
}
Field3 base = smooth(spacing, verticalSpacing);
double detailSpacing = spacing / DETAIL_SHRINK;
double detailVerticalSpacing = verticalSpacing / DETAIL_SHRINK;
if (Math.min(detailSpacing, detailVerticalSpacing) < MIN_DETAIL_SPACING_BLOCKS) {
return base;
}
Field3 detail = smooth(detailSpacing, detailVerticalSpacing);
return (x, y, z) -> {
double weight = detailWeight.at(x, y, z);
return (base.at(x, y, z) + (detail.at(x, y, z) * weight)) / (1D + weight);
};
}
/** A field that only varies over X and Z, changing sign about every {@code spacing} blocks. */
Field3 columns(double spacing) {
NoiseSampler sampler = nextSampler(NoiseStyle.of(STYLE));
@@ -94,6 +121,16 @@ final class CaveNoise {
return sampler::signed;
}
/** {@link #inBlocks} for a field that only varies over X and Z. */
Field3 columnsInBlocks(NoiseStyle style) {
if (style.isFlat()) {
nextSeed();
return LEVEL;
}
NoiseSampler sampler = nextSampler(style);
return (x, y, z) -> sampler.signed(x, z);
}
/** A pack's style rescaled so its features lie about {@code spacing} blocks apart horizontally and {@code verticalSpacing} vertically. */
Field3 scaledTo(NoiseStyle style, double spacing, double verticalSpacing) {
if (style.isFlat()) {
@@ -28,14 +28,15 @@ import com.volmit.noise.NoiseStyle;
* The pillar field varies only across X and Z unless the pack lets pillars change with height; then it is read in 3D
* on the lattice, and a pillar whose field fades out mid-room narrows and breaks off, leaving stubs that flare into
* floor and ceiling.
*
* <p>A value that varies moves the threshold it sets point by point: the lattice then carries the room field less its
* threshold, and the pillar thresholds, so blocks interpolate them like any field. A plain number keeps them constant.
*/
final class CavernShape extends LatticeShape {
private static final int ROOMS = 0;
private static final int PILLARS = 1;
private static final int NOT_READ = -1;
/** A room is the part of a feature above the threshold, which is narrower than the feature itself. */
private static final double FEATURE_BLOCKS_PER_ROOM_BLOCK = 1.6D;
/** A finer layer keeps room walls from looking like smooth bubbles. */
private static final double WALL_DETAIL = 0.3D;
/** Closing a cavern takes a little more than its most open spot, so nothing is left at the very edge of its limits. */
private static final double CLOSING_MARGIN = 1.1D;
/** Pillars are two features apart: one peak, one trough. */
@@ -43,65 +44,135 @@ final class CavernShape extends LatticeShape {
private static final double LARGEST_PILLAR_AREA_SHARE = 0.3D;
private static final double NO_PILLAR = 0D;
private static final double FULL_PILLAR = 1D;
/** Where the threshold is worked out at the lattice points, a block subtracts nothing more. */
private static final double THRESHOLD_WORKED_OUT_AT_POINTS = 0D;
private final Field3 rooms;
private final FieldStats roomStats;
private final ValueField coverage;
private final double threshold;
private final double mostOpen;
private final Field3 pillars;
private final boolean pillarsChangeWithHeight;
private final FieldStats pillarStats;
private final ValueField pillarSpacing;
private final ValueField pillarThickness;
private final ValueField pillarFlare;
private final boolean pillarSizeVaries;
private final double pillarMiddle;
private final double pillarFoot;
private final int mostOpenField;
private final int pillarField;
private final int pillarMiddleField;
private final int pillarFootField;
private final int fieldCount;
CavernShape(CaveNoise noise, CaveCavern cavern) {
double span = cavern.size() * FEATURE_BLOCKS_PER_ROOM_BLOCK;
double height = cavern.height() * FEATURE_BLOCKS_PER_ROOM_BLOCK;
this.rooms = cavern.style()
.map(style -> noise.scaledTo(style, span, height))
.orElseGet(() -> noise.detailed(span, height, WALL_DETAIL));
FieldStats stats = FieldStats.measure(rooms, span);
this.threshold = stats.valueAboveShare(cavern.coverage());
this.mostOpen = Math.max(0D, stats.highest() - threshold);
double valueChangeBlocks = cavern.size().middle() * CaveCavern.VALUE_CHANGE_SIZES;
ValueField size = ValueField.inBlocks(cavern.size(), noise, "cavern.size", valueChangeBlocks);
ValueField height = ValueField.inColumns(cavern.height(), noise, "cavern.height", valueChangeBlocks);
ValueField roughness = ValueField.inBlocks(cavern.roughness(), noise, "cavern.roughness", valueChangeBlocks);
this.coverage = ValueField.inBlocks(cavern.coverage(), noise, "cavern.coverage", valueChangeBlocks);
this.rooms = roomField(noise, cavern, size, height, roughness);
this.roomStats = FieldStats.measure(rooms, size.middle() * FEATURE_BLOCKS_PER_ROOM_BLOCK);
this.threshold = coverage.varies() ? THRESHOLD_WORKED_OUT_AT_POINTS : roomStats.valueAboveShare(coverage.min());
this.mostOpen = Math.max(0D, roomStats.highest() - threshold);
int nextField = ROOMS + 1;
this.mostOpenField = coverage.varies() ? nextField++ : NOT_READ;
if (cavern.pillars().isEmpty()) {
this.pillars = null;
this.pillarsChangeWithHeight = false;
this.pillarStats = null;
this.pillarSpacing = null;
this.pillarThickness = null;
this.pillarFlare = null;
this.pillarSizeVaries = false;
this.pillarMiddle = Double.POSITIVE_INFINITY;
this.pillarFoot = Double.POSITIVE_INFINITY;
this.pillarField = NOT_READ;
this.pillarMiddleField = NOT_READ;
this.pillarFootField = NOT_READ;
this.fieldCount = nextField;
return;
}
CavePillars settings = cavern.pillars().get();
double featureBlocks = settings.spacing() * PILLAR_FEATURES_PER_SPACING;
this.pillarSpacing = ValueField.inColumns(settings.spacing(), noise, "cavern.pillars.spacing", valueChangeBlocks);
this.pillarThickness = ValueField.inColumns(settings.thickness(), noise, "cavern.pillars.thickness", valueChangeBlocks);
this.pillarFlare = ValueField.inColumns(settings.flare(), noise, "cavern.pillars.flare", valueChangeBlocks);
this.pillarSizeVaries = pillarSpacing.varies() || pillarThickness.varies() || pillarFlare.varies();
this.pillarsChangeWithHeight = settings.vertical().isPresent();
this.pillars = pillarField(noise, settings, featureBlocks);
FieldStats pillarStats = FieldStats.measure(pillars, featureBlocks);
double middleAreaShare = Math.min(LARGEST_PILLAR_AREA_SHARE, pillarAreaShare(settings));
this.pillarMiddle = pillarStats.valueAboveShare(middleAreaShare);
this.pillarFoot = pillarStats.valueAboveShare(Math.min(1D, middleAreaShare * settings.flare()));
ValueField vertical = settings.vertical()
.map(value -> ValueField.inColumns(value, noise, "cavern.pillars.vertical", valueChangeBlocks))
.orElseGet(() -> ValueField.constant(0D));
this.pillars = pillarField(noise, settings, pillarSpacing, vertical);
this.pillarStats = FieldStats.measure(pillars, pillarSpacing.middle() * PILLAR_FEATURES_PER_SPACING);
this.pillarMiddle = pillarSizeVaries ? Double.NaN : pillarMiddleAt(0D, 0D);
this.pillarFoot = pillarSizeVaries ? Double.NaN : pillarFootAt(0D, 0D);
this.pillarField = pillarsChangeWithHeight ? nextField++ : NOT_READ;
boolean thresholdsAtPoints = pillarsChangeWithHeight && pillarSizeVaries;
this.pillarMiddleField = thresholdsAtPoints ? nextField++ : NOT_READ;
this.pillarFootField = thresholdsAtPoints ? nextField++ : NOT_READ;
this.fieldCount = nextField;
}
private static Field3 pillarField(CaveNoise noise, CavePillars settings, double featureBlocks) {
private static Field3 roomField(CaveNoise noise, CaveCavern cavern, ValueField size, ValueField height, ValueField roughness) {
NoiseStyle style = cavern.style().orElse(null);
return VaryingScale.of(noise, size, height, "cavern.rooms", (fieldNoise, roomSize, roomHeight) -> {
double span = roomSize * FEATURE_BLOCKS_PER_ROOM_BLOCK;
double featureHeight = roomHeight * FEATURE_BLOCKS_PER_ROOM_BLOCK;
return style == null ? fieldNoise.detailed(span, featureHeight, roughness) : fieldNoise.scaledTo(style, span, featureHeight);
});
}
private static Field3 pillarField(CaveNoise noise, CavePillars settings, ValueField spacing, ValueField vertical) {
NoiseStyle style = settings.style().orElse(null);
if (settings.vertical().isEmpty()) {
return style == null ? noise.columns(featureBlocks) : noise.columnsScaledTo(style, featureBlocks);
}
double vertical = settings.vertical().getAsInt();
return style == null ? noise.smooth(featureBlocks, vertical) : noise.scaledTo(style, featureBlocks, vertical);
boolean straight = settings.vertical().isEmpty();
return VaryingScale.of(noise, spacing, vertical, "cavern.pillars", (fieldNoise, pillarSpacing, verticalBlocks) -> {
double featureBlocks = pillarSpacing * PILLAR_FEATURES_PER_SPACING;
if (straight) {
return style == null ? fieldNoise.columns(featureBlocks) : fieldNoise.columnsScaledTo(style, featureBlocks);
}
return style == null ? fieldNoise.smooth(featureBlocks, verticalBlocks) : fieldNoise.scaledTo(style, featureBlocks, verticalBlocks);
});
}
private static double pillarAreaShare(CavePillars pillars) {
double radius = pillars.thickness() / 2D;
return (Math.PI * radius * radius) / ((double) pillars.spacing() * pillars.spacing());
/** The pillar field value above which a column is the middle of a pillar. */
private double pillarMiddleAt(double x, double z) {
return pillarStats.valueAboveShare(middleAreaShareAt(x, z));
}
/** The pillar field value above which a column is on the foot a pillar widens into towards floor and ceiling. */
private double pillarFootAt(double x, double z) {
return pillarStats.valueAboveShare(Math.min(1D, middleAreaShareAt(x, z) * pillarFlare.at(x, z)));
}
private double middleAreaShareAt(double x, double z) {
double radius = pillarThickness.at(x, z) / 2D;
double spacing = pillarSpacing.at(x, z);
return Math.min(LARGEST_PILLAR_AREA_SHARE, (Math.PI * radius * radius) / (spacing * spacing));
}
@Override
protected int fieldCount() {
return pillarsChangeWithHeight ? 2 : 1;
return fieldCount;
}
@Override
protected void readFields(int x, int y, int z, double[] values) {
values[ROOMS] = rooms.at(x, y, z);
if (pillarsChangeWithHeight) {
values[PILLARS] = pillars.at(x, y, z);
double room = rooms.at(x, y, z);
if (mostOpenField == NOT_READ) {
values[ROOMS] = room;
} else {
double pointThreshold = roomStats.valueAboveShare(coverage.at(x, y, z));
values[ROOMS] = room - pointThreshold;
values[mostOpenField] = Math.max(0D, roomStats.highest() - pointThreshold);
}
if (pillarField != NOT_READ) {
values[pillarField] = pillars.at(x, y, z);
}
if (pillarMiddleField != NOT_READ) {
values[pillarMiddleField] = pillarMiddleAt(x, z);
values[pillarFootField] = pillarFootAt(x, z);
}
}
@@ -112,7 +183,8 @@ final class CavernShape extends LatticeShape {
@Override
protected boolean carvesAt(Pass pass, double shareX, double shareY, double shareZ, double openness, int column) {
double open = pass.cell(ROOMS).at(shareX, shareY, shareZ) - threshold - ((1D - openness) * mostOpen * CLOSING_MARGIN);
double mostOpenHere = mostOpenField == NOT_READ ? mostOpen : pass.cell(mostOpenField).at(shareX, shareY, shareZ);
double open = pass.cell(ROOMS).at(shareX, shareY, shareZ) - threshold - ((1D - openness) * mostOpenHere * CLOSING_MARGIN);
if (open <= 0D) {
return false;
}
@@ -120,9 +192,17 @@ final class CavernShape extends LatticeShape {
return true;
}
double strength = pillarsChangeWithHeight
? pillarStrength(pass.cell(PILLARS).at(shareX, shareY, shareZ))
? pointPillarStrength(pass, shareX, shareY, shareZ)
: columnPillarStrength(pass, column);
return open > strength * mostOpen;
return open > strength * mostOpenHere;
}
private double pointPillarStrength(Pass pass, double shareX, double shareY, double shareZ) {
double value = pass.cell(pillarField).at(shareX, shareY, shareZ);
if (pillarMiddleField == NOT_READ) {
return pillarStrength(value, pillarMiddle, pillarFoot);
}
return pillarStrength(value, pass.cell(pillarMiddleField).at(shareX, shareY, shareZ), pass.cell(pillarFootField).at(shareX, shareY, shareZ));
}
/** {@link #pillarStrength} of a straight pillar, read once per column of the chunk. */
@@ -132,22 +212,26 @@ final class CavernShape extends LatticeShape {
if (!Double.isNaN(known)) {
return known;
}
double value = pillars.at(pass.lattice().originX() + (column >> 4), 0D, pass.lattice().originZ() + (column & 15));
double strength = pillarStrength(value);
double x = pass.lattice().originX() + (column >> 4);
double z = pass.lattice().originZ() + (column & 15);
double value = pillars.at(x, 0D, z);
double strength = pillarSizeVaries
? pillarStrength(value, pillarMiddleAt(x, z), pillarFootAt(x, z))
: pillarStrength(value, pillarMiddle, pillarFoot);
strengths[column] = strength;
return strength;
}
/** How strongly a pillar field value is a pillar: 0 outside one, 1 in its middle, in between on the foot it widens into. */
private double pillarStrength(double value) {
if (value >= pillarMiddle) {
private static double pillarStrength(double value, double middle, double foot) {
if (value >= middle) {
return FULL_PILLAR;
}
double footWidth = pillarMiddle - pillarFoot;
double footWidth = middle - foot;
if (footWidth <= 0D) {
return NO_PILLAR;
}
double intoPillar = Math.max(0D, Math.min(1D, (value - pillarFoot) / footWidth));
double intoPillar = Math.max(0D, Math.min(1D, (value - foot) / footWidth));
return intoPillar * intoPillar;
}
}
@@ -20,7 +20,7 @@ package art.arcane.iris.modules.carve.field;
import art.arcane.iris.modules.carve.CaveTunnel;
import art.arcane.iris.modules.carve.CaveTunnelCoverage;
import com.volmit.config.Range;
import art.arcane.iris.modules.carve.CaveValue;
import com.volmit.noise.NoiseStyle;
/**
@@ -37,8 +37,7 @@ import com.volmit.noise.NoiseStyle;
*/
final class TunnelShape extends LatticeShape {
private static final int SHEETS = 3;
private static final int WIDTH = SHEETS;
private static final int PRESENCE = SHEETS + 1;
private static final int NOT_READ = -1;
private static final int[] PAIR_FIRST = {0, 0, 1};
private static final int[] PAIR_SECOND = {1, 2, 2};
private static final int PAIRS = PAIR_FIRST.length;
@@ -63,15 +62,17 @@ final class TunnelShape extends LatticeShape {
private static final double DEFAULT_WARP_SHARE_OF_SPACING = 0.06D;
private static final double DEFAULT_WARPS_PER_SPACING = 3D;
private static final double SMALLEST_DEFAULT_WARP_SPACING_BLOCKS = 16D;
/** A warp moves a path up and down this share of how far it moves it sideways. */
private static final double VERTICAL_WARP_SHARE = 0.5D;
/** Without a width style, the width changes over this many horizontal spacings. */
private static final double DEFAULT_WIDTH_CHANGE_SPACINGS = 1.5D;
private static final double WIDTH_SPREAD = 1D;
/** Without a coverage style, the areas with tunnels are this many horizontal spacings across. */
private static final double DEFAULT_PRESENCE_SPACINGS = 3D;
/** Field value over which tunnels widen from nothing to full size at the edge of an area that has them. */
private static final double PRESENCE_EDGE = 0.15D;
/**
* Field value over which tunnels widen from nothing to full size at the edge of an area that has them, at a
* softness of 1. A softness of 0 still keeps the least edge, so the share never divides by zero.
*/
private static final double SOFTEST_PRESENCE_EDGE = 0.5D;
private static final double LEAST_PRESENCE_EDGE = 0.005D;
/** Where the share of an area's tunnels is worked out at the lattice points, a block divides by nothing and subtracts nothing. */
private static final double PRESENCE_WORKED_OUT_AT_POINTS = 0D;
private static final double EDGE_WORKED_OUT_AT_POINTS = 1D;
/** A tunnel narrower or lower than this is not a passage any more, so it ends instead. */
private static final double NARROWEST_RADIUS_BLOCKS = 1D;
/** A cell's slope is an average, so a cell is only ruled out when the line is clearly further than the widest tunnel. */
@@ -89,22 +90,46 @@ final class TunnelShape extends LatticeShape {
private final Field3 warpY;
private final Field3 warpZ;
private final double warpBlocks;
private final ValueField verticalWarp;
private final Field3 width;
private final Field3 presence;
private final double presenceThreshold;
private final double narrowRadius;
private final double wideRadius;
private final TunnelHeight heightKind;
private final boolean oval;
private final double lowRadius;
private final double tallRadius;
private final ValueField height;
private final Field3 presence;
private final FieldStats presenceStats;
private final ValueField presenceShare;
private final ValueField presenceSoftness;
private final boolean presenceWorkedOutAtPoints;
private final double presenceThreshold;
private final double presenceEdge;
private final int widthField;
private final int heightField;
private final int presenceField;
private final int fieldCount;
private final double leastSteepness;
/** How tall a tunnel is against how wide. */
private enum TunnelHeight {
/** As tall as it is wide. */
ROUND,
/** Between its low and tall height, as far as it is between its narrow and wide width. */
FOLLOWS_WIDTH,
/** The height its own noise picks. */
OWN_NOISE
}
TunnelShape(CaveNoise noise, CaveTunnel tunnel) {
double spacing = tunnel.spacing().horizontal();
double verticalSpacing = tunnel.spacing().vertical();
double valueChangeBlocks = spacing * CaveTunnel.VALUE_CHANGE_SPACINGS;
for (int sheet = 0; sheet < SHEETS; sheet++) {
sheets[sheet] = noise.smooth(spacing, verticalSpacing);
}
this.verticalWarp = ValueField.inBlocks(tunnel.verticalWarp(), noise, "tunnel.verticalWarp", valueChangeBlocks);
NoiseStyle warp = tunnel.warp().orElse(null);
if (warp == null) {
double warpSpacing = Math.max(SMALLEST_DEFAULT_WARP_SPACING_BLOCKS, spacing / DEFAULT_WARPS_PER_SPACING);
@@ -118,42 +143,91 @@ final class TunnelShape extends LatticeShape {
this.warpZ = noise.inBlocks(warp);
this.warpBlocks = warp.isFlat() ? 0D : warp.multiplier() / 2D;
}
double widthChangeSpacing = spacing * DEFAULT_WIDTH_CHANGE_SPACINGS;
this.width = tunnel.widthStyle().map(noise::inBlocks).orElseGet(() -> noise.smooth(widthChangeSpacing, widthChangeSpacing));
Range widthRange = tunnel.width();
this.narrowRadius = Math.min(widthRange.min(), widthRange.max()) / 2D;
this.wideRadius = Math.max(widthRange.min(), widthRange.max()) / 2D;
Range height = tunnel.height().orElse(null);
this.oval = height != null;
this.lowRadius = oval ? Math.min(height.min(), height.max()) / 2D : 0D;
this.tallRadius = oval ? Math.max(height.min(), height.max()) / 2D : 0D;
CaveValue widthValue = tunnel.width();
double widthChangeBlocks = spacing * CaveTunnel.WIDTH_CHANGE_SPACINGS;
this.width = widthValue.style().map(noise::inBlocks).orElseGet(() -> noise.smooth(widthChangeBlocks, widthChangeBlocks));
this.narrowRadius = widthValue.lowest() / 2D;
this.wideRadius = widthValue.highest() / 2D;
CaveValue heightValue = tunnel.height().orElse(null);
this.heightKind = heightKindOf(heightValue);
this.oval = heightKind != TunnelHeight.ROUND;
this.lowRadius = heightValue == null ? 0D : heightValue.lowest() / 2D;
this.tallRadius = heightValue == null ? 0D : heightValue.highest() / 2D;
this.height = heightKind == TunnelHeight.OWN_NOISE
? ValueField.inBlocks(heightValue, noise, "tunnel.height", widthChangeBlocks)
: null;
double leastSlope = CaveNoise.typicalSlope(spacing) * LEAST_SLOPE_SHARE;
this.leastSteepness = leastSlope * leastSlope;
CaveTunnelCoverage coverage = tunnel.coverage();
if (coverage.share() >= 1D) {
this.presenceShare = ValueField.inBlocks(coverage.share(), noise, "tunnel.coverage.share", valueChangeBlocks);
this.presenceSoftness = ValueField.inBlocks(coverage.softness(), noise, "tunnel.coverage.softness", valueChangeBlocks);
this.presenceWorkedOutAtPoints = presenceShare.varies() || presenceSoftness.varies();
boolean heightReadsTheWidthNoise = heightKind == TunnelHeight.FOLLOWS_WIDTH && heightValue.varies();
boolean readsWidth = widthValue.varies() || heightReadsTheWidthNoise;
this.widthField = readsWidth ? SHEETS : NOT_READ;
int nextField = readsWidth ? SHEETS + 1 : SHEETS;
this.heightField = height == null ? NOT_READ : nextField++;
if (presenceShare.lowest() >= 1D) {
this.presence = null;
this.presenceStats = null;
this.presenceThreshold = Double.NEGATIVE_INFINITY;
this.presenceEdge = EDGE_WORKED_OUT_AT_POINTS;
this.presenceField = NOT_READ;
this.fieldCount = nextField;
return;
}
double presenceSpacing = spacing * DEFAULT_PRESENCE_SPACINGS;
NoiseStyle presenceStyle = coverage.style().orElse(null);
this.presence = presenceStyle == null ? noise.smooth(presenceSpacing, presenceSpacing) : noise.inBlocks(presenceStyle);
double presenceFeatureBlocks = presenceStyle == null ? presenceSpacing : CaveNoise.featureBlocks(presence, presenceStyle);
this.presenceThreshold = FieldStats.measure(presence, presenceFeatureBlocks).valueAboveShare(coverage.share());
this.presenceStats = FieldStats.measure(presence, presenceFeatureBlocks);
this.presenceThreshold = presenceWorkedOutAtPoints ? PRESENCE_WORKED_OUT_AT_POINTS : presenceStats.valueAboveShare(presenceShare.min());
this.presenceEdge = presenceWorkedOutAtPoints ? EDGE_WORKED_OUT_AT_POINTS : presenceEdgeOf(presenceSoftness.min());
this.presenceField = nextField++;
this.fieldCount = nextField;
}
private static TunnelHeight heightKindOf(CaveValue height) {
if (height == null) {
return TunnelHeight.ROUND;
}
return height.varies() && height.style().isPresent() ? TunnelHeight.OWN_NOISE : TunnelHeight.FOLLOWS_WIDTH;
}
private static double presenceEdgeOf(double softness) {
return Math.max(LEAST_PRESENCE_EDGE, softness * SOFTEST_PRESENCE_EDGE);
}
@Override
protected int fieldCount() {
return presence == null ? SHEETS + 1 : SHEETS + 2;
return fieldCount;
}
@Override
protected void readFields(int x, int y, int z, double[] values) {
readSheets(x, y, z, values);
values[WIDTH] = width.at(x, y, z);
if (presence != null) {
values[PRESENCE] = presence.at(x, y, z);
if (widthField != NOT_READ) {
values[widthField] = width.at(x, y, z);
}
if (heightField != NOT_READ) {
values[heightField] = height.at(x, y, z);
}
if (presenceField != NOT_READ) {
values[presenceField] = presenceAt(x, y, z);
}
}
/**
* The presence field, or where share or softness vary, how far into an area with tunnels the point lies in
* edges: the threshold and edge are only known point by point then.
*/
private double presenceAt(int x, int y, int z) {
double value = presence.at(x, y, z);
if (!presenceWorkedOutAtPoints) {
return value;
}
double threshold = presenceStats.valueAboveShare(presenceShare.at(x, y, z));
return (value - threshold) / presenceEdgeOf(presenceSoftness.at(x, y, z));
}
private void readSheets(int x, int y, int z, double[] values) {
@@ -164,7 +238,7 @@ final class TunnelShape extends LatticeShape {
return;
}
double warpedX = x + (warpX.at(x, y, z) * warpBlocks);
double warpedY = y + (warpY.at(x, y, z) * warpBlocks * VERTICAL_WARP_SHARE);
double warpedY = y + (warpY.at(x, y, z) * warpBlocks * verticalWarp.at(x, y, z));
double warpedZ = z + (warpZ.at(x, y, z) * warpBlocks);
for (int sheet = 0; sheet < SHEETS; sheet++) {
values[sheet] = sheets[sheet].at(warpedX, warpedY, warpedZ);
@@ -173,7 +247,7 @@ final class TunnelShape extends LatticeShape {
@Override
protected boolean mayCarveIn(Pass pass) {
if (presence != null && pass.cell(PRESENCE).highest() <= presenceThreshold) {
if (presence != null && pass.cell(presenceField).highest() <= presenceThreshold) {
return false;
}
double reach = Math.max(wideRadius, tallRadius) * CELL_REACH_SLACK;
@@ -252,7 +326,7 @@ final class TunnelShape extends LatticeShape {
if (!oval) {
return isWithinRoundTunnel(pass, shareX, shareY, shareZ, radius);
}
double heightRadius = ((lowRadius + ((tallRadius - lowRadius) * widthShare)) * sizeShare) * openness;
double heightRadius = (fullHeightRadiusAt(pass, shareX, shareY, shareZ, widthShare) * sizeShare) * openness;
if (heightRadius < NARROWEST_RADIUS_BLOCKS) {
return false;
}
@@ -307,8 +381,20 @@ final class TunnelShape extends LatticeShape {
+ (terms[offset + SECOND_SQUARED] * second * second);
}
/** How far between its narrow and its wide width the tunnel is at the block, from 0 to 1; 0 where the width is fixed. */
private double widthShareAt(Pass pass, double shareX, double shareY, double shareZ) {
return clampToShare(0.5D + (pass.cell(WIDTH).at(shareX, shareY, shareZ) * WIDTH_SPREAD));
if (widthField == NOT_READ) {
return 0D;
}
return ValueField.shareAt(pass.cell(widthField).at(shareX, shareY, shareZ));
}
/** Half the height of an oval tunnel at the block, before it narrows at the edges of its areas and limits. */
private double fullHeightRadiusAt(Pass pass, double shareX, double shareY, double shareZ, double widthShare) {
if (heightKind == TunnelHeight.OWN_NOISE) {
return pass.cell(heightField).at(shareX, shareY, shareZ) / 2D;
}
return lowRadius + ((tallRadius - lowRadius) * widthShare);
}
/** How far the block lies into an area with tunnels: 1 inside, falling to 0 over the edge. */
@@ -316,7 +402,7 @@ final class TunnelShape extends LatticeShape {
if (presence == null) {
return 1D;
}
return clampToShare((pass.cell(PRESENCE).at(shareX, shareY, shareZ) - presenceThreshold) / PRESENCE_EDGE);
return clampToShare((pass.cell(presenceField).at(shareX, shareY, shareZ) - presenceThreshold) / presenceEdge);
}
private static double clampToShare(double value) {
@@ -0,0 +1,113 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modules.carve.field;
import art.arcane.iris.modules.carve.CaveValue;
/**
* A {@link CaveValue} ready to read at a place: the same number everywhere, or the number its noise picks there. The
* noise's middle picks the middle of the range and the value reaches min and max half a unit either side of it, so a
* range has stretches at each end as well as the slopes between them.
*/
final class ValueField {
private static final double MIDDLE_SHARE = 0.5D;
private final double min;
private final double max;
private final Field3 noise;
private ValueField(double min, double max, Field3 noise) {
this.min = min;
this.max = max;
this.noise = noise;
}
static ValueField constant(double value) {
return new ValueField(value, value, null);
}
/**
* {@code value} read in 3D, under its own seed of {@code name}. Without a style it changes over about
* {@code changeBlocks} blocks in every direction.
*/
static ValueField inBlocks(CaveValue value, CaveNoise caveNoise, String name, double changeBlocks) {
if (!value.varies()) {
return constant(value.min());
}
CaveNoise noise = caveNoise.named(name);
Field3 field = value.style().map(noise::inBlocks).orElseGet(() -> noise.smooth(changeBlocks, changeBlocks));
return new ValueField(value.min(), value.max(), field);
}
/** {@link #inBlocks} for a value that only varies over X and Z. */
static ValueField inColumns(CaveValue value, CaveNoise caveNoise, String name, double changeBlocks) {
if (!value.varies()) {
return constant(value.min());
}
CaveNoise noise = caveNoise.named(name);
Field3 field = value.style().map(noise::columnsInBlocks).orElseGet(() -> noise.columns(changeBlocks));
return new ValueField(value.min(), value.max(), field);
}
/** The share of the way from min to max that a noise value picks, from 0 to 1. */
static double shareAt(double signedNoise) {
return Math.max(0D, Math.min(1D, MIDDLE_SHARE + signedNoise));
}
boolean varies() {
return noise != null;
}
double min() {
return min;
}
double max() {
return max;
}
double middle() {
return (min + max) / 2D;
}
double lowest() {
return Math.min(min, max);
}
double highest() {
return Math.max(min, max);
}
double at(double x, double y, double z) {
if (noise == null) {
return min;
}
return min + ((max - min) * shareAt(noise.at(x, y, z)));
}
/** How far from min towards max the value is here, from 0 to 1; 0 where it does not vary. */
double share(double x, double y, double z) {
return noise == null ? 0D : shareAt(noise.at(x, y, z));
}
/** {@link #at} for a value read in columns. */
double at(double x, double z) {
return at(x, 0D, z);
}
}
@@ -0,0 +1,71 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modules.carve.field;
/**
* A field whose features' size varies from place to place. A noise read at a scale that changes along the way shears
* and tears, so the scale a field is read at never changes: a field is built at the smallest and at the largest size
* and the two are blended, horizontal and vertical sizes alike. Each size that varies doubles the fields read.
*/
final class VaryingScale {
/** Builds a field whose features lie about {@code horizontal} blocks apart sideways and {@code vertical} blocks apart upwards. */
@FunctionalInterface
interface Builder {
Field3 build(CaveNoise noise, double horizontal, double vertical);
}
private VaryingScale() {
}
/**
* The field {@code builder} makes at the sizes {@code horizontal} and {@code vertical} pick. The smallest field
* takes the seeds of {@code noise}, so a field whose sizes are plain numbers is exactly the one the builder makes;
* the others are seeded by {@code name}.
*/
static Field3 of(CaveNoise noise, ValueField horizontal, ValueField vertical, String name, Builder builder) {
Field3 lowest = alongHorizontal(noise, horizontal, vertical.min(), name, builder);
if (!vertical.varies()) {
return lowest;
}
Field3 tallest = alongHorizontal(noise.named(name + ".tallest"), horizontal, vertical.max(), name, builder);
return blended(lowest, tallest, vertical);
}
private static Field3 alongHorizontal(CaveNoise noise, ValueField horizontal, double vertical, String name, Builder builder) {
Field3 smallest = builder.build(noise, horizontal.min(), vertical);
if (!horizontal.varies()) {
return smallest;
}
Field3 largest = builder.build(noise.named(name + ".largest"), horizontal.max(), vertical);
return blended(smallest, largest, horizontal);
}
/**
* {@code atMin} where {@code scale} is at its min, {@code atMax} where it is at its max, and both in between,
* weighted so the blend spreads as far as either field alone and a threshold keeps its share.
*/
private static Field3 blended(Field3 atMin, Field3 atMax, ValueField scale) {
return (x, y, z) -> {
double towardsMax = scale.share(x, y, z);
double towardsMin = 1D - towardsMax;
double spread = Math.sqrt((towardsMin * towardsMin) + (towardsMax * towardsMax));
return ((atMin.at(x, y, z) * towardsMin) + (atMax.at(x, y, z) * towardsMax)) / spread;
};
}
}