From f69d9128d51a7233e439af95e1c56bda27870cab Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 9 Oct 2026 14:32:17 +0200 Subject: [PATCH] Make deposit settings IrisApi types only: DepositGenerator and its enums in the builtin package with BlockSpec palettes, the palette, ore, replace and clump logic in ResolvedDeposit, and IrisDepositGenerator deleted --- README.md | 5 + .../builtin/deposit/DepositBiomeScope.java | 29 + .../builtin/deposit/DepositGenerator.java | 227 ++++++++ .../deposit/DepositHeightDistribution.java | 31 ++ .../deposit/DepositPlacementScope.java | 31 ++ .../iris/builtin/deposit/DepositSettings.java | 10 +- .../iris/builtin/deposit/DepositShape.java | 31 ++ .../iris/engine/modifier/DepositModule.java | 6 +- .../iris/engine/modifier/DepositPlacer.java | 67 ++- .../iris/engine/modifier/ResolvedDeposit.java | 408 ++++++++++++++ .../deposit/IrisDepositBiomeScope.java | 11 - .../terrain/deposit/IrisDepositGenerator.java | 525 ------------------ .../IrisDepositHeightDistribution.java | 13 - .../deposit/IrisDepositPlacementScope.java | 13 - .../terrain/deposit/IrisDepositShape.java | 13 - 15 files changed, 808 insertions(+), 612 deletions(-) create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/DepositBiomeScope.java create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/DepositGenerator.java create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/DepositHeightDistribution.java create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/DepositPlacementScope.java create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/DepositShape.java create mode 100644 src/main/java/art/arcane/iris/engine/modifier/ResolvedDeposit.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositBiomeScope.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositHeightDistribution.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositPlacementScope.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositShape.java diff --git a/README.md b/README.md index c2b3b66e1..14f5443ee 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ pools and jigsaw pieces as resource kinds (`StructureResources`), from the folde used, and checks them with its validator (`StructureValidator`: assembly samples and vanilla structure replacement) wherever Iris validates a pack; Iris core has no loader or validator of its own for them any more. +Settings move off Iris's classes one feature at a time. `iris:deposit` is the first whose settings are IrisApi types +only: `DepositSettings` holds `DepositGenerator`s (blocks as `BlockSpec`, its enums beside it in +`art.arcane.iris.builtin.deposit`), and packs write the same `deposits` JSON as before. What needs Iris (resolving the +palette, ore checks, clump shapes per world seed) lives in the module's own code, `ResolvedDeposit`. + Every built-in stage is a full port: the module owns its logic and per-engine state, and the mantle stages work out their reach from the pack when it loads. A dimension's `disabledComponents` turns a mantle stage off by its flag (`CARVED`, `OBJECT`, `FLOATING_OBJECT`, `JIGSAW`) or by its stage id. diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositBiomeScope.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositBiomeScope.java new file mode 100644 index 000000000..ec7e9cb86 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositBiomeScope.java @@ -0,0 +1,29 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.deposit; + +import com.volmit.config.Desc; + +@Desc("Selects which biome identity is checked by a deposit's include and exclude filters.") +public enum DepositBiomeScope { + @Desc("Checks the surface biome selected for the deposit column.") + SURFACE, + @Desc("Checks the cave biome selected at the deposit origin.") + CAVE +} diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositGenerator.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositGenerator.java new file mode 100644 index 000000000..ce176754c --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositGenerator.java @@ -0,0 +1,227 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.deposit; + +import com.volmit.block.BlockSpec; +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; +import com.volmit.config.Required; +import com.volmit.config.Snippet; + +import java.util.Collections; +import java.util.List; + +/** + * One kind of deposit a dimension, region or biome generates, as packs write it in {@code "deposits": [...]} or under + * {@code snippet/deposit/}: how many clumps of which blocks, how large, at which heights and in which biomes. A value + * of IrisApi types only; the deposit module builds the clumps and resolves the blocks. + */ +@Snippet("deposit") +@Desc("Creates ore & other block deposits underground") +public final class DepositGenerator { + private static final int MAX_CLUMP_DIMENSION = 11; + + @Required + @MinNumber(-8192) + @MaxNumber(8192) + @Desc("The inclusive minimum origin height in engine-local Y, where 0 is the bottom of the dimension. Negative values let an unclipped vanilla distribution taper into the world floor.") + private int minHeight = 1; + + @Required + @MinNumber(-8192) + @MaxNumber(8192) + @Desc("The inclusive maximum origin height in engine-local Y, where 0 is the bottom of the dimension.") + private int maxHeight = 75; + + @Desc("How origin heights are sampled. CLIPPED_UNIFORM preserves Iris behavior by clipping the band to terrain; UNIFORM and TRIANGLE sample the authored band first and discard cells outside terrain or build height.") + private DepositHeightDistribution heightDistribution = DepositHeightDistribution.CLIPPED_UNIFORM; + + @Desc("TERRAIN places below the generated surface. ABOVE_TERRAIN places only in existing solid hosts above it. FULL_HEIGHT permits existing solid hosts anywhere in the dimension.") + private DepositPlacementScope placementScope = DepositPlacementScope.TERRAIN; + + @MinNumber(0) + @MaxNumber(256) + @Desc("Solid blocks kept between a deposit and the terrain surface. Vanilla-like deposits use 0; the Iris default remains 7.") + private int surfaceClearance = 7; + + @Required + @MinNumber(0) + @MaxNumber(8192) + @Desc("The minimum Iris block count or vanilla configured vein size, selected according to shape.") + private int minSize = 0; + + @Required + @MinNumber(0) + @MaxNumber(8192) + @Desc("The maximum Iris block count or vanilla configured vein size, selected according to shape.") + private int maxSize = 128; + + @Desc("IRIS places a fixed-count cube clump. VANILLA_ELLIPSOID uses Minecraft's chained ellipsoid geometry. VANILLA_SCATTERED uses Minecraft's sparse candidate offsets.") + private DepositShape shape = DepositShape.IRIS; + + @Required + @MinNumber(0) + @MaxNumber(2048) + @Desc("The maximum amount of clumps per chunk") + private int maxPerChunk = 3; + + @Required + @MinNumber(0) + @MaxNumber(2048) + @Desc("The minimum amount of clumps per chunk") + private int minPerChunk = 0; + + @MinNumber(0) + @MaxNumber(1) + @Desc("The chance of the deposit spawning in a chunk") + private double spawnChance = 1; + + @MinNumber(0) + @MaxNumber(1) + @Desc("The chance of each individual clump spawning in a chunk") + private double perClumpSpawnChance = 1; + + @MinNumber(0) + @MaxNumber(1) + @Desc("Chance to discard a candidate ore block when it touches air. This matches vanilla ore exposure reduction.") + private double discardChanceOnAirExposure = 0; + + @Required + @Desc("The palette of blocks to be used in this deposit generator. Each entry is picked uniformly; the per-entry weight field is ignored here.") + private List palette = List.of(); + + @MinNumber(1) + @MaxNumber(64) + @Desc("Ore varience is how many different objects clumps iris will create") + private int varience = 3; + + @Desc("Optional block ids this deposit may replace. An empty list retains Iris's any-solid behavior.") + private List replaceableBlocks = List.of(); + + @Desc("Chooses whether includedBiomes and excludedBiomes inspect the surface biome or the cave biome at the deposit origin.") + private DepositBiomeScope biomeScope = DepositBiomeScope.CAVE; + + @Desc("Optional Iris biome keys or vanilla derivative ids allowed for this deposit.") + private List includedBiomes = List.of(); + + @Desc("Optional Iris biome keys or vanilla derivative ids denied for this deposit.") + private List excludedBiomes = List.of(); + + @Desc("If set to true, this deposit will replace bedrock") + private boolean replaceBedrock = false; + + /** A generator with every option at its default, as packs get it from {@code {}}. */ + public DepositGenerator() { + } + + public int minHeight() { + return minHeight; + } + + public int maxHeight() { + return maxHeight; + } + + public DepositHeightDistribution heightDistribution() { + return heightDistribution == null ? DepositHeightDistribution.CLIPPED_UNIFORM : heightDistribution; + } + + public DepositPlacementScope placementScope() { + return placementScope == null ? DepositPlacementScope.TERRAIN : placementScope; + } + + public int surfaceClearance() { + return surfaceClearance; + } + + public int minSize() { + return minSize; + } + + public int maxSize() { + return maxSize; + } + + public DepositShape shape() { + return shape == null ? DepositShape.IRIS : shape; + } + + public int maxPerChunk() { + return maxPerChunk; + } + + public int minPerChunk() { + return minPerChunk; + } + + public double spawnChance() { + return spawnChance; + } + + public double perClumpSpawnChance() { + return perClumpSpawnChance; + } + + public double discardChanceOnAirExposure() { + return discardChanceOnAirExposure; + } + + public List palette() { + return listOrEmpty(palette); + } + + public int varience() { + return varience; + } + + public List replaceableBlocks() { + return listOrEmpty(replaceableBlocks); + } + + public DepositBiomeScope biomeScope() { + return biomeScope == null ? DepositBiomeScope.CAVE : biomeScope; + } + + public List includedBiomes() { + return listOrEmpty(includedBiomes); + } + + public List excludedBiomes() { + return listOrEmpty(excludedBiomes); + } + + public boolean replaceBedrock() { + return replaceBedrock; + } + + /** The edge of the cube an {@link DepositShape#IRIS} clump of {@link #maxSize()} blocks fills, at most 11. */ + public int maxDimension() { + return Math.min(MAX_CLUMP_DIMENSION, (int) Math.ceil(Math.cbrt(maxSize))); + } + + /** Whether the biome filters need the cave biome at the deposit's origin. */ + public boolean usesCaveBiomeFilter() { + return biomeScope() == DepositBiomeScope.CAVE && (!includedBiomes().isEmpty() || !excludedBiomes().isEmpty()); + } + + private static List listOrEmpty(List list) { + return list == null ? List.of() : Collections.unmodifiableList(list); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositHeightDistribution.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositHeightDistribution.java new file mode 100644 index 000000000..74c41f61f --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositHeightDistribution.java @@ -0,0 +1,31 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.deposit; + +import com.volmit.config.Desc; + +@Desc("Controls how a deposit chooses its origin height within the configured vertical band.") +public enum DepositHeightDistribution { + @Desc("Samples uniformly after clipping the configured band to the terrain and build-height bounds.") + CLIPPED_UNIFORM, + @Desc("Samples uniformly from the configured band, then rejects origins outside the terrain or build-height bounds.") + UNIFORM, + @Desc("Samples toward the middle of the configured band with a triangular distribution, then rejects invalid origins.") + TRIANGLE +} diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositPlacementScope.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositPlacementScope.java new file mode 100644 index 000000000..5a9541033 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositPlacementScope.java @@ -0,0 +1,31 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.deposit; + +import com.volmit.config.Desc; + +@Desc("Controls which vertical part of the world may contain a deposit origin.") +public enum DepositPlacementScope { + @Desc("Places in solid terrain below the generated surface while preserving the configured surface clearance.") + TERRAIN, + @Desc("Places only in existing solid hosts above the generated terrain surface.") + ABOVE_TERRAIN, + @Desc("Places in existing solid hosts anywhere within the dimension build height.") + FULL_HEIGHT +} diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositSettings.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositSettings.java index c9901093e..a6017142b 100644 --- a/src/main/java/art/arcane/iris/builtin/deposit/DepositSettings.java +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositSettings.java @@ -18,7 +18,6 @@ package art.arcane.iris.builtin.deposit; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositGenerator; import com.volmit.FeatureAttachment.Target; import com.volmit.IrisFeature; import com.volmit.config.Desc; @@ -28,22 +27,23 @@ import java.util.List; /** * The deposits one dimension, region or biome declares, written as {@code "deposits": [...]}. Levels stack: - * a chunk gets the deposits of its dimension, its centre column's region and that column's biome. + * a chunk gets the deposits of its dimension, its centre column's region and that column's biome. IrisApi types only, + * like {@link DepositGenerator}. */ @Desc("Ores and other deposits generated in every chunk where this applies") @Feature(id = "iris:deposit", name = "Deposits", alias = "deposits", targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) public final class DepositSettings implements IrisFeature { @Desc("Define deposit generators that this applies to chunks") - private List generators = List.of(); + private List generators = List.of(); public DepositSettings() { } - public DepositSettings(List generators) { + public DepositSettings(List generators) { this.generators = List.copyOf(generators); } - public List generators() { + public List generators() { return generators; } } diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositShape.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositShape.java new file mode 100644 index 000000000..72c3e3022 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositShape.java @@ -0,0 +1,31 @@ +/* + * 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 . + */ + +package art.arcane.iris.builtin.deposit; + +import com.volmit.config.Desc; + +@Desc("Selects the geometry used to build each deposit clump.") +public enum DepositShape { + @Desc("Builds the traditional Iris fixed-block-count cube clump.") + IRIS, + @Desc("Builds a chain of overlapping ellipsoids matching Minecraft's ordinary ore-vein geometry.") + VANILLA_ELLIPSOID, + @Desc("Builds sparse candidate offsets matching Minecraft's scattered-ore geometry.") + VANILLA_SCATTERED +} diff --git a/src/main/java/art/arcane/iris/engine/modifier/DepositModule.java b/src/main/java/art/arcane/iris/engine/modifier/DepositModule.java index e4116ad37..f2889714b 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/DepositModule.java +++ b/src/main/java/art/arcane/iris/engine/modifier/DepositModule.java @@ -19,9 +19,9 @@ package art.arcane.iris.engine.modifier; import art.arcane.iris.builtin.IrisStages; +import art.arcane.iris.builtin.deposit.DepositGenerator; import art.arcane.iris.builtin.deposit.DepositSettings; import art.arcane.iris.core.modules.IrisChunk; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositGenerator; import com.volmit.IrisModule; import com.volmit.ModuleInfo; import com.volmit.config.FeatureSettings; @@ -59,7 +59,7 @@ public final class DepositModule implements IrisModule { private static void place(ChunkStageContext context, List> inChunk) { IrisChunk chunk = IrisChunk.current(); - List generators = generatorsAtCentre(context.settings(), context.originX(), context.originZ()); + List generators = generatorsAtCentre(context.settings(), context.originX(), context.originZ()); if (generators.isEmpty() || chunk.bypassesMantleStages()) { return; } @@ -68,7 +68,7 @@ public final class DepositModule implements IrisModule { } /** Every level's generators at the centre column of the chunk whose first block is {@code originX}, {@code originZ}, in level order. */ - static List generatorsAtCentre(FeatureSettings settings, int originX, int originZ) { + static List generatorsAtCentre(FeatureSettings settings, int originX, int originZ) { return settings.at(DepositSettings.class, originX + CHUNK_CENTRE, originZ + CHUNK_CENTRE).stream() .flatMap(entry -> entry.value().generators().stream()) .toList(); diff --git a/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java b/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java index 21e944c01..ff3844442 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java +++ b/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java @@ -18,12 +18,12 @@ package art.arcane.iris.engine.modifier; +import art.arcane.iris.builtin.deposit.DepositGenerator; +import art.arcane.iris.builtin.deposit.DepositHeightDistribution; +import art.arcane.iris.builtin.deposit.DepositPlacementScope; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.EngineAssignedComponent; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositGenerator; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositHeightDistribution; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositPlacementScope; import art.arcane.iris.engine.object.terrain.deposit.IrisDepositVariant; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver; @@ -42,13 +42,17 @@ import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.util.common.data.B; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Places deposit clumps into one chunk for {@link DepositModule}: one per engine runtime, holding the deposit - * stream's random. Each generator gets its own random, derived from the chunk and its position in the list. + * stream's random and each generator made ready for this engine ({@link ResolvedDeposit}: resolved blocks and clump + * shapes). Each generator gets its own random, derived from the chunk and its position in the list. */ public class DepositPlacer extends EngineAssignedComponent { private final RNG rng; + private final Map resolved = new ConcurrentHashMap<>(); public DepositPlacer(Engine engine) { super(engine, "Deposit"); @@ -56,14 +60,14 @@ public class DepositPlacer extends EngineAssignedComponent { } /** Runs {@code generators}, in order, on the chunk at chunk coordinates {@code x}, {@code z}. */ - public void generate(List generators, Hunk terrain, int x, int z, boolean multicore, + public void generate(List generators, Hunk terrain, int x, int z, boolean multicore, ChunkContext context) { PrecisionStopwatch p = PrecisionStopwatch.start(); generateDeposits(generators, terrain, x, z, multicore, context); getEngine().getMetrics().getDeposit().put(p.getMilliseconds()); } - private void generateDeposits(List generators, Hunk terrain, int x, int z, + private void generateDeposits(List generators, Hunk terrain, int x, int z, boolean multicore, ChunkContext context) { BurstExecutor burst = burst().burst(multicore); @@ -71,7 +75,7 @@ public class DepositPlacer extends EngineAssignedComponent { long mask = 0; MantleChunk chunk = getEngine().getMantle().getMantle().getChunk(x, z).use(); try { - for (IrisDepositGenerator k : generators) { + for (DepositGenerator k : generators) { long finalSeed = seed * ++mask; burst.queue(() -> generate(k, chunk, terrain, rng.nextParallelRNG(finalSeed), x, z, false, context)); } @@ -86,20 +90,21 @@ public class DepositPlacer extends EngineAssignedComponent { } } - public void generate(IrisDepositGenerator k, MantleChunk chunk, Hunk data, RNG rng, int cx, int cz, boolean safe, ChunkContext context) { + public void generate(DepositGenerator k, MantleChunk chunk, Hunk data, RNG rng, int cx, int cz, boolean safe, ChunkContext context) { generate(k, chunk, data, rng, cx, cz, safe, null, context); } - public void generate(IrisDepositGenerator k, MantleChunk chunk, Hunk data, RNG rng, int cx, int cz, boolean safe, HeightMap he, ChunkContext context) { + public void generate(DepositGenerator k, MantleChunk chunk, Hunk data, RNG rng, int cx, int cz, boolean safe, HeightMap he, ChunkContext context) { IrisDimensionCarvingResolver.State carvingState = new IrisDimensionCarvingResolver.State(); - if (k.getSpawnChance() < rng.d()) + ResolvedDeposit deposit = resolved(k); + if (k.spawnChance() < rng.d()) return; - for (int l = 0; l < rng.i(k.getMinPerChunk(), k.getMaxPerChunk() + 1); l++) { - if (k.getPerClumpSpawnChance() < rng.d()) + for (int l = 0; l < rng.i(k.minPerChunk(), k.maxPerChunk() + 1); l++) { + if (k.perClumpSpawnChance() < rng.d()) continue; - IrisObject clump = k.getClump(getEngine(), rng, getData()); + IrisObject clump = deposit.clump(rng); int dim = clump.getW(); int min = dim / 2; @@ -113,8 +118,8 @@ public class DepositPlacer extends EngineAssignedComponent { int x = rng.i(min, max + 1); int z = rng.i(min, max + 1); int terrainSurface = getDepositTerrainSurface(cx, cz, x, z, he, context); - int height = k.getPlacementScope() == IrisDepositPlacementScope.TERRAIN - ? depositSurfaceLimit(terrainSurface, k.getSurfaceClearance()) + int height = k.placementScope() == DepositPlacementScope.TERRAIN + ? depositSurfaceLimit(terrainSurface, k.surfaceClearance()) : getEngine().getHeight() - 1; if (height < 0) { @@ -122,24 +127,24 @@ public class DepositPlacer extends EngineAssignedComponent { } int y = sampleHeight( - k.getHeightDistribution(), rng, k.getMinHeight(), k.getMaxHeight(), + k.heightDistribution(), rng, k.minHeight(), k.maxHeight(), Math.min(height, getEngine().getHeight() - 1)); if (y == Integer.MIN_VALUE) { continue; } - boolean clippedHeight = k.getHeightDistribution() == IrisDepositHeightDistribution.CLIPPED_UNIFORM; + boolean clippedHeight = k.heightDistribution() == DepositHeightDistribution.CLIPPED_UNIFORM; if (clippedHeight && y > height - 2) continue; int biomeY = Math.max(0, Math.min(getEngine().getHeight() - 1, y)); - boolean oreDeposit = k.isOre(getData()); + boolean oreDeposit = deposit.isOre(); IrisBiome surfaceBiome = context.getBiome().get(x, z); IrisBiome depositBiome = oreDeposit || k.usesCaveBiomeFilter() ? getEngine().getCaveBiome( (cx << 4) + x, biomeY, (cz << 4) + z, carvingState) : null; - if (!k.matchesBiome(surfaceBiome, depositBiome)) { + if (!deposit.matchesBiome(surfaceBiome, depositBiome)) { continue; } @@ -153,7 +158,7 @@ public class DepositPlacer extends EngineAssignedComponent { double sizeMultiplier = depositBiome.getOreDepositSizeMultiplier(); if (sizeMultiplier != 1D) { - IrisObject scaledClump = k.getClump(getEngine(), rng, getData(), sizeMultiplier); + IrisObject scaledClump = deposit.clump(rng, sizeMultiplier); int scaledDimension = scaledClump.getW(); x = clampDepositCenter(x, scaledDimension, 16); if (clippedHeight) { @@ -177,7 +182,7 @@ public class DepositPlacer extends EngineAssignedComponent { } int columnSurface = getDepositTerrainSurface(cx, cz, nx, nz, he, context); if (!placementSurfaceAllows( - k.getPlacementScope(), ny, columnSurface, k.getSurfaceClearance())) { + k.placementScope(), ny, columnSurface, k.surfaceClearance())) { continue; } @@ -185,14 +190,14 @@ public class DepositPlacer extends EngineAssignedComponent { if (!canReplaceDepositTarget(current)) { continue; } - if (!k.canReplace(current)) { + if (!deposit.canReplace(current)) { continue; } - if (!k.isReplaceBedrock() && IrisProceduralBlocks.materialKey(current).equals("minecraft:bedrock")) { + if (!k.replaceBedrock() && IrisProceduralBlocks.materialKey(current).equals("minecraft:bedrock")) { continue; } if (shouldDiscardExposed( - k.getDiscardChanceOnAirExposure(), rng.d(), isAdjacentToAir(data, nx, ny, nz))) { + k.discardChanceOnAirExposure(), rng.d(), isAdjacentToAir(data, nx, ny, nz))) { continue; } @@ -209,6 +214,10 @@ public class DepositPlacer extends EngineAssignedComponent { } } + private ResolvedDeposit resolved(DepositGenerator generator) { + return resolved.computeIfAbsent(generator, ignored -> ResolvedDeposit.of(generator, getEngine())); + } + private int getDepositTerrainSurface( int cx, int cz, int localX, int localZ, HeightMap heightMap, ChunkContext context) { @@ -226,7 +235,7 @@ public class DepositPlacer extends EngineAssignedComponent { } static boolean placementSurfaceAllows( - IrisDepositPlacementScope scope, int candidateY, int surfaceY, int surfaceClearance) { + DepositPlacementScope scope, int candidateY, int surfaceY, int surfaceClearance) { int clearance = Math.max(0, surfaceClearance); return switch (scope) { case ABOVE_TERRAIN -> candidateY > surfaceY + clearance; @@ -244,12 +253,12 @@ public class DepositPlacer extends EngineAssignedComponent { } static int sampleHeight( - IrisDepositHeightDistribution distribution, RNG rng, + DepositHeightDistribution distribution, RNG rng, int configuredMinimum, int configuredMaximum, int clippedMaximum) { - int minimum = distribution == IrisDepositHeightDistribution.CLIPPED_UNIFORM + int minimum = distribution == DepositHeightDistribution.CLIPPED_UNIFORM ? Math.max(0, configuredMinimum) : configuredMinimum; - int maximum = distribution == IrisDepositHeightDistribution.CLIPPED_UNIFORM + int maximum = distribution == DepositHeightDistribution.CLIPPED_UNIFORM ? Math.min(clippedMaximum, configuredMaximum) : configuredMaximum; if (minimum > maximum) { @@ -258,7 +267,7 @@ public class DepositPlacer extends EngineAssignedComponent { if (minimum == maximum) { return minimum; } - if (distribution != IrisDepositHeightDistribution.TRIANGLE) { + if (distribution != DepositHeightDistribution.TRIANGLE) { return minimum + rng.nextInt(maximum - minimum + 1); } diff --git a/src/main/java/art/arcane/iris/engine/modifier/ResolvedDeposit.java b/src/main/java/art/arcane/iris/engine/modifier/ResolvedDeposit.java new file mode 100644 index 000000000..1aaf2d4e5 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/modifier/ResolvedDeposit.java @@ -0,0 +1,408 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.modifier; + +import art.arcane.iris.builtin.deposit.DepositBiomeScope; +import art.arcane.iris.builtin.deposit.DepositGenerator; +import art.arcane.iris.builtin.deposit.DepositShape; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import art.arcane.iris.util.common.math.IrisBlockVector; +import art.arcane.iris.util.common.math.Vector3i; +import art.arcane.volmlib.util.collection.KSet; +import art.arcane.volmlib.util.math.BlockPosition; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.block.BlockRegistry; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * One {@link DepositGenerator} made ready for one engine: its palette resolved to the platform's blocks, whether it is + * an ore deposit, the blocks it may replace, and the clump shapes it places, built once per size. What the settings + * describe stays in the settings; everything that needs the platform, the pack or the world seed is here. + */ +final class ResolvedDeposit { + private static final long FNV_OFFSET_BASIS = 0xcbf29ce484222325L; + private static final long FNV_PRIME = 0x100000001b3L; + private static final int MAX_CLUMP_DIMENSION = 11; + private static final int MAX_DEPOSIT_SIZE = 8192; + private static final int VARIANT_SEED_STEP = 2349; + private static final int VARIANT_SEED_OFFSET = 3598; + private static final int MAX_SCATTER_MAGNITUDE = 7; + private static final String MINECRAFT_NAMESPACE = "minecraft:"; + + private final DepositGenerator generator; + private final long depositSeed; + private final List palette; + private final boolean ore; + private final Set replaceableMaterials; + private final Map> clumps = new ConcurrentHashMap<>(); + + /** @param palette the generator's palette as the platform's blocks, in order */ + ResolvedDeposit(DepositGenerator generator, long depositSeed, List palette) { + this.generator = generator; + this.depositSeed = depositSeed; + this.palette = List.copyOf(palette); + this.ore = palette.stream().anyMatch(PlatformBlockState::isOre); + this.replaceableMaterials = replaceableMaterials(generator.replaceableBlocks()); + } + + /** {@code generator} ready for {@code engine}: its blocks resolved through the pack, clumps seeded from the world's deposit seed. */ + static ResolvedDeposit of(DepositGenerator generator, Engine engine) { + BlockRegistry blocks = engine.getData().getPackResources().blocks(); + List palette = generator.palette().stream() + .map(spec -> B.getState(blocks.resolve(spec).key())) + .toList(); + return new ResolvedDeposit(generator, engine.getSeedManager().getDeposit(), palette); + } + + DepositGenerator generator() { + return generator; + } + + /** Whether any block of the palette is an ore: ore deposits follow the cave biome's ore tuning. */ + boolean isOre() { + return ore; + } + + /** Whether the deposit may replace {@code state}: any block when it names none, otherwise only the named ones. */ + boolean canReplace(PlatformBlockState state) { + return generator.replaceableBlocks().isEmpty() || replaceableMaterials.contains(IrisProceduralBlocks.materialKey(state)); + } + + /** Whether the biome the generator's scope picks passes its include and exclude filters. */ + boolean matchesBiome(IrisBiome surfaceBiome, IrisBiome caveBiome) { + IrisBiome selected = generator.biomeScope() == DepositBiomeScope.SURFACE ? surfaceBiome : caveBiome; + if (!generator.includedBiomes().isEmpty() && !matchesAnyBiome(selected, generator.includedBiomes())) { + return false; + } + return generator.excludedBiomes().isEmpty() || !matchesAnyBiome(selected, generator.excludedBiomes()); + } + + /** One clump to place, picked with {@code rng}. */ + IrisObject clump(RNG rng) { + return clump(rng, generator.minSize(), generator.maxSize(), 0L); + } + + /** One clump to place with every size scaled by {@code sizeMultiplier}, as a biome's ore size tuning asks. */ + IrisObject clump(RNG rng, double sizeMultiplier) { + if (sizeMultiplier == 1D) { + return clump(rng); + } + int minSize = scaledDepositSize(generator.minSize(), sizeMultiplier); + int maxSize = scaledDepositSize(generator.maxSize(), sizeMultiplier); + long sizeSeed = ((long) minSize << 32) ^ (maxSize & 0xffffffffL); + return clump(rng, minSize, maxSize, sizeSeed); + } + + private IrisObject clump(RNG rng, int minSize, int maxSize, long sizeSeed) { + if (generator.shape() != DepositShape.IRIS) { + return configuredClump(rng, minSize, maxSize); + } + List variants = clumps.computeIfAbsent(new ClumpSizes(minSize, maxSize), sizes -> { + RNG variantRng = new RNG(depositSeed + stableClumpSalt() + sizeSeed); + List built = new ArrayList<>(); + for (int i = 0; i < generator.varience(); i++) { + built.add(irisClump(variantRng.nextParallelRNG(VARIANT_SEED_STEP * i + VARIANT_SEED_OFFSET), sizes.minSize(), sizes.maxSize())); + } + return List.copyOf(built); + }); + return variants.get(rng.i(0, variants.size())); + } + + static int scaledDepositSize(int size, double multiplier) { + return Math.max(0, Math.min(MAX_DEPOSIT_SIZE, (int) Math.round(size * multiplier))); + } + + /** A hash of everything the generator describes and its resolved palette, so equal generators share clump shapes. */ + long stableClumpSalt() { + long hash = FNV_OFFSET_BASIS; + hash = mix(hash, generator.minHeight()); + hash = mix(hash, generator.maxHeight()); + hash = mixEnum(hash, generator.heightDistribution()); + hash = mixEnum(hash, generator.placementScope()); + hash = mix(hash, generator.surfaceClearance()); + hash = mix(hash, generator.minSize()); + hash = mix(hash, generator.maxSize()); + hash = mixEnum(hash, generator.shape()); + hash = mix(hash, generator.maxPerChunk()); + hash = mix(hash, generator.minPerChunk()); + hash = mix(hash, Double.doubleToLongBits(generator.spawnChance())); + hash = mix(hash, Double.doubleToLongBits(generator.perClumpSpawnChance())); + hash = mix(hash, Double.doubleToLongBits(generator.discardChanceOnAirExposure())); + hash = mix(hash, palette.size()); + for (PlatformBlockState block : palette) { + hash = mixString(hash, block == null ? null : block.key()); + } + hash = mix(hash, generator.varience()); + hash = mixStrings(hash, generator.replaceableBlocks()); + hash = mixEnum(hash, generator.biomeScope()); + hash = mixStrings(hash, generator.includedBiomes()); + hash = mixStrings(hash, generator.excludedBiomes()); + return mix(hash, generator.replaceBedrock() ? 1L : 0L); + } + + private static long mix(long hash, long value) { + return (hash ^ value) * FNV_PRIME; + } + + private static long mixEnum(long hash, Enum value) { + return mixString(hash, value == null ? null : value.name()); + } + + private static long mixString(long hash, String value) { + if (value == null) { + return mix(hash, -1L); + } + long mixed = mix(hash, value.length()); + for (int i = 0; i < value.length(); i++) { + mixed = mix(mixed, value.charAt(i)); + } + return mixed; + } + + private static long mixStrings(long hash, List values) { + long mixed = mix(hash, values.size()); + for (String value : values) { + mixed = mixString(mixed, value); + } + return mixed; + } + + private IrisObject configuredClump(RNG rng, int minSize, int maxSize) { + int size = rng.i(minSize, maxSize + 1); + return switch (generator.shape()) { + case VANILLA_ELLIPSOID -> vanillaEllipsoid(rng, size); + case VANILLA_SCATTERED -> vanillaScattered(rng, size); + case IRIS -> irisClump(rng, minSize, maxSize); + }; + } + + /** Minecraft's ordinary ore vein: a chain of overlapping ellipsoids whose reach grows with {@code size}. */ + IrisObject vanillaEllipsoid(RNG rng, int size) { + if (size <= 0) { + return new IrisObject(1, 1, 1); + } + + float angle = rng.nextFloat() * (float) Math.PI; + float reach = size / 8F; + double startX = Math.sin(angle) * reach; + double endX = -Math.sin(angle) * reach; + double startZ = Math.cos(angle) * reach; + double endZ = -Math.cos(angle) * reach; + double startY = rng.nextInt(3) - 2; + double endY = rng.nextInt(3) - 2; + double[] nodes = new double[size * 4]; + + for (int i = 0; i < size; i++) { + float progress = (float) i / size; + double radiusNoise = rng.nextDouble() * size / 16D; + nodes[i * 4] = startX + (endX - startX) * progress; + nodes[i * 4 + 1] = startY + (endY - startY) * progress; + nodes[i * 4 + 2] = startZ + (endZ - startZ) * progress; + nodes[i * 4 + 3] = ((Math.sin(Math.PI * progress) + 1D) * radiusNoise + 1D) / 2D; + } + + for (int i = 0; i < size - 1; i++) { + if (nodes[i * 4 + 3] <= 0D) { + continue; + } + for (int j = i + 1; j < size; j++) { + if (nodes[j * 4 + 3] <= 0D) { + continue; + } + double dx = nodes[i * 4] - nodes[j * 4]; + double dy = nodes[i * 4 + 1] - nodes[j * 4 + 1]; + double dz = nodes[i * 4 + 2] - nodes[j * 4 + 2]; + double dr = nodes[i * 4 + 3] - nodes[j * 4 + 3]; + if (dr * dr <= dx * dx + dy * dy + dz * dz) { + continue; + } + if (dr > 0D) { + nodes[j * 4 + 3] = -1D; + } else { + nodes[i * 4 + 3] = -1D; + } + } + } + + KSet cells = new KSet<>(); + for (int i = 0; i < size; i++) { + double radius = nodes[i * 4 + 3]; + if (radius < 0D) { + continue; + } + double centerX = nodes[i * 4]; + double centerY = nodes[i * 4 + 1]; + double centerZ = nodes[i * 4 + 2]; + int minX = (int) Math.floor(centerX - radius); + int maxX = Math.max((int) Math.floor(centerX + radius), minX); + int minY = (int) Math.floor(centerY - radius); + int maxY = Math.max((int) Math.floor(centerY + radius), minY); + int minZ = (int) Math.floor(centerZ - radius); + int maxZ = Math.max((int) Math.floor(centerZ + radius), minZ); + + for (int x = minX; x <= maxX; x++) { + double nx = (x + 0.5D - centerX) / radius; + if (nx * nx >= 1D) { + continue; + } + for (int y = minY; y <= maxY; y++) { + double ny = (y + 0.5D - centerY) / radius; + if (nx * nx + ny * ny >= 1D) { + continue; + } + for (int z = minZ; z <= maxZ; z++) { + double nz = (z + 0.5D - centerZ) / radius; + if (nx * nx + ny * ny + nz * nz < 1D) { + cells.add(new BlockPosition(x, y, z)); + } + } + } + } + } + + return objectFromCells(cells, rng); + } + + /** Minecraft's scattered ore: up to {@code size} candidate offsets, the later ones further from the centre. */ + IrisObject vanillaScattered(RNG rng, int size) { + KSet cells = new KSet<>(); + int candidates = rng.nextInt(Math.max(0, size) + 1); + for (int i = 0; i < candidates; i++) { + int magnitude = Math.min(i, MAX_SCATTER_MAGNITUDE); + cells.add(new BlockPosition( + Math.round((rng.nextFloat() - rng.nextFloat()) * magnitude), + Math.round((rng.nextFloat() - rng.nextFloat()) * magnitude), + Math.round((rng.nextFloat() - rng.nextFloat()) * magnitude))); + } + return objectFromCells(cells, rng); + } + + private IrisObject objectFromCells(KSet cells, RNG rng) { + if (cells.isEmpty()) { + return new IrisObject(1, 1, 1); + } + + int minX = Integer.MAX_VALUE; + int minY = Integer.MAX_VALUE; + int minZ = Integer.MAX_VALUE; + int maxX = Integer.MIN_VALUE; + int maxY = Integer.MIN_VALUE; + int maxZ = Integer.MIN_VALUE; + for (BlockPosition cell : cells) { + minX = Math.min(minX, cell.getX()); + minY = Math.min(minY, cell.getY()); + minZ = Math.min(minZ, cell.getZ()); + maxX = Math.max(maxX, cell.getX()); + maxY = Math.max(maxY, cell.getY()); + maxZ = Math.max(maxZ, cell.getZ()); + } + + int extentX = Math.max(Math.abs(minX), Math.abs(maxX)); + int extentY = Math.max(Math.abs(minY), Math.abs(maxY)); + int extentZ = Math.max(Math.abs(minZ), Math.abs(maxZ)); + IrisObject object = new IrisObject(extentX * 2 + 1, extentY * 2 + 1, extentZ * 2 + 1); + for (BlockPosition cell : cells) { + object.setUnsigned(cell.getX() + extentX, cell.getY() + extentY, cell.getZ() + extentZ, nextBlock(rng)); + } + return object; + } + + /** The traditional Iris clump: a cube just large enough for the block count, filled at random cells. */ + private IrisObject irisClump(RNG rng, int minSize, int maxSize) { + int remaining = rng.i(minSize, maxSize + 1); + if (remaining == 1) { + IrisObject single = new IrisObject(1, 1, 1); + Vector3i center = single.getCenter(); + single.getBlocks().put(new IrisBlockVector(center.getX(), center.getY(), center.getZ()), nextBlock(rng)); + return single; + } + + int dimension = Math.min(MAX_CLUMP_DIMENSION, (int) Math.ceil(Math.cbrt(remaining))); + IrisObject clump = new IrisObject(dimension, dimension, dimension); + if (remaining >= dimension * dimension * dimension) { + fillCube(clump, dimension, rng); + return clump; + } + + KSet filled = new KSet<>(); + while (remaining > 0) { + BlockPosition cell = new BlockPosition(rng.i(0, dimension), rng.i(0, dimension), rng.i(0, dimension)); + if (!filled.add(cell)) { + continue; + } + remaining--; + clump.setUnsigned(cell.getX(), cell.getY(), cell.getZ(), nextBlock(rng)); + } + return clump; + } + + private void fillCube(IrisObject clump, int dimension, RNG rng) { + for (int z = 0; z < dimension; z++) { + for (int y = 0; y < dimension; y++) { + for (int x = 0; x < dimension; x++) { + clump.setUnsigned(x, y, z, nextBlock(rng)); + } + } + } + } + + private PlatformBlockState nextBlock(RNG rng) { + return palette.get(rng.i(0, palette.size())); + } + + private static Set replaceableMaterials(List keys) { + Set materials = new KSet<>(); + for (String key : keys) { + PlatformBlockState state = B.getStateOrNull(key, false); + if (state != null) { + materials.add(IrisProceduralBlocks.materialKey(state)); + } + } + return materials; + } + + private static boolean matchesAnyBiome(IrisBiome biome, List configuredBiomes) { + if (biome == null) { + return false; + } + for (String configured : configuredBiomes) { + String namespaced = configured.contains(":") ? configured : MINECRAFT_NAMESPACE + configured; + if (configured.equals(biome.getLoadKey()) + || namespaced.equals(biome.getDerivativeKey()) + || namespaced.equals(biome.getVanillaDerivativeKey())) { + return true; + } + } + return false; + } + + /** The sizes one set of clump variants is built for: the generator's own, or scaled by a biome's ore tuning. */ + record ClumpSizes(int minSize, int maxSize) { + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositBiomeScope.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositBiomeScope.java deleted file mode 100644 index 1f9c6ace1..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositBiomeScope.java +++ /dev/null @@ -1,11 +0,0 @@ -package art.arcane.iris.engine.object.terrain.deposit; - -import art.arcane.iris.engine.object.annotations.Desc; - -@Desc("Selects which biome identity is checked by a deposit's include and exclude filters.") -public enum IrisDepositBiomeScope { - @Desc("Checks the surface biome selected for the deposit column.") - SURFACE, - @Desc("Checks the cave biome selected at the deposit origin.") - CAVE -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositGenerator.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositGenerator.java deleted file mode 100644 index c900f3b70..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositGenerator.java +++ /dev/null @@ -1,525 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package art.arcane.iris.engine.object.terrain.deposit; - -import art.arcane.iris.engine.object.material.IrisBlockData; -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.data.cache.AtomicCache; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.MaxNumber; -import art.arcane.iris.engine.object.annotations.MinNumber; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import art.arcane.iris.util.common.math.IrisBlockVector; -import art.arcane.iris.util.common.math.Vector3i; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.collection.KSet; -import art.arcane.volmlib.util.math.BlockPosition; -import art.arcane.volmlib.util.math.RNG; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -@Snippet("deposit") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Creates ore & other block deposits underground") -@Data -public class IrisDepositGenerator { - private static final long FNV_OFFSET_BASIS = 0xcbf29ce484222325L; - private static final long FNV_PRIME = 0x100000001b3L; - - private final transient ConcurrentMap> objects = new ConcurrentHashMap<>(); - private final transient AtomicCache> blockData = new AtomicCache<>(); - private final transient AtomicCache ore = new AtomicCache<>(); - private final transient AtomicCache> replaceableBlockData = new AtomicCache<>(); - private final transient ConcurrentMap> scaledObjects = new ConcurrentHashMap<>(); - @Required - @MinNumber(-8192) - @MaxNumber(8192) - @Desc("The inclusive minimum origin height in engine-local Y, where 0 is the bottom of the dimension. Negative values let an unclipped vanilla distribution taper into the world floor.") - private int minHeight = 1; - @Required - @MinNumber(-8192) - @MaxNumber(8192) - @Desc("The inclusive maximum origin height in engine-local Y, where 0 is the bottom of the dimension.") - private int maxHeight = 75; - @Desc("How origin heights are sampled. CLIPPED_UNIFORM preserves Iris behavior by clipping the band to terrain; UNIFORM and TRIANGLE sample the authored band first and discard cells outside terrain or build height.") - private IrisDepositHeightDistribution heightDistribution = IrisDepositHeightDistribution.CLIPPED_UNIFORM; - @Desc("TERRAIN places below the generated surface. ABOVE_TERRAIN places only in existing solid hosts above it. FULL_HEIGHT permits existing solid hosts anywhere in the dimension.") - private IrisDepositPlacementScope placementScope = IrisDepositPlacementScope.TERRAIN; - @MinNumber(0) - @MaxNumber(256) - @Desc("Solid blocks kept between a deposit and the terrain surface. Vanilla-like deposits use 0; the Iris default remains 7.") - private int surfaceClearance = 7; - @Required - @MinNumber(0) - @MaxNumber(8192) - @Desc("The minimum Iris block count or vanilla configured vein size, selected according to shape.") - private int minSize = 0; - @Required - @MinNumber(0) - @MaxNumber(8192) - @Desc("The maximum Iris block count or vanilla configured vein size, selected according to shape.") - private int maxSize = 128; - @Desc("IRIS places a fixed-count cube clump. VANILLA_ELLIPSOID uses Minecraft's chained ellipsoid geometry. VANILLA_SCATTERED uses Minecraft's sparse candidate offsets.") - private IrisDepositShape shape = IrisDepositShape.IRIS; - @Required - @MinNumber(0) - @MaxNumber(2048) - @Desc("The maximum amount of clumps per chunk") - private int maxPerChunk = 3; - @Required - @MinNumber(0) - @MaxNumber(2048) - @Desc("The minimum amount of clumps per chunk") - private int minPerChunk = 0; - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance of the deposit spawning in a chunk") - private double spawnChance = 1; - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance of each individual clump spawning in a chunk") - private double perClumpSpawnChance = 1; - @MinNumber(0) - @MaxNumber(1) - @Desc("Chance to discard a candidate ore block when it touches air. This matches vanilla ore exposure reduction.") - private double discardChanceOnAirExposure = 0; - @Required - @ArrayType(min = 1, type = IrisBlockData.class) - @Desc("The palette of blocks to be used in this deposit generator. Each entry is picked uniformly; the per-entry weight field is ignored here.") - private KList palette = new KList<>(); - @MinNumber(1) - @MaxNumber(64) - @Desc("Ore varience is how many different objects clumps iris will create") - private int varience = 3; - @ArrayType(min = 1, type = String.class) - @Desc("Optional block ids this deposit may replace. An empty list retains Iris's any-solid behavior.") - private KList replaceableBlocks = new KList<>(); - @Desc("Chooses whether includedBiomes and excludedBiomes inspect the surface biome or the cave biome at the deposit origin.") - private IrisDepositBiomeScope biomeScope = IrisDepositBiomeScope.CAVE; - @ArrayType(min = 1, type = String.class) - @Desc("Optional Iris biome keys or vanilla derivative ids allowed for this deposit.") - private KList includedBiomes = new KList<>(); - @ArrayType(min = 1, type = String.class) - @Desc("Optional Iris biome keys or vanilla derivative ids denied for this deposit.") - private KList excludedBiomes = new KList<>(); - @Desc("If set to true, this deposit will replace bedrock") - private boolean replaceBedrock = false; - - public IrisObject getClump(Engine engine, RNG rng, IrisData rdata) { - if (shape != IrisDepositShape.IRIS) { - return generateConfiguredClumpObject(rng, rdata, minSize, maxSize); - } - - ClumpCacheKey cacheKey = new ClumpCacheKey(engine.getSeedManager().getDeposit(), minSize, maxSize); - KList objects = this.objects.computeIfAbsent(cacheKey, key -> { - RNG rngv = new RNG(key.depositSeed() + stableClumpSalt(rdata)); - KList objectsf = new KList<>(); - - for (int i = 0; i < varience; i++) { - objectsf.add(generateClumpObject( - rngv.nextParallelRNG(2349 * i + 3598), rdata, key.minSize(), key.maxSize())); - } - - return objectsf; - }); - return objects.get(rng.i(0, objects.size())); - } - - public IrisObject getClump(Engine engine, RNG rng, IrisData rdata, double sizeMultiplier) { - if (sizeMultiplier == 1D) { - return getClump(engine, rng, rdata); - } - - int scaledMinSize = scaledDepositSize(minSize, sizeMultiplier); - int scaledMaxSize = scaledDepositSize(maxSize, sizeMultiplier); - if (shape != IrisDepositShape.IRIS) { - return generateConfiguredClumpObject(rng, rdata, scaledMinSize, scaledMaxSize); - } - - ClumpCacheKey cacheKey = new ClumpCacheKey( - engine.getSeedManager().getDeposit(), scaledMinSize, scaledMaxSize); - KList objects = scaledObjects.computeIfAbsent(cacheKey, key -> { - long sizeSeed = ((long) key.minSize() << 32) ^ (key.maxSize() & 0xffffffffL); - RNG rngv = new RNG(key.depositSeed() + stableClumpSalt(rdata) + sizeSeed); - KList generated = new KList<>(); - - for (int i = 0; i < varience; i++) { - generated.add(generateClumpObject( - rngv.nextParallelRNG(2349 * i + 3598), rdata, key.minSize(), key.maxSize())); - } - - return generated; - }); - return objects.get(rng.i(0, objects.size())); - } - - public int getMaxDimension() { - return Math.min(11, (int) Math.ceil(Math.cbrt(maxSize))); - } - - static int scaledDepositSize(int size, double multiplier) { - return Math.max(0, Math.min(8192, (int) Math.round(size * multiplier))); - } - - long stableClumpSalt(IrisData rdata) { - long hash = FNV_OFFSET_BASIS; - hash = mix(hash, minHeight); - hash = mix(hash, maxHeight); - hash = mixEnum(hash, heightDistribution); - hash = mixEnum(hash, placementScope); - hash = mix(hash, surfaceClearance); - hash = mix(hash, minSize); - hash = mix(hash, maxSize); - hash = mixEnum(hash, shape); - hash = mix(hash, maxPerChunk); - hash = mix(hash, minPerChunk); - hash = mix(hash, Double.doubleToLongBits(spawnChance)); - hash = mix(hash, Double.doubleToLongBits(perClumpSpawnChance)); - hash = mix(hash, Double.doubleToLongBits(discardChanceOnAirExposure)); - KList resolvedPalette = getBlockData(rdata); - hash = mix(hash, resolvedPalette.size()); - for (PlatformBlockState block : resolvedPalette) { - hash = mixString(hash, block == null ? null : block.key()); - } - hash = mix(hash, varience); - hash = mixStrings(hash, replaceableBlocks); - hash = mixEnum(hash, biomeScope); - hash = mixStrings(hash, includedBiomes); - hash = mixStrings(hash, excludedBiomes); - return mix(hash, replaceBedrock ? 1L : 0L); - } - - private static long mix(long hash, long value) { - return (hash ^ value) * FNV_PRIME; - } - - private static long mixEnum(long hash, Enum value) { - return mixString(hash, value == null ? null : value.name()); - } - - private static long mixString(long hash, String value) { - if (value == null) { - return mix(hash, -1L); - } - long mixed = mix(hash, value.length()); - for (int i = 0; i < value.length(); i++) { - mixed = mix(mixed, value.charAt(i)); - } - return mixed; - } - - private static long mixStrings(long hash, KList values) { - if (values == null) { - return mix(hash, -1L); - } - long mixed = mix(hash, values.size()); - for (String value : values) { - mixed = mixString(mixed, value); - } - return mixed; - } - - private IrisObject generateConfiguredClumpObject(RNG rng, IrisData rdata, int clumpMinSize, int clumpMaxSize) { - int size = rng.i(clumpMinSize, clumpMaxSize + 1); - return switch (shape) { - case VANILLA_ELLIPSOID -> generateVanillaEllipsoid(rng, rdata, size); - case VANILLA_SCATTERED -> generateVanillaScattered(rng, rdata, size); - case IRIS -> generateClumpObject(rng, rdata, clumpMinSize, clumpMaxSize); - }; - } - - IrisObject generateVanillaEllipsoid(RNG rng, IrisData rdata, int size) { - if (size <= 0) { - return new IrisObject(1, 1, 1); - } - - float angle = rng.nextFloat() * (float) Math.PI; - float reach = size / 8F; - double startX = Math.sin(angle) * reach; - double endX = -Math.sin(angle) * reach; - double startZ = Math.cos(angle) * reach; - double endZ = -Math.cos(angle) * reach; - double startY = rng.nextInt(3) - 2; - double endY = rng.nextInt(3) - 2; - double[] nodes = new double[size * 4]; - - for (int i = 0; i < size; i++) { - float progress = (float) i / size; - double radiusNoise = rng.nextDouble() * size / 16D; - nodes[i * 4] = startX + (endX - startX) * progress; - nodes[i * 4 + 1] = startY + (endY - startY) * progress; - nodes[i * 4 + 2] = startZ + (endZ - startZ) * progress; - nodes[i * 4 + 3] = ((Math.sin(Math.PI * progress) + 1D) * radiusNoise + 1D) / 2D; - } - - for (int i = 0; i < size - 1; i++) { - if (nodes[i * 4 + 3] <= 0D) { - continue; - } - for (int j = i + 1; j < size; j++) { - if (nodes[j * 4 + 3] <= 0D) { - continue; - } - double dx = nodes[i * 4] - nodes[j * 4]; - double dy = nodes[i * 4 + 1] - nodes[j * 4 + 1]; - double dz = nodes[i * 4 + 2] - nodes[j * 4 + 2]; - double dr = nodes[i * 4 + 3] - nodes[j * 4 + 3]; - if (dr * dr <= dx * dx + dy * dy + dz * dz) { - continue; - } - if (dr > 0D) { - nodes[j * 4 + 3] = -1D; - } else { - nodes[i * 4 + 3] = -1D; - } - } - } - - KSet cells = new KSet<>(); - for (int i = 0; i < size; i++) { - double radius = nodes[i * 4 + 3]; - if (radius < 0D) { - continue; - } - double centerX = nodes[i * 4]; - double centerY = nodes[i * 4 + 1]; - double centerZ = nodes[i * 4 + 2]; - int minX = (int) Math.floor(centerX - radius); - int maxX = Math.max((int) Math.floor(centerX + radius), minX); - int minY = (int) Math.floor(centerY - radius); - int maxY = Math.max((int) Math.floor(centerY + radius), minY); - int minZ = (int) Math.floor(centerZ - radius); - int maxZ = Math.max((int) Math.floor(centerZ + radius), minZ); - - for (int x = minX; x <= maxX; x++) { - double nx = (x + 0.5D - centerX) / radius; - if (nx * nx >= 1D) { - continue; - } - for (int y = minY; y <= maxY; y++) { - double ny = (y + 0.5D - centerY) / radius; - if (nx * nx + ny * ny >= 1D) { - continue; - } - for (int z = minZ; z <= maxZ; z++) { - double nz = (z + 0.5D - centerZ) / radius; - if (nx * nx + ny * ny + nz * nz < 1D) { - cells.add(new BlockPosition(x, y, z)); - } - } - } - } - } - - return objectFromCells(cells, rng, rdata); - } - - IrisObject generateVanillaScattered(RNG rng, IrisData rdata, int size) { - KSet cells = new KSet<>(); - int candidates = rng.nextInt(Math.max(0, size) + 1); - for (int i = 0; i < candidates; i++) { - int magnitude = Math.min(i, 7); - cells.add(new BlockPosition( - Math.round((rng.nextFloat() - rng.nextFloat()) * magnitude), - Math.round((rng.nextFloat() - rng.nextFloat()) * magnitude), - Math.round((rng.nextFloat() - rng.nextFloat()) * magnitude))); - } - return objectFromCells(cells, rng, rdata); - } - - private IrisObject objectFromCells(KSet cells, RNG rng, IrisData rdata) { - if (cells.isEmpty()) { - return new IrisObject(1, 1, 1); - } - - int minX = Integer.MAX_VALUE; - int minY = Integer.MAX_VALUE; - int minZ = Integer.MAX_VALUE; - int maxX = Integer.MIN_VALUE; - int maxY = Integer.MIN_VALUE; - int maxZ = Integer.MIN_VALUE; - for (BlockPosition cell : cells) { - minX = Math.min(minX, cell.getX()); - minY = Math.min(minY, cell.getY()); - minZ = Math.min(minZ, cell.getZ()); - maxX = Math.max(maxX, cell.getX()); - maxY = Math.max(maxY, cell.getY()); - maxZ = Math.max(maxZ, cell.getZ()); - } - - int extentX = Math.max(Math.abs(minX), Math.abs(maxX)); - int extentY = Math.max(Math.abs(minY), Math.abs(maxY)); - int extentZ = Math.max(Math.abs(minZ), Math.abs(maxZ)); - IrisObject object = new IrisObject(extentX * 2 + 1, extentY * 2 + 1, extentZ * 2 + 1); - for (BlockPosition cell : cells) { - object.setUnsigned( - cell.getX() + extentX, - cell.getY() + extentY, - cell.getZ() + extentZ, - nextBlock(rng, rdata)); - } - return object; - } - - private IrisObject generateClumpObject(RNG rngv, IrisData rdata, int clumpMinSize, int clumpMaxSize) { - int s = rngv.i(clumpMinSize, clumpMaxSize + 1); - if (s == 1) { - IrisObject o = new IrisObject(1, 1, 1); - Vector3i center = o.getCenter(); - o.getBlocks().put(new IrisBlockVector(center.getX(), center.getY(), center.getZ()), nextBlock(rngv, rdata)); - return o; - } - - int dim = Math.min(11, (int) Math.ceil(Math.cbrt(s))); - IrisObject o = new IrisObject(dim, dim, dim); - - int volume = dim * dim * dim; - if (s >= volume) { - int x = 0, y = 0, z = 0; - - while (z < dim) { - o.setUnsigned(x++, y, z, nextBlock(rngv, rdata)); - - if (x == dim) { - x = 0; - y++; - } - - if (y == dim) { - y = 0; - z++; - } - } - return o; - } - - KSet set = new KSet<>(); - while (s > 0) { - BlockPosition ang = new BlockPosition( - rngv.i(0, dim), - rngv.i(0, dim), - rngv.i(0, dim) - ); - if (!set.add(ang)) continue; - - s--; - o.setUnsigned(ang.getX(), ang.getY(), ang.getZ(), nextBlock(rngv, rdata)); - } - - return o; - } - - private PlatformBlockState nextBlock(RNG rngv, IrisData rdata) { - return getBlockData(rdata).get(rngv.i(0, getBlockData(rdata).size())); - } - - public KList getBlockData(IrisData rdata) { - return blockData.aquire(() -> - { - KList blockData = new KList<>(); - - for (IrisBlockData ix : palette) { - PlatformBlockState bx = ix.getBlockData(rdata); - - if (bx != null) { - blockData.add(bx); - } - } - - return blockData; - }); - } - - public boolean isOre(IrisData rdata) { - return ore.aquire(() -> { - for (PlatformBlockState block : getBlockData(rdata)) { - if (block.isOre()) { - return true; - } - } - - return false; - }); - } - - public boolean canReplace(PlatformBlockState state) { - if (replaceableBlocks == null || replaceableBlocks.isEmpty()) { - return true; - } - return replaceableBlockData.aquire(this::resolveReplaceableBlocks) - .contains(IrisProceduralBlocks.materialKey(state)); - } - - public boolean matchesBiome(IrisBiome surfaceBiome, IrisBiome caveBiome) { - IrisBiome selected = biomeScope == IrisDepositBiomeScope.SURFACE ? surfaceBiome : caveBiome; - if (includedBiomes != null && !includedBiomes.isEmpty() && !matchesAnyBiome(selected, includedBiomes)) { - return false; - } - return excludedBiomes == null || excludedBiomes.isEmpty() || !matchesAnyBiome(selected, excludedBiomes); - } - - public boolean usesCaveBiomeFilter() { - return biomeScope == IrisDepositBiomeScope.CAVE - && ((includedBiomes != null && !includedBiomes.isEmpty()) - || (excludedBiomes != null && !excludedBiomes.isEmpty())); - } - - private KSet resolveReplaceableBlocks() { - KSet resolved = new KSet<>(); - for (String key : replaceableBlocks) { - PlatformBlockState state = B.getStateOrNull(key, false); - if (state != null) { - resolved.add(IrisProceduralBlocks.materialKey(state)); - } - } - return resolved; - } - - private boolean matchesAnyBiome(IrisBiome biome, KList configuredBiomes) { - if (biome == null) { - return false; - } - for (String configured : configuredBiomes) { - String namespaced = configured.contains(":") ? configured : "minecraft:" + configured; - if (configured.equals(biome.getLoadKey()) - || namespaced.equals(biome.getDerivativeKey()) - || namespaced.equals(biome.getVanillaDerivativeKey())) { - return true; - } - } - return false; - } - - record ClumpCacheKey(long depositSeed, int minSize, int maxSize) { - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositHeightDistribution.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositHeightDistribution.java deleted file mode 100644 index 57d9cf943..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositHeightDistribution.java +++ /dev/null @@ -1,13 +0,0 @@ -package art.arcane.iris.engine.object.terrain.deposit; - -import art.arcane.iris.engine.object.annotations.Desc; - -@Desc("Controls how a deposit chooses its origin height within the configured vertical band.") -public enum IrisDepositHeightDistribution { - @Desc("Samples uniformly after clipping the configured band to the terrain and build-height bounds.") - CLIPPED_UNIFORM, - @Desc("Samples uniformly from the configured band, then rejects origins outside the terrain or build-height bounds.") - UNIFORM, - @Desc("Samples toward the middle of the configured band with a triangular distribution, then rejects invalid origins.") - TRIANGLE -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositPlacementScope.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositPlacementScope.java deleted file mode 100644 index 9fd557476..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositPlacementScope.java +++ /dev/null @@ -1,13 +0,0 @@ -package art.arcane.iris.engine.object.terrain.deposit; - -import art.arcane.iris.engine.object.annotations.Desc; - -@Desc("Controls which vertical part of the world may contain a deposit origin.") -public enum IrisDepositPlacementScope { - @Desc("Places in solid terrain below the generated surface while preserving the configured surface clearance.") - TERRAIN, - @Desc("Places only in existing solid hosts above the generated terrain surface.") - ABOVE_TERRAIN, - @Desc("Places in existing solid hosts anywhere within the dimension build height.") - FULL_HEIGHT -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositShape.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositShape.java deleted file mode 100644 index f8d2d1ea2..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositShape.java +++ /dev/null @@ -1,13 +0,0 @@ -package art.arcane.iris.engine.object.terrain.deposit; - -import art.arcane.iris.engine.object.annotations.Desc; - -@Desc("Selects the geometry used to build each deposit clump.") -public enum IrisDepositShape { - @Desc("Builds the traditional Iris fixed-block-count cube clump.") - IRIS, - @Desc("Builds a chain of overlapping ellipsoids matching Minecraft's ordinary ore-vein geometry.") - VANILLA_ELLIPSOID, - @Desc("Builds sparse candidate offsets matching Minecraft's scattered-ore geometry.") - VANILLA_SCATTERED -}