Replace the noise cave profile with listed caves

Packs now describe caves as files in caves/ and list them under "caves"
on the dimension, regions and biomes. The lists of a column add up.

A cave has tunnels, caverns or both. Tunnels are the lines where two of
three smooth fields meet, so they run long and join into one network.
Caverns are rooms where one slow field rises over a threshold; pillars
are columns where a second, 2D field peaks. Sizes are written in blocks.

Every shape reads its fields on a 4-block lattice and decides per block
from the interpolated values, so thin tunnels survive between lattice
points. The adaptive sampler and the 2,268-line carver are gone.

Removed with the profile: cave water pockets and their support check,
profile defaults for cave objects, and profile carving of floating
islands. Floating islands still carve with carveStyle.

Pack validation read module settings before the pack had resources; a
module that turns keys into ids then failed the pack. Linked biomes are
now skipped there and checked when the pack loads.
This commit is contained in:
piexel committed 2026-11-12 21:21:40 +01:00
1 parent 573e631bb8
commit 7d166df70f
60 files changed
+1996 -5915

No files matched your search

@@ -105,7 +105,9 @@ public final class ModuleSettings {
}
private Set<String> linkedBiomes(IrisPackResources resources, Function<LinkedBiomes, Set<ResourceId>> pick) {
if (values.isEmpty()) {
// Pack validation reads dimensions through pack data that has no resources of its own, and a module's
// settings cannot turn keys into ids without them. The biomes they link are checked when the pack loads.
if (values.isEmpty() || resources == null) {
return Set.of();
}
Set<String> biomes = new LinkedHashSet<>();
@@ -34,7 +34,7 @@ import java.util.Locale;
* Catches the shared IrisStyledRange class default (min 16, max 32) leaking into pack content.
* The POJO cannot distinguish an empty object from an explicit 16/32 after Gson runs, so the raw
* JSON is the only place this mistake is still visible: an objects[].densityStyle of {} places
* 16-32 objects per chunk, and a caveProfile.densityThreshold of {} hollows the whole cave range.
* 16-32 objects per chunk.
*/
final class PackStyledRangeDefaultValidator {
private static final String STYLE_RANGE_SNIPPET_FOLDER = "snippet/style-range/";
@@ -74,7 +74,6 @@ final class PackStyledRangeDefaultValidator {
}
validateObjectPlacements(packFolder, type, key, json, errors, warnings);
validateCaveProfileThreshold(packFolder, type, key, json.optJSONObject("caveProfile"), errors, warnings);
}
}
return new Validation(errors, warnings);
@@ -98,18 +97,6 @@ final class PackStyledRangeDefaultValidator {
}
}
private static void validateCaveProfileThreshold(File packFolder, String type, String key, JSONObject caveProfile,
List<String> errors, List<String> warnings) {
if (caveProfile == null || !caveProfile.has("densityThreshold") || caveProfile.isNull("densityThreshold")) {
return;
}
checkRange(packFolder, caveProfile.opt("densityThreshold"),
type + " '" + key + "' caveProfile.densityThreshold",
"a carve threshold of 16-32, hollowing the entire vertical range",
"remove densityThreshold to keep the cave profile default",
errors, warnings);
}
private static void checkRange(File packFolder, Object raw, String path, String consequence, String removal,
List<String> errors, List<String> warnings) {
JSONObject range = null;
@@ -18,7 +18,6 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.modules.carve.CarvingBiomeSettings;
import art.arcane.iris.modules.carve.CarvingEnabledSettings;
import art.arcane.iris.modules.carve.CarvingChild;
@@ -26,7 +25,7 @@ import art.arcane.iris.modules.carve.CarvingEntry;
import art.arcane.iris.modules.carve.CarvingSettings;
import art.arcane.iris.modules.carve.CaveDepthSettings;
import art.arcane.iris.builtin.carve.CaveLavaHeightSettings;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.modules.carve.CaveList;
import art.arcane.iris.modules.carve.UpperDimensionCarvingSettings;
import art.arcane.volmlib.util.json.JSONObject;
import com.google.gson.Gson;
@@ -51,7 +50,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* The cave settings packs have always written, read by the carve module under their old keys: {@code caveProfile} (an object at a
* The cave settings of packs, read by the carve module under their keys: {@code caves} (a list of cave keys at a
* dimension, region or biome), {@code carving} and {@code carvingEnabled} (a list and a boolean at a dimension), {@code carvingBiome} and
* {@code caveMinDepthBelowSurface} (a biome key and a number at a biome). The dimension, region and biome are files of the overworld pack
* as they were before the port.
@@ -81,25 +80,9 @@ public class CarveSettingsDecodingTest {
}
@Test
public void theOverworldReadsItsCaveProfileItsCarvingBandsAndCarvingEnabled() throws IOException {
public void theOverworldReadsItsCarvingBandsAndCarvingEnabled() throws IOException {
ModuleSettings settings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld");
CaveProfile profile = settings.find(CaveProfile.class).orElseThrow();
assertTrue(profile.enabled());
assertEquals(6, profile.verticalRange().min(), 0);
assertEquals(700, profile.verticalRange().max(), 0);
assertEquals("PERLIN_IRIS", profile.baseDensityStyle().style());
assertEquals(0.72, profile.baseDensityStyle().zoom(), 0);
assertEquals("FRACTAL_WATER", profile.warpStyle().style());
assertEquals(-0.14, profile.densityThreshold().min(), 0);
assertEquals(3, profile.sampleStep());
assertEquals(5, profile.surfaceClearance());
assertEquals(14, profile.objectMinDepthBelowSurface());
assertEquals(ObjectPlaceMode.ORGANIC_STILT, profile.defaultObjectPlaceMode().orElseThrow());
assertEquals(2, profile.modules().size());
assertTrue(profile.modules().get(1).invert());
assertEquals(240, profile.modules().get(1).verticalRange().max(), 0);
List<CarvingEntry> bands = settings.find(CarvingSettings.class).orElseThrow().entries();
assertEquals(1, bands.size());
assertEquals("global-deepdark-band", bands.getFirst().id());
@@ -115,44 +98,35 @@ public class CarveSettingsDecodingTest {
}
@Test
public void aRegionReadsItsCaveProfile() throws IOException {
JSONObject region = file("regions/forests.json");
public void cavesAreAListOfCaveKeysAtEveryLevel() {
JSONObject json = new JSONObject("{\"caves\": [\"tunnels\", \"deep/caverns\"]}");
CaveProfile profile = decoder.decode(Level.REGION, region, "region forests").find(CaveProfile.class).orElseThrow();
for (Level level : List.of(Level.DIMENSION, Level.REGION, Level.BIOME)) {
CaveList caves = decoder.decode(level, json, level + " test").find(CaveList.class).orElseThrow();
assertTrue(profile.enabled());
assertEquals(6, profile.verticalRange().min(), 0);
assertEquals(120, profile.verticalRange().max(), 0);
assertEquals(1, profile.baseWeight(), 0);
assertEquals(3, profile.sampleStep());
assertEquals(List.of("tunnels", "deep/caverns"), caves.caves());
}
}
@Test
public void aBiomeReadsItsCaveProfileAndItsMinimumDepth() throws IOException {
public void settingsLinkNoBiomesWhileThePackHasNoResourcesYet() {
ModuleSettings settings = decoder.decode(Level.DIMENSION, new JSONObject("{\"caves\": [\"tunnels\"]}"), "dimension test");
assertEquals(Set.of(), settings.usedBiomes(null, ModuleSettings.NONE, "overworld"));
assertEquals(Set.of(), settings.treeBiomes(null));
}
@Test
public void aBiomeReadsItsMinimumDepth() throws IOException {
JSONObject biome = file("biomes/carving/amethyst.json");
ModuleSettings settings = decoder.decode(Level.BIOME, biome, "biome carving/amethyst");
CaveProfile profile = settings.find(CaveProfile.class).orElseThrow();
assertTrue(profile.enabled());
assertEquals(620, profile.verticalRange().max(), 0);
assertEquals(0.91, profile.baseWeight(), 0);
assertEquals(2, profile.sampleStep());
assertEquals(biome.getInt("caveMinDepthBelowSurface"), settings.find(CaveDepthSettings.class).orElseThrow().depth());
assertEquals(10, settings.find(CaveDepthSettings.class).orElseThrow().depth());
assertTrue("the biome writes no carvingBiome", settings.find(CarvingBiomeSettings.class).isEmpty());
}
@Test
public void aCaveProfileMayBeWrittenAsASnippetReference() {
ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"caveProfile\": \"snippet/iris/carve/cave-profile/shallow\"}"), "biome test");
CaveProfile profile = settings.find(CaveProfile.class).orElseThrow();
assertTrue(profile.enabled());
assertEquals(100, profile.verticalRange().max(), 0);
assertEquals(2, profile.sampleStep());
}
@Test
public void carvingBandsReadChildrenAndTheirOptions() {
JSONObject json = new JSONObject("""
@@ -208,9 +182,9 @@ public class CarveSettingsDecodingTest {
@Test
public void everyKeyIsOnlyReadAtTheLevelsTheOldFieldExistedAt() {
assertTrue(decoder.keys(Level.DIMENSION).containsAll(List.of("caveProfile", "carving", "carvingEnabled", "caveLavaHeight", "upperDimensionCarving")));
assertTrue(decoder.keys(Level.REGION).contains("caveProfile"));
assertTrue(decoder.keys(Level.BIOME).containsAll(List.of("caveProfile", "carvingBiome", "caveMinDepthBelowSurface")));
assertTrue(decoder.keys(Level.DIMENSION).containsAll(List.of("caves", "carving", "carvingEnabled", "caveLavaHeight", "upperDimensionCarving")));
assertTrue(decoder.keys(Level.REGION).contains("caves"));
assertTrue(decoder.keys(Level.BIOME).containsAll(List.of("caves", "carvingBiome", "caveMinDepthBelowSurface")));
assertFalse(decoder.keys(Level.REGION).contains("carving"));
assertFalse(decoder.keys(Level.DIMENSION).contains("carvingBiome"));
assertFalse(decoder.keys(Level.DIMENSION).contains("caveMinDepthBelowSurface"));
@@ -22,6 +22,8 @@ import art.arcane.iris.builtin.IrisSeedPurposes;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.ResourceLoader;
import art.arcane.iris.engine.object.material.IrisBlockData;
import art.arcane.iris.modules.carve.Cave;
import art.arcane.iris.modules.carve.CaveResources;
import com.volmit.config.Level;
import com.volmit.config.SettingsStack;
import com.volmit.IrisFeature;
@@ -78,6 +80,7 @@ public final class CarveTestWorld implements PackWorld {
private final Map<Class<?>, Object> states = new HashMap<>();
private final List<Entry<?>> declared = new ArrayList<>();
private final Map<ResourceId, PackBiome> biomes = new HashMap<>();
private final Map<ResourceId, Cave> caves = new HashMap<>();
private final IrisData data = packData();
private final Resources resources = new Resources();
private long carveSeed = 1337L;
@@ -98,6 +101,12 @@ public final class CarveTestWorld implements PackWorld {
return this;
}
/** Puts {@code cave} in the pack's caves folder under {@code key}. */
public CarveTestWorld cave(String key, Cave cave) {
caves.put(resources.idOf(key), cave);
return this;
}
public CarveTestWorld carveSeed(long seed) {
this.carveSeed = seed;
return this;
@@ -228,6 +237,9 @@ public final class CarveTestWorld implements PackWorld {
@Override
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
if (kind.equals(CaveResources.CAVES)) {
return Optional.ofNullable(kind.type().cast(caves.get(id)));
}
if (!kind.equals(BIOMES)) {
return Optional.empty();
}
@@ -67,18 +67,6 @@ public class PackStyledRangeDefaultValidatorTest {
assertTrue(validation.errors().get(0).contains("via snippet 'snippet/style-range/empty'"));
}
@Test
public void flagsEmptyCaveDensityThreshold() throws Exception {
File pack = temporaryFolder.newFolder("pack");
write(pack, "dimensions/main.json", "{\"caveProfile\":{\"densityThreshold\":{}}}");
PackStyledRangeDefaultValidator.Validation validation = PackStyledRangeDefaultValidator.validate(pack);
assertEquals(1, validation.errors().size());
assertTrue(validation.errors().get(0).startsWith(
"Dimension 'main' caveProfile.densityThreshold omits both min and max"));
}
@Test
public void emptyDensityStyleBlocksFullPackValidation() throws Exception {
File pack = temporaryFolder.newFolder("pack");
@@ -1,116 +1,129 @@
/*
* 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.engine.mantle.components;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.core.modules.CarveTestTerrain;
import art.arcane.iris.core.modules.CarveTestWorld;
import art.arcane.iris.core.modules.InMemoryMantle;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.modules.carve.Cave;
import art.arcane.iris.modules.carve.CaveList;
import art.arcane.volmlib.util.matter.MatterCavern;
import com.volmit.ModuleLog;
import com.volmit.config.Level;
import com.volmit.config.Range;
import com.volmit.noise.NoiseStyle;
import com.volmit.noise.StyledRange;
import com.volmit.resource.ResourceId;
import com.volmit.world.BiomeSample;
import org.junit.Before;
import org.junit.Test;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/** The caves a chunk gets: the profile its dimension, region, surface biome and cave biome declare, the last enabled one winning, carved into the mantle. */
public class CaveCarvingTest {
private static final int HEIGHT = 128;
private static final int SURFACE = 100;
private static final int FLUID_HEIGHT = 30;
private static final int LAVA_HEIGHT = 8;
private static final double EVERYTHING_BELOW = 2D;
private static final int ROCK_KEPT_UNDER_SURFACE = 8;
private static final ResourceId REGION = CarveTestWorld.id("region");
private static final ResourceId PLAINS = CarveTestWorld.id("plains");
private static final ResourceId LUSH = CarveTestWorld.id("cave/lush");
private InMemoryMantle mantle;
private CarveTestWorld world;
private ModuleLog log;
@Before
public void setUp() {
world = newWorld();
}
private static CarveTestWorld newWorld() {
return new CarveTestWorld().biome("cave/lush").biome("plains");
world = new CarveTestWorld().biome("cave/lush").biome("plains").cave("rooms", rooms(0, 127)).cave("low", rooms(-50, -30));
log = mock(ModuleLog.class);
}
@Test
public void theDimensionsProfileCarvesWhereNothingNarrowerDeclaresOne() {
world.dimension(profile(true));
assertTrue(carvedBlocks(BiomeSample::surfaceBiome) > 0);
public void nothingIsCarvedWhereNoLevelListsACave() {
assertEquals(0, carvedBlocks(sample -> PLAINS).size());
}
@Test
public void aDisabledProfileDeclaresNothingAndTheDimensionsStillCarves() {
world.dimension(profile(true));
int dimensionOnly = carvedBlocks(BiomeSample::surfaceBiome);
world = newWorld().dimension(profile(true)).declare(Level.REGION, "region", profile(false));
public void aCaveTheDimensionListsCarvesEveryColumn() {
world.dimension(new CaveList(List.of("rooms")));
assertTrue(dimensionOnly > 0);
assertEquals(dimensionOnly, carvedBlocks(BiomeSample::surfaceBiome));
assertTrue(carvedBlocks(sample -> PLAINS).size() > 0);
}
@Test
public void anEnabledProfileOfARegionReplacesTheDimensionsWithinItsOwnBounds() {
world.dimension(profile(true)).declare(Level.REGION, "region", TestSettings.with(profile(true), "verticalRange", Range.of(50D, 60D)));
public void theListsOfADimensionAndARegionAddUp() {
world.dimension(new CaveList(List.of("rooms")));
Set<Long> dimensionOnly = carvedBlocks(sample -> PLAINS);
world.declare(Level.REGION, "region", new CaveList(List.of("low")));
int carved = carvedBlocks(BiomeSample::surfaceBiome);
Set<Long> both = carvedBlocks(sample -> PLAINS);
assertTrue(carved > 0);
mantle.chunk(0, 0).iterate(MatterCavern.class, (x, y, z, cavern) -> assertTrue("y=" + y, y >= 50 && y <= 60));
assertTrue("the region's cave carves on top", both.size() > dimensionOnly.size());
assertTrue("the dimension's cave still carves all it did", both.containsAll(dimensionOnly));
}
@Test
public void theCaveBiomeOfAColumnCarvesWithItsOwnProfileWhereTheDimensionDeclaresNone() {
world.declare(Level.BIOME, "cave/lush", profile(true));
public void theCaveBiomeOfAColumnListsCavesToo() {
world.declare(Level.BIOME, "cave/lush", new CaveList(List.of("rooms")));
assertEquals("the surface biome declares none", 0, carvedBlocks(BiomeSample::surfaceBiome));
assertTrue(carvedBlocks(sample -> sample.caveBiome().orElseThrow()) > 0);
assertEquals("the surface biome lists none", 0, carvedBlocks(sample -> PLAINS).size());
assertTrue(carvedBlocks(sample -> LUSH).size() > 0);
}
/** Carves chunk 0, 0 with the cave biome of every block {@code caveBiomeOf} says, and counts the blocks of the chunk's mantle that became cave. */
private int carvedBlocks(java.util.function.Function<BiomeSample, com.volmit.resource.ResourceId> caveBiomeOf) {
@Test
public void aCaveStaysInItsDepthRangeAndUnderTheRockItKeeps() {
world.dimension(new CaveList(List.of("low")));
Set<Long> carved = carvedBlocks(sample -> PLAINS);
assertFalse(carved.isEmpty());
for (long block : carved) {
int y = (int) (block & 0xFFF);
assertTrue("y=" + y, y >= 14 && y <= 34);
}
world = new CarveTestWorld().biome("plains").cave("rooms", rooms(0, 127)).dimension(new CaveList(List.of("rooms")));
for (long block : carvedBlocks(sample -> PLAINS)) {
int y = (int) (block & 0xFFF);
assertTrue("y=" + y, y <= SURFACE - ROCK_KEPT_UNDER_SURFACE);
}
}
@Test
public void aListedCaveThePackDoesNotHaveIsReportedAndCarvesNothing() {
world.dimension(new CaveList(List.of("missing")));
assertEquals(0, carvedBlocks(sample -> PLAINS).size());
verify(log).warnOnce(anyString(), anyString());
}
/** Carves chunk 0, 0 with the cave biome of every block {@code caveBiomeOf} says, and answers the blocks of the chunk that became cave. */
private Set<Long> carvedBlocks(Function<BiomeSample, ResourceId> caveBiomeOf) {
mantle = new InMemoryMantle(HEIGHT / 16);
CarveTestTerrain terrain = new CarveTestTerrain(0, 0, HEIGHT, FLUID_HEIGHT, (x, z) -> SURFACE).biomes((x, y, z) -> {
BiomeSample sample = new BiomeSample(CarveTestWorld.id("region"), CarveTestWorld.id("plains"), Optional.of(CarveTestWorld.id("cave/lush")));
BiomeSample sample = new BiomeSample(REGION, PLAINS, Optional.of(LUSH));
return new BiomeSample(sample.region(), sample.surfaceBiome(), Optional.of(caveBiomeOf.apply(sample)));
});
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), 1337L, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
new CaveCarving(world, carveWorld, false, (x, z) -> false).carve(mantle.carved(), terrain, 0, 0);
new CaveCarving(world, carveWorld, (x, z) -> false, log).carve(mantle.carved(), terrain, 0, 0);
int[] count = new int[1];
mantle.chunk(0, 0).iterate(MatterCavern.class, (x, y, z, cavern) -> count[0]++);
return count[0];
Set<Long> carved = new HashSet<>();
mantle.chunk(0, 0).iterate(MatterCavern.class, (x, y, z, cavern) -> carved.add(((long) x << 24) | ((long) z << 12) | y));
return carved;
}
private static CaveProfile profile(boolean enabled) {
return TestSettings.with(new CaveProfile(), "enabled", enabled, "verticalRange", Range.of(20D, 90D),
"densityThreshold", StyledRange.of(EVERYTHING_BELOW, EVERYTHING_BELOW, NoiseStyle.of(NoiseStyle.FLAT)),
"allowSurfaceBreak", false, "allowFluid", false, "adaptiveSampling", false, "sampleStep", 1);
/** Caverns that take up most of the rock between two world heights, so a chunk is sure to hold some. */
private static Cave rooms(int minWorldY, int maxWorldY) {
return TestSettings.of(Cave.class, "{\"cavern\": {\"size\": 24, \"height\": 12, \"coverage\": 0.5},"
+ " \"depth\": {\"min\": " + minWorldY + ", \"max\": " + maxWorldY + "}, \"fade\": 0, \"surfaceClearance\": " + ROCK_KEPT_UNDER_SURFACE + "}");
}
}
@@ -1,163 +0,0 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.engine.object.TestSettings;
import org.junit.BeforeClass;
import org.junit.Test;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class CaveCarvingTop2BlendTest {
private static Constructor<?> weightedProfileConstructor;
private static Method limitMethod;
private static Field profileField;
private static Field columnWeightsField;
@BeforeClass
public static void setup() throws Exception {
Class<?> weightedProfileClass = Class.forName("art.arcane.iris.engine.mantle.components.CaveCarving$WeightedProfile");
weightedProfileConstructor = weightedProfileClass.getDeclaredConstructor(CaveProfile.class, double[].class, double.class, com.volmit.config.Range.class, int.class);
weightedProfileConstructor.setAccessible(true);
limitMethod = CaveCarving.class.getDeclaredMethod("limitAndMergeBlendedProfiles", List.class, int.class, int.class);
limitMethod.setAccessible(true);
profileField = weightedProfileClass.getDeclaredField("profile");
profileField.setAccessible(true);
columnWeightsField = weightedProfileClass.getDeclaredField("columnWeights");
columnWeightsField.setAccessible(true);
}
@Test
public void topTwoProfilesAreKeptAndDroppedWeightsAreMergedIntoDominantColumns() throws Exception {
WeightedInput input = createWeightedProfiles();
List<?> limited = invokeLimit(input.weightedProfiles(), 2);
assertEquals(2, limited.size());
Map<CaveProfile, double[]> byProfile = extractWeightsByProfile(limited);
CaveProfile first = input.profiles().first();
CaveProfile second = input.profiles().second();
assertEquals(1.0D, byProfile.get(first)[1], 0D);
assertEquals(1.0D, byProfile.get(second)[0], 0D);
}
@Test
public void topTwoMergeIsDeterministicAcrossRuns() throws Exception {
WeightedInput firstInput = createWeightedProfiles();
WeightedInput secondInput = createWeightedProfiles();
List<?> first = invokeLimit(firstInput.weightedProfiles(), 2);
List<?> second = invokeLimit(secondInput.weightedProfiles(), 2);
Map<CaveProfile, double[]> firstByProfile = extractWeightsByProfile(first);
Map<CaveProfile, double[]> secondByProfile = extractWeightsByProfile(second);
assertEquals(firstByProfile.get(firstInput.profiles().first())[0], secondByProfile.get(secondInput.profiles().first())[0], 0D);
assertEquals(firstByProfile.get(firstInput.profiles().first())[1], secondByProfile.get(secondInput.profiles().first())[1], 0D);
assertEquals(firstByProfile.get(firstInput.profiles().second())[0], secondByProfile.get(secondInput.profiles().second())[0], 0D);
assertEquals(firstByProfile.get(firstInput.profiles().second())[1], secondByProfile.get(secondInput.profiles().second())[1], 0D);
}
@Test
public void topTwoMergePreservesIndependentWeightsAtHighColumnIndexes() throws Exception {
WeightedInput input = createWeightedProfiles();
List<?> limited = invokeLimit(input.weightedProfiles(), 2);
Map<CaveProfile, double[]> byProfile = extractWeightsByProfile(limited);
CaveProfile first = input.profiles().first();
CaveProfile second = input.profiles().second();
assertEquals(1.0D, byProfile.get(first)[255], 0D);
assertEquals(1.0D, byProfile.get(second)[254], 0D);
}
@Test
public void topTwoTieBreaksBySequenceNotIdentity() throws Exception {
CaveProfile first = TestSettings.of(CaveProfile.class, "{\"enabled\":true,\"baseWeight\":1.0}");
CaveProfile second = TestSettings.of(CaveProfile.class, "{\"enabled\":true,\"baseWeight\":1.0}");
CaveProfile third = TestSettings.of(CaveProfile.class, "{\"enabled\":true,\"baseWeight\":1.0}");
double[] weightsA = new double[256];
double[] weightsB = new double[256];
double[] weightsC = new double[256];
weightsA[0] = 0.5D;
weightsB[0] = 0.5D;
weightsC[0] = 0.5D;
List<Object> weighted = new ArrayList<>();
weighted.add(weightedProfileConstructor.newInstance(first, weightsA, average(weightsA), null, 0));
weighted.add(weightedProfileConstructor.newInstance(second, weightsB, average(weightsB), null, 1));
weighted.add(weightedProfileConstructor.newInstance(third, weightsC, average(weightsC), null, 2));
List<?> limited = invokeLimit(weighted, 2);
assertEquals(2, limited.size());
Map<CaveProfile, double[]> byProfile = extractWeightsByProfile(limited);
assertEquals(true, byProfile.containsKey(first));
assertEquals(true, byProfile.containsKey(second));
assertEquals(false, byProfile.containsKey(third));
}
private WeightedInput createWeightedProfiles() throws Exception {
CaveProfile first = TestSettings.of(CaveProfile.class, "{\"enabled\":true,\"baseWeight\":1.31}");
CaveProfile second = TestSettings.of(CaveProfile.class, "{\"enabled\":true,\"baseWeight\":1.17}");
CaveProfile third = TestSettings.of(CaveProfile.class, "{\"enabled\":true,\"baseWeight\":0.93}");
Profiles profiles = new Profiles(first, second, third);
double[] firstWeights = new double[256];
firstWeights[0] = 0.2D;
firstWeights[1] = 0.8D;
firstWeights[255] = 0.6D;
double[] secondWeights = new double[256];
secondWeights[0] = 0.7D;
secondWeights[1] = 0.1D;
secondWeights[254] = 0.7D;
double[] thirdWeights = new double[256];
thirdWeights[0] = 0.3D;
thirdWeights[1] = 0.4D;
thirdWeights[254] = 0.3D;
thirdWeights[255] = 0.4D;
List<Object> weighted = new ArrayList<>();
weighted.add(weightedProfileConstructor.newInstance(first, firstWeights, average(firstWeights), null, 0));
weighted.add(weightedProfileConstructor.newInstance(second, secondWeights, average(secondWeights), null, 1));
weighted.add(weightedProfileConstructor.newInstance(third, thirdWeights, average(thirdWeights), null, 2));
return new WeightedInput(weighted, profiles);
}
private List<?> invokeLimit(List<Object> weightedProfiles, int limit) throws Exception {
return (List<?>) limitMethod.invoke(null, weightedProfiles, limit, 256);
}
private Map<CaveProfile, double[]> extractWeightsByProfile(List<?> weightedProfiles) throws Exception {
Map<CaveProfile, double[]> byProfile = new IdentityHashMap<>();
for (Object weightedProfile : weightedProfiles) {
CaveProfile profile = (CaveProfile) profileField.get(weightedProfile);
double[] weights = (double[]) columnWeightsField.get(weightedProfile);
byProfile.put(profile, weights);
}
return byProfile;
}
private double average(double[] weights) {
double total = 0D;
for (double weight : weights) {
total += weight;
}
return total / weights.length;
}
private record Profiles(CaveProfile first, CaveProfile second, CaveProfile third) {
}
private record WeightedInput(List<Object> weightedProfiles, Profiles profiles) {
}
}
@@ -1,7 +1,6 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.modules.objects.PlacementChanges;
import com.volmit.object.PlaceableObject;
@@ -54,18 +53,6 @@ public class EffectivePlacementsTest {
assertTrue(new EffectivePlacements(true, 0).forSurface(centered, object("castle")).isNone());
}
@Test
public void aCaveProfileGivesCenteredPlacementsItsPlaceMode() {
ObjectPlacement centered = TestSettings.of(ObjectPlacement.class, "{\"mode\":\"CENTER_HEIGHT\"}");
CaveProfile profile = TestSettings.of(CaveProfile.class, "{\"enabled\":true,\"defaultObjectPlaceMode\":\"STILT\"}");
PlacementChanges changes = new EffectivePlacements(true, 0).forCave(centered, object("crystal"), profile);
assertEquals(ObjectPlaceMode.STILT, changes.mode());
assertEquals(List.of("crystal"), changes.place());
assertNull(new EffectivePlacements(true, 0).forCave(centered, object("crystal"), null).mode());
}
private static PlaceableObject object(String key) {
PlaceableObject object = mock(PlaceableObject.class);
when(object.name()).thenReturn(key);
@@ -7,7 +7,9 @@ import art.arcane.iris.engine.mantle.components.CarveWorld;
import art.arcane.iris.engine.mantle.components.CaveCarving;
import art.arcane.iris.engine.mantle.components.CaveFloorMarking;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.modules.carve.Cave;
import art.arcane.iris.modules.carve.CaveList;
import com.volmit.ModuleLog;
import art.arcane.volmlib.util.matter.MatterCavern;
import com.volmit.block.BlockState;
import com.volmit.config.Range;
@@ -46,8 +48,8 @@ public class CarvePipelineHarnessTest {
private static final long SEED = 424242L;
private static final int APPLIED_CHUNKS_PER_SIDE = 6;
private static final int CARVE_RING = 1;
private static final String VOIDS_DIGEST = "df7ae961c3025eb5";
private static final String BLOCKS_DIGEST = "bdb40db5625eb942";
private static final String VOIDS_DIGEST = "630fef28ea2529d4";
private static final String BLOCKS_DIGEST = "58fbce572cb007d4";
private static final BlockState STONE = new BlockState("minecraft:stone");
private static final BlockState AIR = new BlockState("minecraft:air");
@@ -99,7 +101,8 @@ public class CarvePipelineHarnessTest {
}
private Result run() {
CarveTestWorld world = new CarveTestWorld().biome("cave/lush").biome("plains").carveSeed(SEED).dimension(profile());
CarveTestWorld world = new CarveTestWorld().biome("cave/lush").biome("plains").carveSeed(SEED)
.cave("mixed", cave()).dimension(new CaveList(List.of("mixed")));
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), SEED, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
RecordingCaveDressing dressing = new RecordingCaveDressing();
dressing.fluid = WATER;
@@ -108,7 +111,7 @@ public class CarvePipelineHarnessTest {
dressing.ceilings.put(CarveTestWorld.id("cave/lush"), List.of(CEILING));
InMemoryMantle mantle = new InMemoryMantle(HEIGHT / 16);
MantleLayer<CarvedVoid> voids = mantle.carved();
CaveCarving carving = new CaveCarving(world, carveWorld, false, (x, z) -> surface(x, z) < FLUID_HEIGHT);
CaveCarving carving = new CaveCarving(world, carveWorld, (x, z) -> surface(x, z) < FLUID_HEIGHT, mock(ModuleLog.class));
CaveFloorMarking floorMarking = new CaveFloorMarking(carveWorld, false);
CaveApplying applying = new CaveApplying(world, carveWorld, false);
List<String> floors = new ArrayList<>();
@@ -215,7 +218,11 @@ public class CarvePipelineHarnessTest {
return blocks;
}
private static CaveProfile profile() {
return TestSettings.with(new CaveProfile(), "enabled", true, "verticalRange", Range.of(4D, HEIGHT - 8D));
private static Cave cave() {
return TestSettings.of(Cave.class, """
{"tunnel": {"width": {"min": 3, "max": 5}, "stretch": 40},
"cavern": {"size": 32, "height": 14, "coverage": 0.12, "pillars": {"spacing": 12, "thickness": 3}},
"opensToSurface": true, "fade": 4}
""");
}
}
@@ -1,171 +0,0 @@
/*
* 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.engine.object.terrain.carving;
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
import art.arcane.iris.builtin.carve.CaveAnchorMode;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.builtin.carve.CarvingMode;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
/**
* The cave profile of the overworld pack's dimension, read into {@link CaveProfile} (IrisApi types only) with the values
* Iris's own cave profile class read from the same JSON, and what the carvers read it as ({@link ResolvedCaveProfile}).
*/
public class CaveProfileDecodingTest {
private static final String OVERWORLD_CAVE_PROFILE = """
{"enabled": true, "verticalRange": {"min": 6, "max": 700},
"baseDensityStyle": {"style": "PERLIN_IRIS", "zoom": 0.72}, "detailDensityStyle": {"style": "SIMPLEX", "zoom": 0.54},
"warpStyle": {"style": "FRACTAL_WATER", "zoom": 0.5}, "baseWeight": 0.9, "detailWeight": 0.11, "warpStrength": 0.24,
"densityThreshold": {"min": -0.14, "max": -0.06, "style": {"style": "SIMPLEX", "zoom": 0.74}},
"thresholdBias": 0.14, "sampleStep": 3, "surfaceClearance": 5, "allowSurfaceBreak": true,
"surfaceBreakStyle": {"style": "SIMPLEX", "zoom": 0.88}, "surfaceBreakNoiseThreshold": 0.6, "surfaceBreakDepth": 16,
"surfaceBreakThresholdBoost": 0.1, "objectMinDepthBelowSurface": 14, "defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT", "anchorScanStep": 1, "anchorSearchAttempts": 12, "allowFluid": true,
"fluidMinDepthBelowSurface": 20, "fluidRequiresFloor": true, "allowLava": true,
"modules": [{"style": {"style": "SIMPLEX_VASCULAR", "zoom": 1.08}, "weight": 0.08, "threshold": 0.03,
"verticalRange": {"min": 24, "max": 660}, "invert": false},
{"style": {"style": "FRACTAL_FBM_SIMPLEX", "zoom": 0.24}, "weight": 0.04, "threshold": 0.08,
"verticalRange": {"min": 6, "max": 240}, "invert": true}],
"verticalEdgeFade": 24, "verticalEdgeFadeStrength": 0.18, "minCarveCells": 24, "recoveryThresholdBoost": 0.07}
""";
private static final String DARK_DEPTHS_OBJECT = """
{"place": ["rocks/a"], "chance": 0.235719, "density": 4, "carvingSupport": "CARVING_ONLY",
"caveAnchorMode": "PROFILE_DEFAULT", "translate": {"y": -1}, "bottom": true, "force": true}
""";
@Rule
public TemporaryFolder folder = new TemporaryFolder();
private Gson gson;
@Before
public void decodeLikeIrisDoes() throws IOException {
File snippets = folder.newFolder("snippet", "iris", "carve", "cave-profile");
Files.writeString(new File(snippets, "lush.json").toPath(), "{\"enabled\": true, \"sampleStep\": 2}");
IrisData data = mock(IrisData.class, CALLS_REAL_METHODS);
doReturn(folder.getRoot()).when(data).getDataFolder();
gson = new GsonBuilder().registerTypeAdapterFactory(data).create();
}
@Test
public void theOverworldProfileReadsEveryFieldIrisReadFromIt() {
CaveProfile profile = gson.fromJson(OVERWORLD_CAVE_PROFILE, CaveProfile.class);
assertTrue(profile.enabled());
assertEquals(6, profile.verticalRange().min(), 0);
assertEquals(700, profile.verticalRange().max(), 0);
assertEquals("PERLIN_IRIS", profile.baseDensityStyle().style());
assertEquals(0.72, profile.baseDensityStyle().zoom(), 0);
assertEquals("FRACTAL_WATER", profile.warpStyle().style());
assertEquals(0.9, profile.baseWeight(), 0);
assertEquals(0.24, profile.warpStrength(), 0);
assertEquals(-0.14, profile.densityThreshold().min(), 0);
assertEquals("SIMPLEX", profile.densityThreshold().style().style());
assertEquals(3, profile.sampleStep());
assertEquals(CaveAnchorMode.FLOOR, profile.defaultObjectAnchor());
assertEquals(ObjectPlaceMode.ORGANIC_STILT, profile.defaultObjectPlaceMode().orElseThrow());
assertEquals(12, profile.anchorSearchAttempts());
assertEquals(24, profile.verticalEdgeFade());
assertEquals(2, profile.modules().size());
assertEquals("SIMPLEX_VASCULAR", profile.modules().get(0).style().style());
assertFalse(profile.modules().get(0).invert());
assertTrue(profile.modules().get(1).invert());
assertEquals(240, profile.modules().get(1).verticalRange().max(), 0);
}
@Test
public void anEmptyProfileHasIrisDefaults() {
CaveProfile profile = gson.fromJson("{}", CaveProfile.class);
assertFalse(profile.enabled());
assertEquals(0, profile.verticalRange().min(), 0);
assertEquals(384, profile.verticalRange().max(), 0);
assertEquals("CELLULAR_IRIS_DOUBLE", profile.baseDensityStyle().style());
assertEquals("SIMPLEX", profile.detailDensityStyle().style());
assertEquals("FLAT", profile.warpStyle().style());
assertEquals(0.08, profile.surfaceBreakStyle().zoom(), 0);
assertEquals(-0.2, profile.densityThreshold().min(), 0);
assertEquals(0.2, profile.densityThreshold().max(), 0);
assertEquals(0.35, profile.detailWeight(), 0);
assertEquals(0.16, profile.thresholdBias(), 0);
assertEquals(20, profile.verticalEdgeFade());
assertEquals(CaveAnchorMode.FLOOR, profile.defaultObjectAnchor());
assertTrue(profile.defaultObjectPlaceMode().isEmpty());
assertTrue(profile.modules().isEmpty());
assertTrue(profile.allowFluid() && profile.fluidRequiresFloor() && profile.allowLava() && profile.adaptiveSampling());
assertEquals(12, profile.fluidMinDepthBelowSurface());
assertEquals(6, profile.anchorSearchAttempts());
}
@Test
public void profilesMayBeSnippets() {
CaveProfile profile = gson.fromJson("\"snippet/iris/carve/cave-profile/lush\"", CaveProfile.class);
assertTrue(profile.enabled());
assertEquals(2, profile.sampleStep());
}
@Test
public void placementsReadTheirCarvingSupportAndAnchorMode() {
ObjectPlacement placement = gson.fromJson(DARK_DEPTHS_OBJECT, ObjectPlacement.class);
assertEquals(CarvingMode.CARVING_ONLY, placement.carvingSupport());
assertTrue(placement.carvingSupport().supportsCarving());
assertFalse(placement.carvingSupport().supportsSurface());
assertEquals(CaveAnchorMode.PROFILE_DEFAULT, placement.caveAnchorMode());
assertEquals(CarvingMode.SURFACE_ONLY, gson.fromJson("{}", ObjectPlacement.class).carvingSupport());
}
@Test
public void carversReadTheProfileThroughItsApiValues() {
CaveProfile profile = gson.fromJson(OVERWORLD_CAVE_PROFILE, CaveProfile.class);
assertEquals(6, profile.verticalRange().min(), 0);
assertEquals(700, profile.verticalRange().max(), 0);
assertEquals("PERLIN_IRIS", profile.baseDensityStyle().style());
assertEquals(0.72, profile.baseDensityStyle().zoom(), 0);
assertEquals("FRACTAL_WATER", profile.warpStyle().style());
assertEquals(0.88, profile.surfaceBreakStyle().zoom(), 0);
assertEquals(-0.06, profile.densityThreshold().max(), 0);
assertEquals("SIMPLEX", profile.densityThreshold().style().style());
assertEquals(2, profile.modules().size());
assertEquals(0.08, profile.modules().get(0).weight(), 0);
assertEquals(24, profile.modules().get(0).verticalRange().min(), 0);
assertTrue(profile.modules().get(1).invert());
}
}
@@ -547,8 +547,6 @@ public class FloatingIslandBoundarySamplerTest {
when(entry.topShapeNoise()).thenReturn(constant);
when(entry.bottomNoise()).thenReturn(constant);
when(entry.wallWarpNoise()).thenReturn(null);
when(entry.carvingProfileSampler()).thenReturn(null);
when(entry.hasCarvingReference()).thenReturn(false);
when(entry.carveNoise()).thenReturn(constant);
when(entry.settings()).thenReturn(TestSettings.with(new FloatingChildBiome(), "footprintThreshold", 0.5D, "minHeightAboveSurface", 160, "maxHeightAboveSurface", 160, "topShapeMode", TopShapeMode.NOISE, "topShapeAmp", 1.0D, "maxTopHeight", 18, "bottomExponent", 1.0D, "bottomDepthMin", 20, "bottomDepthMax", 20, "maxThickness", 64, "wallWarpAmplitude", 0.0D, "carveThreshold", 0.5D));
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
@@ -611,8 +609,6 @@ public class FloatingIslandBoundarySamplerTest {
when(entry.topShapeNoise()).thenReturn(constant);
when(entry.bottomNoise()).thenReturn(constant);
when(entry.wallWarpNoise()).thenReturn(null);
when(entry.carvingProfileSampler()).thenReturn(null);
when(entry.hasCarvingReference()).thenReturn(false);
when(entry.carveNoise()).thenReturn(null);
when(entry.settings()).thenReturn(TestSettings.with(new FloatingChildBiome(), "footprintThreshold", 0.5D, "topShapeMode", TopShapeMode.NOISE, "topShapeAmp", 1.0D, "maxTopHeight", 18, "bottomExponent", 1.0D, "bottomDepthMin", 20, "bottomDepthMax", 20, "maxThickness", 64, "wallWarpAmplitude", 0.0D, "carveThreshold", 1.0D,
"minHeightAboveSurface", entry == lower ? 160 : 180, "maxHeightAboveSurface", entry == lower ? 160 : 180));
@@ -319,11 +319,12 @@ public class FloatingIslandSampleBottomYTest {
}
@Test
public void directCarveEnabled_respectsCarvingReferenceOverride() {
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "carving", "carving/mushroom"), null);
public void directCarveEnabled_needsCarveNoiseAndAThresholdBelowOne() {
NoiseSampler carve = constantNoise(0.0);
assertFalse(FloatingIslandSample.directCarveEnabled(entry, null, carve, 0.5));
assertTrue(FloatingIslandSample.directCarveEnabled(carve, 0.5));
assertFalse(FloatingIslandSample.directCarveEnabled(carve, 1.0));
assertFalse(FloatingIslandSample.directCarveEnabled(null, 0.5));
}
@Test
@@ -0,0 +1,148 @@
package art.arcane.iris.modules.carve.field;
import art.arcane.iris.core.modules.CarveTestWorld;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.modules.carve.Cave;
import com.volmit.noise.NoiseFactory;
import org.junit.Test;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.BitSet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class CaveCarverTest {
private static final int CHUNKS = 8;
private static final int SIZE = CHUNKS * 16;
private static final int SURFACE_Y = 160;
private static final int LAYERS = SURFACE_Y + 1;
private static final int WORLD_BOTTOM_Y = 0;
private static final int WORLD_HEIGHT = 256;
private static final long SEED = 91_277L;
private static final String TUNNELS = "{\"tunnel\": {\"width\": {\"min\": 4, \"max\": 6}, \"stretch\": 48}, \"opensToSurface\": true}";
private final NoiseFactory noise = new CarveTestWorld().resources().noise();
@Test
public void theSameSeedCarvesTheSameCaveAndAnotherSeedADifferentOne() {
BitSet first = carve(TUNNELS, SEED, false);
assertFalse(first.isEmpty());
assertEquals(first, carve(TUNNELS, SEED, false));
assertNotEquals(first, carve(TUNNELS, SEED + 1, false));
}
@Test
public void tunnelsJoinIntoOneNetwork() {
BitSet carved = carve(TUNNELS, SEED, false);
double largestShare = largestConnectedShare(carved);
assertTrue("largest connected share " + largestShare, largestShare > 0.7D);
}
@Test
public void thinTunnelsSurviveBetweenTheLatticePoints() {
BitSet carved = carve("{\"tunnel\": {\"width\": {\"min\": 2, \"max\": 3}, \"stretch\": 48}, \"opensToSurface\": true}", SEED, false);
double largestShare = largestConnectedShare(carved);
assertTrue("largest connected share " + largestShare, largestShare > 0.5D);
}
@Test
public void pillarsLeaveRockStandingInACavern() {
String open = "{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3}}";
String pillared = "{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3, \"pillars\": {\"spacing\": 14, \"thickness\": 4}}}";
BitSet withoutPillars = carve(open, SEED, false);
BitSet withPillars = carve(pillared, SEED, false);
assertTrue(withPillars.cardinality() < withoutPillars.cardinality());
BitSet onlyWithPillars = (BitSet) withPillars.clone();
onlyWithPillars.andNot(withoutPillars);
assertTrue("pillars only ever keep rock", onlyWithPillars.isEmpty());
}
@Test
public void aCaveOpensTheSurfaceOnlyWhereItMayAndKeepsItsRockElsewhere() {
String cave = "{\"tunnel\": {\"width\": {\"min\": 5, \"max\": 7}, \"stretch\": 32}, \"opensToSurface\": true, \"surfaceClearance\": 10}";
BitSet open = carve(cave, SEED, false);
BitSet sealed = carve(cave, SEED, true);
assertTrue("an open cave reaches the surface somewhere", highestCarvedY(open) == SURFACE_Y);
assertTrue("a sealed cave keeps its clearance: " + highestCarvedY(sealed), highestCarvedY(sealed) <= SURFACE_Y - 10);
}
private BitSet carve(String caveJson, long seed, boolean sealEveryColumn) {
CaveCarver carver = new CaveCarver(TestSettings.of(Cave.class, caveJson), noise, seed, WORLD_BOTTOM_Y, WORLD_HEIGHT);
int[] surfaceY = new int[256];
Arrays.fill(surfaceY, SURFACE_Y);
double[] weight = new double[256];
Arrays.fill(weight, 1D);
boolean[] sealed = new boolean[256];
Arrays.fill(sealed, sealEveryColumn);
BitSet carved = new BitSet(SIZE * SIZE * LAYERS);
for (int chunkX = 0; chunkX < CHUNKS; chunkX++) {
for (int chunkZ = 0; chunkZ < CHUNKS; chunkZ++) {
int originX = chunkX * 16;
int originZ = chunkZ * 16;
carver.carve(originX, originZ, surfaceY, weight, sealed, (localX, y, localZ) -> carved.set(index(originX + localX, y, originZ + localZ)));
}
}
return carved;
}
private static int index(int x, int y, int z) {
return (y * SIZE * SIZE) + (z * SIZE) + x;
}
private static int highestCarvedY(BitSet carved) {
return (carved.length() - 1) / (SIZE * SIZE);
}
private static double largestConnectedShare(BitSet carved) {
BitSet seen = new BitSet(carved.size());
ArrayDeque<Integer> open = new ArrayDeque<>();
int largest = 0;
for (int root = carved.nextSetBit(0); root >= 0; root = carved.nextSetBit(root + 1)) {
if (seen.get(root)) {
continue;
}
int size = 0;
seen.set(root);
open.add(root);
while (!open.isEmpty()) {
int block = open.poll();
size++;
int x = block % SIZE;
int z = (block / SIZE) % SIZE;
int y = block / (SIZE * SIZE);
visit(carved, seen, open, x + 1, y, z);
visit(carved, seen, open, x - 1, y, z);
visit(carved, seen, open, x, y + 1, z);
visit(carved, seen, open, x, y - 1, z);
visit(carved, seen, open, x, y, z + 1);
visit(carved, seen, open, x, y, z - 1);
}
largest = Math.max(largest, size);
}
return largest / (double) carved.cardinality();
}
private static void visit(BitSet carved, BitSet seen, ArrayDeque<Integer> open, int x, int y, int z) {
if (x < 0 || z < 0 || y < 0 || x >= SIZE || z >= SIZE || y >= LAYERS) {
return;
}
int block = index(x, y, z);
if (carved.get(block) && !seen.get(block)) {
seen.set(block);
open.add(block);
}
}
}
@@ -850,88 +850,6 @@
"global-clutter"
]
},
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 700
},
"baseDensityStyle": {
"style": "PERLIN_IRIS",
"zoom": 0.72
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.54
},
"warpStyle": {
"style": "FRACTAL_WATER",
"zoom": 0.5
},
"baseWeight": 0.9,
"detailWeight": 0.11,
"warpStrength": 0.24,
"densityThreshold": {
"min": -0.14,
"max": -0.06,
"style": {
"style": "SIMPLEX",
"zoom": 0.74
}
},
"thresholdBias": 0.14,
"sampleStep": 3,
"surfaceClearance": 5,
"allowSurfaceBreak": true,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.6,
"surfaceBreakDepth": 16,
"surfaceBreakThresholdBoost": 0.1,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": [
{
"style": {
"style": "SIMPLEX_VASCULAR",
"zoom": 1.08
},
"weight": 0.08,
"threshold": 0.03,
"verticalRange": {
"min": 24,
"max": 660
},
"invert": false
},
{
"style": {
"style": "FRACTAL_FBM_SIMPLEX",
"zoom": 0.24
},
"weight": 0.04,
"threshold": 0.08,
"verticalRange": {
"min": 6,
"max": 240
},
"invert": true
}
],
"verticalEdgeFade": 24,
"verticalEdgeFadeStrength": 0.18,
"minCarveCells": 24,
"recoveryThresholdBoost": 0.07
},
"carving": [
{
"id": "global-deepdark-band",
@@ -76,57 +76,6 @@
"beach/clutter"
]
},
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 90
},
"baseDensityStyle": {
"style": "IRIS_DOUBLE",
"zoom": 0.8
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"baseWeight": 1,
"detailWeight": 0,
"warpStrength": 0,
"densityThreshold": {
"min": -0.1,
"max": -0.04,
"style": {
"style": "SIMPLEX",
"zoom": 0.5
}
},
"thresholdBias": 0.14,
"sampleStep": 3,
"surfaceClearance": 12,
"allowSurfaceBreak": false,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.99,
"surfaceBreakDepth": 4,
"surfaceBreakThresholdBoost": 0.02,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": []
},
"caveBiomeZoom": 3.6,
"entitySpawners": [
"hot/cave",
@@ -135,57 +135,6 @@
"mushroom/food"
]
},
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 100
},
"baseDensityStyle": {
"style": "CELLULAR",
"zoom": 0.9
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"baseWeight": 1.0,
"detailWeight": 0.0,
"warpStrength": 0.0,
"densityThreshold": {
"min": -0.12,
"max": -0.06,
"style": {
"style": "SIMPLEX",
"zoom": 0.5
}
},
"thresholdBias": 0.1,
"sampleStep": 3,
"surfaceClearance": 12,
"allowSurfaceBreak": false,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.99,
"surfaceBreakDepth": 4,
"surfaceBreakThresholdBoost": 0.02,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": []
},
"caveBiomeZoom": 3.2,
"entitySpawners": [
"mushroom/cave",
@@ -64,57 +64,6 @@
"swamp/food"
]
},
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 80
},
"baseDensityStyle": {
"style": "FRACTAL_SMOKE",
"zoom": 0.45
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"baseWeight": 1,
"detailWeight": 0,
"warpStrength": 0,
"densityThreshold": {
"min": -0.14,
"max": -0.06,
"style": {
"style": "SIMPLEX",
"zoom": 0.5
}
},
"thresholdBias": 0.06,
"sampleStep": 3,
"surfaceClearance": 12,
"allowSurfaceBreak": false,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.99,
"surfaceBreakDepth": 4,
"surfaceBreakThresholdBoost": 0.02,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": []
},
"caveBiomeZoom": 3.2,
"entitySpawners": [
"swamp/cave",
@@ -34,57 +34,6 @@
{"biome": "carving/deepravine", "weight": 1},
{"biome": "carving/chalk-gardens", "weight": 1}
],
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 60
},
"baseDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.4
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"baseWeight": 1.0,
"detailWeight": 0.0,
"warpStrength": 0.0,
"densityThreshold": {
"min": -0.16,
"max": -0.08,
"style": {
"style": "SIMPLEX",
"zoom": 0.5
}
},
"thresholdBias": 0.12,
"sampleStep": 3,
"surfaceClearance": 12,
"allowSurfaceBreak": false,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.99,
"surfaceBreakDepth": 4,
"surfaceBreakThresholdBoost": 0.02,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": []
},
"caveBiomeZoom": 3.1,
"entitySpawners": [
"temperate/cave",
@@ -198,88 +198,6 @@
}
}
],
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 620
},
"baseDensityStyle": {
"style": "PERLIN_IRIS",
"zoom": 0.8
},
"detailDensityStyle": {
"style": "FRACTAL_BILLOW_SIMPLEX",
"zoom": 0.52
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.46
},
"baseWeight": 0.91,
"detailWeight": 0.1,
"warpStrength": 0.18,
"densityThreshold": {
"min": -0.12,
"max": -0.04,
"style": {
"style": "SIMPLEX",
"zoom": 0.7
}
},
"thresholdBias": 0.12,
"sampleStep": 2,
"surfaceClearance": 6,
"allowSurfaceBreak": true,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.9
},
"surfaceBreakNoiseThreshold": 0.68,
"surfaceBreakDepth": 12,
"surfaceBreakThresholdBoost": 0.1,
"objectMinDepthBelowSurface": 16,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 18,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": [
{
"style": {
"style": "SIMPLEX_VASCULAR",
"zoom": 0.98
},
"weight": 0.08,
"threshold": 0.03,
"verticalRange": {
"min": 24,
"max": 680
},
"invert": false
},
{
"style": {
"style": "FRACTAL_BILLOW_SIMPLEX",
"zoom": 0.34
},
"weight": 0.04,
"threshold": 0.07,
"verticalRange": {
"min": 8,
"max": 260
},
"invert": true
}
],
"verticalEdgeFade": 26,
"verticalEdgeFadeStrength": 0.18,
"minCarveCells": 24,
"recoveryThresholdBoost": 0.07
},
"caveMinDepthBelowSurface": 10,
"children": [
{"biome": "carving/amethyst", "weight": 1}
@@ -850,88 +850,6 @@
"global-clutter"
]
},
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 700
},
"baseDensityStyle": {
"style": "PERLIN_IRIS",
"zoom": 0.72
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.54
},
"warpStyle": {
"style": "FRACTAL_WATER",
"zoom": 0.5
},
"baseWeight": 0.9,
"detailWeight": 0.11,
"warpStrength": 0.24,
"densityThreshold": {
"min": -0.14,
"max": -0.06,
"style": {
"style": "SIMPLEX",
"zoom": 0.74
}
},
"thresholdBias": 0.14,
"sampleStep": 3,
"surfaceClearance": 5,
"allowSurfaceBreak": true,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.6,
"surfaceBreakDepth": 16,
"surfaceBreakThresholdBoost": 0.1,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": [
{
"style": {
"style": "SIMPLEX_VASCULAR",
"zoom": 1.08
},
"weight": 0.08,
"threshold": 0.03,
"verticalRange": {
"min": 24,
"max": 660
},
"invert": false
},
{
"style": {
"style": "FRACTAL_FBM_SIMPLEX",
"zoom": 0.24
},
"weight": 0.04,
"threshold": 0.08,
"verticalRange": {
"min": 6,
"max": 240
},
"invert": true
}
],
"verticalEdgeFade": 24,
"verticalEdgeFadeStrength": 0.18,
"minCarveCells": 24,
"recoveryThresholdBoost": 0.07
},
"carving": [
{
"id": "global-deepdark-band",
@@ -45,57 +45,6 @@
"temperate/food"
]
},
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 120
},
"baseDensityStyle": {
"style": "PERLIN",
"zoom": 0.55
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.5
},
"baseWeight": 1,
"detailWeight": 0,
"warpStrength": 0,
"densityThreshold": {
"min": -0.14,
"max": -0.06,
"style": {
"style": "SIMPLEX",
"zoom": 0.5
}
},
"thresholdBias": 0.06,
"sampleStep": 3,
"surfaceClearance": 12,
"allowSurfaceBreak": false,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.99,
"surfaceBreakDepth": 4,
"surfaceBreakThresholdBoost": 0.02,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": []
},
"caveBiomeZoom": 3.3,
"entitySpawners": [
"temperate/cave",
@@ -425,57 +425,6 @@
"cave/clutter"
]
},
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 100
},
"baseDensityStyle": {
"style": "CELLULAR",
"zoom": 0.78
},
"detailDensityStyle": {
"style": "SIMPLEX",
"zoom": 0.32
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.26
},
"baseWeight": 1.0,
"detailWeight": 0.16,
"warpStrength": 0.32,
"densityThreshold": {
"min": -0.08,
"max": 0.02,
"style": {
"style": "SIMPLEX",
"zoom": 0.42
}
},
"thresholdBias": 0.06,
"sampleStep": 2,
"surfaceClearance": 12,
"allowSurfaceBreak": false,
"surfaceBreakStyle": {
"style": "SIMPLEX",
"zoom": 0.88
},
"surfaceBreakNoiseThreshold": 0.99,
"surfaceBreakDepth": 4,
"surfaceBreakThresholdBoost": 0.02,
"objectMinDepthBelowSurface": 14,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 12,
"allowFluid": true,
"fluidMinDepthBelowSurface": 20,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": []
},
"caveBiomeZoom": 3.3,
"entitySpawners": [
"temperate/cave",
@@ -3,68 +3,6 @@
"derivative": "minecraft:lush_caves",
"vanillaDerivative": "minecraft:lush_caves",
"caveMinDepthBelowSurface": 9,
"caveProfile": {
"enabled": true,
"verticalRange": {
"min": 6,
"max": 700
},
"baseDensityStyle": {
"style": "SIMPLEX_VASCULAR",
"zoom": 0.88
},
"detailDensityStyle": {
"style": "FRACTAL_BILLOW_SIMPLEX",
"zoom": 0.42
},
"warpStyle": {
"style": "SIMPLEX",
"zoom": 0.28
},
"baseWeight": 0.9,
"detailWeight": 0.12,
"warpStrength": 0.38,
"densityThreshold": {
"min": -0.13,
"max": -0.035,
"style": {
"style": "SIMPLEX",
"zoom": 0.66
}
},
"thresholdBias": 0.08,
"sampleStep": 2,
"surfaceClearance": 9,
"allowSurfaceBreak": false,
"objectMinDepthBelowSurface": 13,
"defaultObjectAnchor": "FLOOR",
"defaultObjectPlaceMode": "ORGANIC_STILT",
"anchorScanStep": 1,
"anchorSearchAttempts": 16,
"allowFluid": true,
"fluidMinDepthBelowSurface": 18,
"fluidRequiresFloor": true,
"allowLava": true,
"modules": [
{
"style": {
"style": "FRACTAL_BILLOW_SIMPLEX",
"zoom": 0.34
},
"weight": 0.06,
"threshold": 0.06,
"verticalRange": {
"min": 12,
"max": 420
},
"invert": true
}
],
"verticalEdgeFade": 22,
"verticalEdgeFadeStrength": 0.15,
"minCarveCells": 20,
"recoveryThresholdBoost": 0.06
},
"wall": {
"style": {
"style": "SIMPLEX",