From 6617cc3957b9f591b710d2d7ba443ab6e926392f Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:27:45 +0200 Subject: [PATCH 1/7] Ores, hideOresForHiddenOre, deposit variants and the ore deposit multipliers are settings of iris:terrain and iris:deposit OreSettings (ores), HideOresSettings (hideOresForHiddenOre), DepositVariantSettings (depositVariants), OreFrequencySettings and OreSizeSettings are IrisApi-typed features under the keys packs always wrote. ResolvedOre/ResolvedOres/TerrainOres keep the resolved blocks and the chance noise per world, warmed in the same order and with the same seeds as before; ResolvedDepositVariant resolves the remaps. IrisBiome, IrisRegion and IrisDimension lose the fields and their caches; IrisOreGenerator, IrisBiomeOres, IrisOreGeneratorBounds and IrisDepositVariant are deleted. Inferred biome variants keep the module settings of the biome they are copied from. --- .../iris/builtin/deposit/DepositVariant.java | 67 +++++++++ .../deposit/DepositVariantSettings.java | 52 +++++++ .../builtin/deposit/OreFrequencySettings.java | 49 +++++++ .../iris/builtin/deposit/OreSizeSettings.java | 49 +++++++ .../builtin/terrain/HideOresSettings.java | 46 +++++++ .../iris/builtin/terrain/OreGenerator.java | 80 +++++++++++ .../iris/builtin/terrain/OreSettings.java | 52 +++++++ .../iris/engine/actuator/HiddenOres.java | 32 +++++ .../iris/engine/actuator/OreWarmUp.java | 29 ++-- .../iris/engine/actuator/ResolvedOre.java | 125 +++++++++++++++++ .../iris/engine/actuator/ResolvedOres.java | 119 ++++++++++++++++ .../iris/engine/actuator/TerrainModule.java | 83 +++++------ .../iris/engine/actuator/TerrainOres.java | 53 +++++++ .../iris/engine/modifier/DepositModule.java | 11 ++ .../iris/engine/modifier/DepositPlacer.java | 44 ++++-- .../engine/modifier/PerfectionModule.java | 3 +- .../modifier/ResolvedDepositVariant.java | 66 +++++++++ .../object/terrain/deposit/IrisBiomeOres.java | 130 ------------------ .../terrain/deposit/IrisDepositVariant.java | 87 ------------ .../terrain/deposit/IrisOreGenerator.java | 81 ----------- .../deposit/IrisOreGeneratorBounds.java | 44 ------ .../engine/object/world/biome/IrisBiome.java | 73 +--------- .../object/world/dimension/IrisDimension.java | 101 -------------- .../object/world/region/IrisRegion.java | 99 ------------- 24 files changed, 884 insertions(+), 691 deletions(-) create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/DepositVariant.java create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/DepositVariantSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/OreFrequencySettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/deposit/OreSizeSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/HideOresSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/OreGenerator.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/OreSettings.java create mode 100644 src/main/java/art/arcane/iris/engine/actuator/HiddenOres.java create mode 100644 src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java create mode 100644 src/main/java/art/arcane/iris/engine/actuator/ResolvedOres.java create mode 100644 src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java create mode 100644 src/main/java/art/arcane/iris/engine/modifier/ResolvedDepositVariant.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisBiomeOres.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositVariant.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGeneratorBounds.java diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositVariant.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositVariant.java new file mode 100644 index 000000000..582301354 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositVariant.java @@ -0,0 +1,67 @@ +/* + * 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; +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.Map; + +/** + * One deposit ore remap rule, an entry of {@code depositVariants}: within a vertical band, ore blocks are rewritten to + * alternate blocks. A value of IrisApi types only; {@code ResolvedDepositVariant} resolves the blocks. + */ +@Snippet("deposit-variant") +@Desc("Remaps ore block ids to alternate block ids within a vertical band. Ores declared at dimension, region, and biome scope can be rewritten at placement time (for example, iron_ore -> deepslate_iron_ore inside a deep carving band, or yourmod:iron -> yourmod:moon_iron inside a lunar biome).") +public final class DepositVariant { + @Required + @MinNumber(-2048) + @MaxNumber(8192) + @Desc("Inclusive minimum world Y this variant applies at.") + private int minHeight = 0; + + @Required + @MinNumber(-2048) + @MaxNumber(8192) + @Desc("Inclusive maximum world Y this variant applies at.") + private int maxHeight = 0; + + @Required + @Desc("Source block id (for example `minecraft:iron_ore`) -> replacement block id (for example `minecraft:deepslate_iron_ore`). Any block id the data loader resolves is accepted, including external/mod blocks. Source match is by material only, so block properties on the source key are ignored.") + private Map remap = Map.of(); + + public DepositVariant() { + } + + public int minHeight() { + return minHeight; + } + + public int maxHeight() { + return maxHeight; + } + + public Map remap() { + return remap == null ? Map.of() : Collections.unmodifiableMap(remap); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/deposit/DepositVariantSettings.java b/src/main/java/art/arcane/iris/builtin/deposit/DepositVariantSettings.java new file mode 100644 index 000000000..e6a6d15ef --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/DepositVariantSettings.java @@ -0,0 +1,52 @@ +/* + * 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.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MinItems; + +import java.util.Collections; +import java.util.List; + +/** + * The deposit ore remap rules one dimension, region or biome declares, written as {@code "depositVariants": [...]}, the list + * of {@link DepositVariant}s. The biome's rules apply first, then the region's, then the dimension's; the first matching rule wins. + */ +@Desc("Deposit ore remap rules. Each entry declares a vertical band and a source->replacement block id map. Applied biome first, then region, then dimension; first matching rule wins.") +@Feature(id = "iris:deposit/variants", name = "Deposit variants", key = "depositVariants", root = "variants", + targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) +public final class DepositVariantSettings implements IrisFeature { + @MinItems(1) + @Desc("Deposit ore remap rules. Each entry declares a vertical band and a source->replacement block id map. Applied biome first, then region, then dimension; first matching rule wins.") + private List variants = List.of(); + + public DepositVariantSettings() { + } + + public DepositVariantSettings(List variants) { + this.variants = List.copyOf(variants); + } + + public List variants() { + return variants == null ? List.of() : Collections.unmodifiableList(variants); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/deposit/OreFrequencySettings.java b/src/main/java/art/arcane/iris/builtin/deposit/OreFrequencySettings.java new file mode 100644 index 000000000..e279b0df6 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/OreFrequencySettings.java @@ -0,0 +1,49 @@ +/* + * 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.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; + +/** A biome's {@code oreDepositFrequencyMultiplier}, written as the bare number. */ +@Desc("Multiplier applied to the frequency of every ore deposit whose center is inside this biome. A value of 0.4 keeps 40% of ore veins while leaving non-ore deposits unchanged.") +@Feature(id = "iris:deposit/ore-frequency", name = "Ore deposit frequency", key = "oreDepositFrequencyMultiplier", root = "multiplier", targets = Target.BIOME) +public final class OreFrequencySettings implements IrisFeature { + private static final double UNCHANGED = 1D; + + @MinNumber(0) + @MaxNumber(1) + @Desc("Multiplier applied to the frequency of every ore deposit whose center is inside this biome. A value of 0.4 keeps 40% of ore veins while leaving non-ore deposits unchanged.") + private double multiplier = UNCHANGED; + + public OreFrequencySettings() { + } + + public OreFrequencySettings(double multiplier) { + this.multiplier = multiplier; + } + + public double multiplier() { + return multiplier; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/deposit/OreSizeSettings.java b/src/main/java/art/arcane/iris/builtin/deposit/OreSizeSettings.java new file mode 100644 index 000000000..80e1d5892 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/deposit/OreSizeSettings.java @@ -0,0 +1,49 @@ +/* + * 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.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; + +/** A biome's {@code oreDepositSizeMultiplier}, written as the bare number. */ +@Desc("Multiplier applied to the block count of every ore deposit whose center is inside this biome. Non-ore deposits are unchanged.") +@Feature(id = "iris:deposit/ore-size", name = "Ore deposit size", key = "oreDepositSizeMultiplier", root = "multiplier", targets = Target.BIOME) +public final class OreSizeSettings implements IrisFeature { + private static final double UNCHANGED = 1D; + + @MinNumber(0.01) + @MaxNumber(16) + @Desc("Multiplier applied to the block count of every ore deposit whose center is inside this biome. Non-ore deposits are unchanged.") + private double multiplier = UNCHANGED; + + public OreSizeSettings() { + } + + public OreSizeSettings(double multiplier) { + this.multiplier = multiplier; + } + + public double multiplier() { + return multiplier; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/HideOresSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/HideOresSettings.java new file mode 100644 index 000000000..afebc3443 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/HideOresSettings.java @@ -0,0 +1,46 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** + * A dimension's {@code hideOresForHiddenOre}: whether every ore block the generator would place is replaced with its base + * material. Written as the bare boolean. + */ +@Desc("When true, every ore block the generator would place (terrain ores, deposits, ores inside objects) is replaced with its base material such as stone, deepslate or netherrack, so drop-control plugins like HiddenOre can manage ore rewards themselves") +@Feature(id = "iris:terrain/hide-ores", name = "Hide ores", key = "hideOresForHiddenOre", root = "hide", targets = Target.DIMENSION) +public final class HideOresSettings implements IrisFeature { + @Desc("When true, every ore block the generator would place (terrain ores, deposits, ores inside objects) is replaced with its base material such as stone, deepslate or netherrack, so drop-control plugins like HiddenOre can manage ore rewards themselves") + private boolean hide = false; + + public HideOresSettings() { + } + + public HideOresSettings(boolean hide) { + this.hide = hide; + } + + public boolean hide() { + return hide; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/OreGenerator.java b/src/main/java/art/arcane/iris/builtin/terrain/OreGenerator.java new file mode 100644 index 000000000..1f9cb8f47 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/OreGenerator.java @@ -0,0 +1,80 @@ +/* + * 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.terrain; + +import com.volmit.block.PaletteSpec; +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; +import com.volmit.config.Range; +import com.volmit.noise.NoiseStyle; + +import java.util.List; + +/** + * One ore generator of a dimension, region or biome, an entry of its {@code ores} list: single ore blocks scattered + * through the terrain by a noise field, in a vertical band. A value of IrisApi types only; the terrain module resolves + * its blocks and builds its noise ({@code ResolvedOre}). + */ +@Desc("Scatters single ore blocks through terrain by sampling a noise field at every block in a vertical band. Defined on dimensions, regions, or biomes; the most specific level wins.") +public final class OreGenerator { + private static final double DEFAULT_THRESHOLD = 0.5; + private static final double DEFAULT_RANGE_MIN = 30; + private static final double DEFAULT_RANGE_MAX = 80; + + @Desc("The ore blocks to place. An empty palette generates nothing, so this must be set for the generator to have any effect.") + private PaletteSpec palette = PaletteSpec.of(List.of()); + + @Desc("The noise style sampled per block to decide where ore appears. STATIC gives independent random speckle; smoother styles give veiny clusters.") + private NoiseStyle chanceStyle = NoiseStyle.of("STATIC"); + + @Desc("When true this generator also replaces surface-layer blocks (it runs before layers and fluid); when false it only replaces underground rock.") + private boolean generateSurface = false; + + @MinNumber(0) + @MaxNumber(1) + @Desc("Noise cutoff: a block becomes ore when the sampled noise is at or below this value, so higher means more ore. 0 disables, 1 replaces everything in range.") + private double threshold = DEFAULT_THRESHOLD; + + @Desc("Vertical band (min, max) this ore can generate in, in engine-local Y where 0 is the bottom of the dimension, not world Y.") + private Range range = Range.of(DEFAULT_RANGE_MIN, DEFAULT_RANGE_MAX); + + public OreGenerator() { + } + + public PaletteSpec palette() { + return palette; + } + + public NoiseStyle chanceStyle() { + return chanceStyle; + } + + public boolean generateSurface() { + return generateSurface; + } + + public double threshold() { + return threshold; + } + + public Range range() { + return range; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/OreSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/OreSettings.java new file mode 100644 index 000000000..ae2d39553 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/OreSettings.java @@ -0,0 +1,52 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MinItems; + +import java.util.Collections; +import java.util.List; + +/** + * The ore generators one dimension, region or biome declares, written as {@code "ores": [...]}, the list of generators. + * Levels stack: a column's ores come from its biome first, then its region, then the dimension. IrisApi types only, + * like {@link OreGenerator}. + */ +@Desc("Collection of ores to be generated") +@Feature(id = "iris:terrain/ores", name = "Ores", key = "ores", root = "generators", targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) +public final class OreSettings implements IrisFeature { + @MinItems(1) + @Desc("Collection of ores to be generated") + private List generators = List.of(); + + public OreSettings() { + } + + public OreSettings(List generators) { + this.generators = List.copyOf(generators); + } + + public List generators() { + return generators == null ? List.of() : Collections.unmodifiableList(generators); + } +} diff --git a/src/main/java/art/arcane/iris/engine/actuator/HiddenOres.java b/src/main/java/art/arcane/iris/engine/actuator/HiddenOres.java new file mode 100644 index 000000000..48b5a3535 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/actuator/HiddenOres.java @@ -0,0 +1,32 @@ +/* + * 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.actuator; + +import art.arcane.iris.builtin.terrain.HideOresSettings; +import art.arcane.iris.engine.object.world.dimension.IrisDimension; + +/** Whether a dimension hides its ores ({@code hideOresForHiddenOre}): the terrain places none and the perfection pass turns the rest into their base blocks. */ +public final class HiddenOres { + private HiddenOres() { + } + + public static boolean in(IrisDimension dimension) { + return dimension.getModuleSettings().find(HideOresSettings.class).map(HideOresSettings::hide).orElse(false); + } +} diff --git a/src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.java b/src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.java index 0e5bbbaf9..11935ef1f 100644 --- a/src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.java +++ b/src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.java @@ -19,55 +19,52 @@ package art.arcane.iris.engine.actuator; import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGenerator; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.math.RNG; import java.util.Comparator; +import java.util.function.LongSupplier; /** * Builds the noise of every ore generator the world's biomes, regions and dimension declare before generation needs it. - * A generator keeps the noise of the first random it is given, so each one is warmed with the random of its place in + * A generator keeps the noise of the first seed it is given, so each one is warmed with the seed of its place in * this order: the biomes by key, the regions by key, then the dimension. The order is part of what a world generates. */ final class OreWarmUp { private static final long ROOT_SEED_SALT = 7777L; private final Engine engine; + private final TerrainOres ores; private final RNG root; private int warmed; OreWarmUp(Engine engine) { + this(engine, TerrainOres.of(engine)); + } + + OreWarmUp(Engine engine, TerrainOres ores) { this.engine = engine; + this.ores = ores; this.root = new RNG(engine.getSeedManager().getComponent() + ROOT_SEED_SALT); } void warm() { + LongSupplier seeds = () -> root.nextParallelRNG(warmed++).getSeed(); + KList biomes = engine.getAllBiomes(); biomes.sort(Comparator.comparing(IrisBiome::getLoadKey)); for (IrisBiome biome : biomes) { - warmAll(biome.getOres()); + ores.of(biome).warm(seeds); } KList regions = engine.getDimension().getAllRegions(engine); regions.sort(Comparator.comparing(IrisRegion::getLoadKey)); for (IrisRegion region : regions) { - warmAll(region.getOres()); + ores.of(region).warm(seeds); } - warmAll(engine.getDimension().getOres()); - } - - private void warmAll(KList ores) { - if (ores == null) { - return; - } - for (IrisOreGenerator ore : ores) { - if (ore != null) { - ore.warm(root.nextParallelRNG(warmed++), engine.getData()); - } - } + ores.of(engine.getDimension()).warm(seeds); } } diff --git a/src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java b/src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java new file mode 100644 index 000000000..ee0b330a4 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java @@ -0,0 +1,125 @@ +/* + * 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.actuator; + +import art.arcane.iris.builtin.terrain.OreGenerator; +import art.arcane.iris.engine.data.cache.AtomicCache; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import com.volmit.block.BlockRegistry; +import com.volmit.block.BlockSpec; +import com.volmit.block.PaletteSampler; +import com.volmit.noise.NoiseFactory; +import com.volmit.noise.NoiseSampler; + +import java.util.ArrayList; +import java.util.List; + +/** + * One {@link OreGenerator} made ready for one world: its palette resolved to the platform's blocks and the noise that + * decides where it places ore, built from the seed it is warmed with or, when nothing warmed it, from the terrain seed + * of its first use. The palette picks with the terrain seed. What the generator describes stays in the settings; + * everything that needs the platform, the pack or the world seed is here. + */ +final class ResolvedOre { + private final OreGenerator settings; + private final NoiseFactory noise; + private final BlockRegistry blockRegistry; + private final long terrainSeed; + private final List blocks; + private final AtomicCache chance = new AtomicCache<>(); + private final AtomicCache palette = new AtomicCache<>(); + + /** + * @param terrainSeed the seed the palette picks with, and the noise is built from when nothing warmed it first + * @param blocks the palette as the platform's blocks, each repeated by its weight + */ + ResolvedOre(OreGenerator settings, NoiseFactory noise, BlockRegistry blockRegistry, long terrainSeed, List blocks) { + this.settings = settings; + this.noise = noise; + this.blockRegistry = blockRegistry; + this.terrainSeed = terrainSeed; + this.blocks = List.copyOf(blocks); + } + + /** {@code settings} ready for {@code engine}: its blocks resolved through the pack, its picks seeded with the terrain seed. */ + static ResolvedOre of(OreGenerator settings, Engine engine) { + var resources = engine.getData().getPackResources(); + BlockRegistry registry = resources.blocks(); + return new ResolvedOre(settings, resources.noise(), registry, engine.getSeedManager().getTerrain(), weighted(registry, settings.palette().palette())); + } + + private static List weighted(BlockRegistry registry, List specs) { + List weighted = new ArrayList<>(); + for (BlockSpec spec : specs) { + PlatformBlockState state = B.getState(registry.resolve(spec).key()); + if (state == null) { + continue; + } + for (int n = 0; n < spec.weight(); n++) { + weighted.add(state); + } + } + return weighted; + } + + boolean generatesSurface() { + return settings.generateSurface(); + } + + double minY() { + return settings.range().min(); + } + + double maxY() { + return settings.range().max(); + } + + /** Builds the chance noise from {@code seed}, unless it is built already: the first seed it is given is the one it keeps. */ + void warm(long seed) { + chance.aquire(() -> noise.sampler(settings.chanceStyle(), seed)); + } + + /** The ore block at the position, or null when the position is out of the band, the chance noise is above the threshold or the palette has no block. */ + PlatformBlockState generate(int x, int y, int z) { + if (!settings.range().contains(y)) { + return null; + } + if (settings.palette().palette().isEmpty()) { + return null; + } + NoiseSampler sampler = chance.aquire(() -> noise.sampler(settings.chanceStyle(), terrainSeed)); + if (sampler.sample(x, y, z) > settings.threshold()) { + return null; + } + return pick(x, y, z); + } + + private PlatformBlockState pick(int x, int y, int z) { + if (blocks.isEmpty()) { + return null; + } + if (blocks.size() == 1) { + return blocks.getFirst(); + } + PaletteSampler sampler = palette.aquire(() -> blockRegistry.palette(settings.palette(), terrainSeed)); + return B.getState(sampler.at(x, y, z).key()); + } +} diff --git a/src/main/java/art/arcane/iris/engine/actuator/ResolvedOres.java b/src/main/java/art/arcane/iris/engine/actuator/ResolvedOres.java new file mode 100644 index 000000000..e3df4ad35 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/actuator/ResolvedOres.java @@ -0,0 +1,119 @@ +/* + * 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.actuator; + +import art.arcane.iris.builtin.terrain.OreGenerator; +import art.arcane.iris.builtin.terrain.OreSettings; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.spi.PlatformBlockState; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.LongSupplier; + +/** + * The ore generators of one dimension, region or biome made ready ({@link ResolvedOre}), in the order its settings list them + * and split into the ones that also replace surface blocks and the ones that only replace rock. A level without ores is + * {@link #NONE}. + */ +final class ResolvedOres { + static final ResolvedOres NONE = new ResolvedOres(List.of()); + + private final List all; + private final List surface; + private final List underground; + private final YBand surfaceBand; + private final YBand undergroundBand; + + ResolvedOres(List all) { + this.all = List.copyOf(all); + this.surface = this.all.stream().filter(ResolvedOre::generatesSurface).toList(); + this.underground = this.all.stream().filter(ore -> !ore.generatesSurface()).toList(); + this.surfaceBand = YBand.of(surface); + this.undergroundBand = YBand.of(underground); + } + + /** {@code settings} ready for {@code engine}; generators the pack wrote as {@code null} are left out. */ + static ResolvedOres of(OreSettings settings, Engine engine) { + List ores = new ArrayList<>(); + for (OreGenerator generator : settings.generators()) { + if (generator != null) { + ores.add(ResolvedOre.of(generator, engine)); + } + } + return ores.isEmpty() ? NONE : new ResolvedOres(ores); + } + + /** The heights where any surface ore can generate. */ + YBand surfaceBand() { + return surfaceBand; + } + + /** The heights where any rock-only ore can generate. */ + YBand undergroundBand() { + return undergroundBand; + } + + /** Warms every ore in the order the settings list them, each with the next seed. */ + void warm(LongSupplier seeds) { + for (ResolvedOre ore : all) { + ore.warm(seeds.getAsLong()); + } + } + + PlatformBlockState generateSurface(int x, int y, int z) { + return firstOre(surface, x, y, z); + } + + PlatformBlockState generateUnderground(int x, int y, int z) { + return firstOre(underground, x, y, z); + } + + private static PlatformBlockState firstOre(List ores, int x, int y, int z) { + for (int index = 0; index < ores.size(); index++) { + PlatformBlockState ore = ores.get(index).generate(x, y, z); + if (ore != null) { + return ore; + } + } + return null; + } + + /** The lowest and highest height any of a set of ores reaches; empty when there are none. */ + record YBand(boolean hasOres, double min, double max) { + static final YBand EMPTY = new YBand(false, 0, 0); + + static YBand of(List ores) { + if (ores.isEmpty()) { + return EMPTY; + } + double min = Double.POSITIVE_INFINITY; + double max = Double.NEGATIVE_INFINITY; + for (ResolvedOre ore : ores) { + min = Math.min(min, ore.minY()); + max = Math.max(max, ore.maxY()); + } + return new YBand(true, min, max); + } + + boolean contains(int y) { + return hasOres && y >= min && y <= max; + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java b/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java index 7926c0357..3ebec481d 100644 --- a/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java +++ b/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java @@ -19,14 +19,15 @@ package art.arcane.iris.engine.actuator; import art.arcane.iris.builtin.IrisStages; +import art.arcane.iris.builtin.terrain.HideOresSettings; +import art.arcane.iris.builtin.terrain.OreSettings; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.modules.IrisChunk; import art.arcane.iris.core.modules.IrisPackWorld; import art.arcane.iris.engine.IrisComplex; import art.arcane.iris.engine.UpperDimensionContext; +import art.arcane.iris.engine.actuator.ResolvedOres.YBand; import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGenerator; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGeneratorBounds; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.world.region.IrisRegion; @@ -63,6 +64,8 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { @Override public void register(FeatureRegistry registry) { + registry.registerSettings(OreSettings.class); + registry.registerSettings(HideOresSettings.class); registry.registerLifecycle(this); } @@ -86,10 +89,16 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { private static final PlatformBlockState BEDROCK = B.getState("BEDROCK"); private final Engine engine; + private final TerrainOres ores; private final RNG rng; TerrainShaper(Engine engine) { + this(engine, TerrainOres.of(engine)); + } + + TerrainShaper(Engine engine, TerrainOres ores) { this.engine = engine; + this.ores = ores; this.rng = new RNG(engine.getSeedManager().getTerrain()); } @@ -115,7 +124,7 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { int fluidHeight = dimension.getFluidHeight(); int clampedFluidHeight = Math.min(chunkHeight, fluidHeight); boolean bedrockEnabled = dimension.isBedrock(); - boolean hideOres = dimension.isHideOresForHiddenOre(); + boolean hideOres = HiddenOres.in(dimension); ChunkedDataCache biomeCache = context.getBiome(); ChunkedDataCache regionCache = context.getRegion(); ChunkedDataCache fluidCache = context.getFluid(); @@ -123,11 +132,10 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { int realX = xf + x; UpperDimensionContext upperContext = engine.getUpperContext(); // Dimension-level ore lookups are chunk-invariant; resolving them per column paid - // four accessor chains times 256 per chunk for constants. - KList dimensionSurfaceOres = hideOres ? null : dimension.getSurfaceOreGenerators(); - KList dimensionUndergroundOres = hideOres ? null : dimension.getUndergroundOreGenerators(); - IrisOreGeneratorBounds dimensionSurfaceOreBounds = hideOres ? IrisOreGeneratorBounds.EMPTY : dimension.getSurfaceOreGeneratorBounds(); - IrisOreGeneratorBounds dimensionUndergroundOreBounds = hideOres ? IrisOreGeneratorBounds.EMPTY : dimension.getUndergroundOreGeneratorBounds(); + // the settings lookup times 256 per chunk for a constant. + ResolvedOres dimensionOres = hideOres ? ResolvedOres.NONE : ores.of(dimension); + YBand dimensionSurfaceBand = dimensionOres.surfaceBand(); + YBand dimensionUndergroundBand = dimensionOres.undergroundBand(); for (int zf = 0; zf < chunkDepth; zf++) { int realZ = zf + z; @@ -143,16 +151,14 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { PlatformBlockState fluid = fluidCache.get(xf, zf); PlatformBlockState rock = rockCache.get(xf, zf); PlatformBlockState mappedSurfaceBlock = complex.getImageMapRuntime().sampleSurfaceBlock(realX, realZ); - KList biomeSurfaceOres = hideOres ? null : biome.getSurfaceOreGenerators(); - KList regionSurfaceOres = hideOres ? null : region.getSurfaceOreGenerators(); - KList biomeUndergroundOres = hideOres ? null : biome.getUndergroundOreGenerators(); - KList regionUndergroundOres = hideOres ? null : region.getUndergroundOreGenerators(); - IrisOreGeneratorBounds biomeSurfaceOreBounds = hideOres ? IrisOreGeneratorBounds.EMPTY : biome.getSurfaceOreGeneratorBounds(); - IrisOreGeneratorBounds regionSurfaceOreBounds = hideOres ? IrisOreGeneratorBounds.EMPTY : region.getSurfaceOreGeneratorBounds(); - IrisOreGeneratorBounds biomeUndergroundOreBounds = hideOres ? IrisOreGeneratorBounds.EMPTY : biome.getUndergroundOreGeneratorBounds(); - IrisOreGeneratorBounds regionUndergroundOreBounds = hideOres ? IrisOreGeneratorBounds.EMPTY : region.getUndergroundOreGeneratorBounds(); - boolean hasSurfaceOres = biomeSurfaceOreBounds.hasOres() || regionSurfaceOreBounds.hasOres() || dimensionSurfaceOreBounds.hasOres(); - boolean hasUndergroundOres = biomeUndergroundOreBounds.hasOres() || regionUndergroundOreBounds.hasOres() || dimensionUndergroundOreBounds.hasOres(); + ResolvedOres biomeOres = hideOres ? ResolvedOres.NONE : ores.of(biome); + ResolvedOres regionOres = hideOres ? ResolvedOres.NONE : ores.of(region); + YBand biomeSurfaceBand = biomeOres.surfaceBand(); + YBand regionSurfaceBand = regionOres.surfaceBand(); + YBand biomeUndergroundBand = biomeOres.undergroundBand(); + YBand regionUndergroundBand = regionOres.undergroundBand(); + boolean hasSurfaceOres = biomeSurfaceBand.hasOres() || regionSurfaceBand.hasOres() || dimensionSurfaceBand.hasOres(); + boolean hasUndergroundOres = biomeUndergroundBand.hasOres() || regionUndergroundBand.hasOres() || dimensionUndergroundBand.hasOres(); KList blocks = null; KList fblocks = null; @@ -164,14 +170,14 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { PlatformBlockState ore = null; if (hasSurfaceOres) { - if (biomeSurfaceOreBounds.contains(i)) { - ore = generateOres(biomeSurfaceOres, realX, i, realZ, localRng, data); + if (biomeSurfaceBand.contains(i)) { + ore = biomeOres.generateSurface(realX, i, realZ); } - if (ore == null && regionSurfaceOreBounds.contains(i)) { - ore = generateOres(regionSurfaceOres, realX, i, realZ, localRng, data); + if (ore == null && regionSurfaceBand.contains(i)) { + ore = regionOres.generateSurface(realX, i, realZ); } - if (ore == null && dimensionSurfaceOreBounds.contains(i)) { - ore = generateOres(dimensionSurfaceOres, realX, i, realZ, localRng, data); + if (ore == null && dimensionSurfaceBand.contains(i)) { + ore = dimensionOres.generateSurface(realX, i, realZ); } } if (ore != null) { @@ -209,14 +215,14 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { } if (hasUndergroundOres) { - if (biomeUndergroundOreBounds.contains(i)) { - ore = generateOres(biomeUndergroundOres, realX, i, realZ, localRng, data); + if (biomeUndergroundBand.contains(i)) { + ore = biomeOres.generateUnderground(realX, i, realZ); } - if (ore == null && regionUndergroundOreBounds.contains(i)) { - ore = generateOres(regionUndergroundOres, realX, i, realZ, localRng, data); + if (ore == null && regionUndergroundBand.contains(i)) { + ore = regionOres.generateUnderground(realX, i, realZ); } - if (ore == null && dimensionUndergroundOreBounds.contains(i)) { - ore = generateOres(dimensionUndergroundOres, realX, i, realZ, localRng, data); + if (ore == null && dimensionUndergroundBand.contains(i)) { + ore = dimensionOres.generateUnderground(realX, i, realZ); } } @@ -264,22 +270,5 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { } } } - - private PlatformBlockState generateOres(KList oreGenerators, int x, int y, int z, RNG rng, IrisData data) { - if (oreGenerators == null || oreGenerators.isEmpty()) { - return null; - } - - int oreCount = oreGenerators.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = oreGenerators.get(oreIndex); - PlatformBlockState ore = oreGenerator.generate(x, y, z, rng, data); - if (ore != null) { - return ore; - } - } - - return null; - } } } diff --git a/src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java b/src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java new file mode 100644 index 000000000..8dc6a9b0e --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java @@ -0,0 +1,53 @@ +/* + * 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.actuator; + +import art.arcane.iris.builtin.terrain.OreSettings; +import art.arcane.iris.core.loader.IrisRegistrant; +import art.arcane.iris.engine.framework.Engine; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * What the terrain module keeps for one world: the ore generators of its dimension, regions and biomes made ready + * ({@link ResolvedOres}), built from their {@link OreSettings} when first asked for or ahead of generation by {@link OreWarmUp}. + */ +final class TerrainOres { + private final Engine engine; + private final Map resolved = new ConcurrentHashMap<>(); + + TerrainOres(Engine engine) { + this.engine = engine; + } + + /** The ores of the world {@code engine} generates now. */ + static TerrainOres of(Engine engine) { + return engine.getGeneration().state(TerrainOres.class, TerrainOres::new); + } + + /** The ore generators {@code owner}, a dimension, region or biome, declares; {@link ResolvedOres#NONE} when it declares none. */ + ResolvedOres of(IrisRegistrant owner) { + OreSettings settings = owner.getModuleSettings().find(OreSettings.class).orElse(null); + if (settings == null) { + return ResolvedOres.NONE; + } + return resolved.computeIfAbsent(settings, declared -> ResolvedOres.of(declared, engine)); + } +} 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 f2889714b..668755e37 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/DepositModule.java +++ b/src/main/java/art/arcane/iris/engine/modifier/DepositModule.java @@ -21,7 +21,11 @@ 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.builtin.deposit.DepositVariantSettings; +import art.arcane.iris.builtin.deposit.OreFrequencySettings; +import art.arcane.iris.builtin.deposit.OreSizeSettings; import art.arcane.iris.core.modules.IrisChunk; +import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; import com.volmit.config.FeatureSettings; @@ -48,6 +52,13 @@ public final class DepositModule implements IrisModule { return ModuleInfo.of("iris:deposit", "Deposits", VERSION); } + @Override + public void register(FeatureRegistry registry) { + registry.registerSettings(DepositVariantSettings.class); + registry.registerSettings(OreFrequencySettings.class); + registry.registerSettings(OreSizeSettings.class); + } + @Override public void install(StageGraph graph) { graph.define(IrisStages.Deposit.ORES) 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 ff3844442..2a8906b69 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java +++ b/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java @@ -21,10 +21,14 @@ 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.builtin.deposit.DepositVariant; +import art.arcane.iris.builtin.deposit.DepositVariantSettings; +import art.arcane.iris.builtin.deposit.OreFrequencySettings; +import art.arcane.iris.builtin.deposit.OreSizeSettings; +import art.arcane.iris.core.loader.IrisRegistrant; 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.IrisDepositVariant; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver; import art.arcane.iris.engine.object.prefab.IrisObject; @@ -52,7 +56,10 @@ import java.util.concurrent.ConcurrentHashMap; */ public class DepositPlacer extends EngineAssignedComponent { private final RNG rng; + private static final double UNCHANGED_ORE_MULTIPLIER = 1D; + private final Map resolved = new ConcurrentHashMap<>(); + private final Map variants = new ConcurrentHashMap<>(); public DepositPlacer(Engine engine) { super(engine, "Deposit"); @@ -150,13 +157,13 @@ public class DepositPlacer extends EngineAssignedComponent { if (oreDeposit) { if (depositBiome != null) { - double frequencyMultiplier = depositBiome.getOreDepositFrequencyMultiplier(); + double frequencyMultiplier = oreFrequencyMultiplier(depositBiome); if (frequencyMultiplier < 1D && !passesOreFrequency(frequencyMultiplier, rng.d())) { continue; } - double sizeMultiplier = depositBiome.getOreDepositSizeMultiplier(); + double sizeMultiplier = oreSizeMultiplier(depositBiome); if (sizeMultiplier != 1D) { IrisObject scaledClump = deposit.clump(rng, sizeMultiplier); int scaledDimension = scaledClump.getW(); @@ -317,7 +324,7 @@ public class DepositPlacer extends EngineAssignedComponent { IrisBiome biome = getEngine().getCaveBiome(worldX, localY, worldZ, carvingState); if (biome != null) { - PlatformBlockState match = matchDepositVariant(biome.getDepositVariants(), ore, worldY); + PlatformBlockState match = matchDepositVariant(biome, ore, worldY); if (match != null) { return match; } @@ -325,14 +332,14 @@ public class DepositPlacer extends EngineAssignedComponent { IrisRegion region = context.getRegion().get(nx, nz); if (region != null) { - PlatformBlockState match = matchDepositVariant(region.getDepositVariants(), ore, worldY); + PlatformBlockState match = matchDepositVariant(region, ore, worldY); if (match != null) { return match; } } if (dimension != null) { - PlatformBlockState match = matchDepositVariant(dimension.getDepositVariants(), ore, worldY); + PlatformBlockState match = matchDepositVariant(dimension, ore, worldY); if (match != null) { return match; } @@ -341,17 +348,14 @@ public class DepositPlacer extends EngineAssignedComponent { return null; } - private PlatformBlockState matchDepositVariant(java.util.List variants, PlatformBlockState ore, int y) { - if (variants == null || variants.isEmpty()) { - return null; - } - - for (IrisDepositVariant variant : variants) { - if (y < variant.getMinHeight() || y > variant.getMaxHeight()) { + private PlatformBlockState matchDepositVariant(IrisRegistrant owner, PlatformBlockState ore, int y) { + for (DepositVariant declared : variantsOf(owner)) { + ResolvedDepositVariant variant = variants.computeIfAbsent(declared, ResolvedDepositVariant::new); + if (!variant.appliesAt(y)) { continue; } - PlatformBlockState swapped = variant.remapOrNull(ore, getData()); + PlatformBlockState swapped = variant.remapOrNull(ore); if (swapped != null) { return swapped; } @@ -359,4 +363,16 @@ public class DepositPlacer extends EngineAssignedComponent { return null; } + + private static List variantsOf(IrisRegistrant owner) { + return owner.getModuleSettings().find(DepositVariantSettings.class).map(DepositVariantSettings::variants).orElse(List.of()); + } + + private static double oreFrequencyMultiplier(IrisBiome biome) { + return biome.getModuleSettings().find(OreFrequencySettings.class).map(OreFrequencySettings::multiplier).orElse(UNCHANGED_ORE_MULTIPLIER); + } + + private static double oreSizeMultiplier(IrisBiome biome) { + return biome.getModuleSettings().find(OreSizeSettings.class).map(OreSizeSettings::multiplier).orElse(UNCHANGED_ORE_MULTIPLIER); + } } diff --git a/src/main/java/art/arcane/iris/engine/modifier/PerfectionModule.java b/src/main/java/art/arcane/iris/engine/modifier/PerfectionModule.java index 6e45f193f..cc98dc82c 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/PerfectionModule.java +++ b/src/main/java/art/arcane/iris/engine/modifier/PerfectionModule.java @@ -20,6 +20,7 @@ package art.arcane.iris.engine.modifier; import art.arcane.iris.builtin.IrisStages; import art.arcane.iris.core.modules.IrisChunk; +import art.arcane.iris.engine.actuator.HiddenOres; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; import art.arcane.iris.engine.object.world.dimension.IrisDimension; @@ -68,7 +69,7 @@ public final class PerfectionModule implements IrisModule { IrisDimension dimension = engine.getDimension(); PrecisionStopwatch stopwatch = PrecisionStopwatch.start(); Hunk blocks = chunk.blocks(); - if (dimension.isHideOresForHiddenOre()) { + if (HiddenOres.in(dimension)) { hideOres(blocks); } boolean removed; diff --git a/src/main/java/art/arcane/iris/engine/modifier/ResolvedDepositVariant.java b/src/main/java/art/arcane/iris/engine/modifier/ResolvedDepositVariant.java new file mode 100644 index 000000000..b1a6dce34 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/modifier/ResolvedDepositVariant.java @@ -0,0 +1,66 @@ +/* + * 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.DepositVariant; +import art.arcane.iris.engine.data.cache.AtomicCache; +import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; + +import java.util.HashMap; +import java.util.Map; + +/** + * One {@link DepositVariant} made ready: its source and replacement block ids resolved to the platform's blocks, built once on + * first use. A rule whose source or replacement the platform does not know remaps nothing. + */ +final class ResolvedDepositVariant { + private final DepositVariant settings; + private final AtomicCache> remapped = new AtomicCache<>(); + + ResolvedDepositVariant(DepositVariant settings) { + this.settings = settings; + } + + boolean appliesAt(int worldY) { + return worldY >= settings.minHeight() && worldY <= settings.maxHeight(); + } + + /** The block {@code ore} is rewritten to, or null when the rule does not remap its material. */ + PlatformBlockState remapOrNull(PlatformBlockState ore) { + if (ore == null || settings.remap().isEmpty()) { + return null; + } + return remapped.aquire(this::resolveRemap).get(IrisProceduralBlocks.materialKey(ore)); + } + + private Map resolveRemap() { + Map resolved = new HashMap<>(); + for (Map.Entry entry : settings.remap().entrySet()) { + PlatformBlockState source = B.getStateOrNull(entry.getKey(), false); + PlatformBlockState target = B.getStateOrNull(entry.getValue(), true); + if (source == null || target == null) { + continue; + } + resolved.put(IrisProceduralBlocks.materialKey(source), target); + } + return resolved; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisBiomeOres.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisBiomeOres.java deleted file mode 100644 index 1473d3b1b..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisBiomeOres.java +++ /dev/null @@ -1,130 +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.world.biome.IrisBiome; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.data.cache.AtomicCache; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.RNG; - -/** - * Ore generation for {@link IrisBiome}. IrisBiome is Gson deserialized from pack JSON, so its - * fields stay put and only the behavior lives here. Note that {@code IrisBiome.setOres(KList)} - * stays on IrisBiome: it is a hand written Lombok setter override that resets these caches. - */ -public final class IrisBiomeOres { - private IrisBiomeOres() { - } - - public static PlatformBlockState generateOres(IrisBiome biome, int x, int y, int z, RNG rng, IrisData data, boolean surface) { - KList localOres = surface ? getSurfaceOres(biome) : getUndergroundOres(biome); - return generateOres(localOres, x, y, z, rng, data); - } - - public static PlatformBlockState generateSurfaceOres(IrisBiome biome, int x, int y, int z, RNG rng, IrisData data) { - return generateOres(getSurfaceOres(biome), x, y, z, rng, data); - } - - public static PlatformBlockState generateUndergroundOres(IrisBiome biome, int x, int y, int z, RNG rng, IrisData data) { - return generateOres(getUndergroundOres(biome), x, y, z, rng, data); - } - - public static boolean hasSurfaceOres(IrisBiome biome) { - return !getSurfaceOres(biome).isEmpty(); - } - - public static boolean hasUndergroundOres(IrisBiome biome) { - return !getUndergroundOres(biome).isEmpty(); - } - - public static KList getSurfaceOreGenerators(IrisBiome biome) { - return getOres(biome, true); - } - - public static KList getUndergroundOreGenerators(IrisBiome biome) { - return getOres(biome, false); - } - - public static IrisOreGeneratorBounds getSurfaceOreGeneratorBounds(IrisBiome biome) { - // getIfPresent fast path: aquire allocates a capturing lambda even on a hit, and this - // runs per column on the terrain hot path. - IrisOreGeneratorBounds cached = biome.getSurfaceOreBoundsCache().getIfPresent(); - if (cached != null) { - return cached; - } - return biome.getSurfaceOreBoundsCache().aquire(() -> IrisOreGeneratorBounds.of(getSurfaceOres(biome))); - } - - public static IrisOreGeneratorBounds getUndergroundOreGeneratorBounds(IrisBiome biome) { - IrisOreGeneratorBounds cached = biome.getUndergroundOreBoundsCache().getIfPresent(); - if (cached != null) { - return cached; - } - return biome.getUndergroundOreBoundsCache().aquire(() -> IrisOreGeneratorBounds.of(getUndergroundOres(biome))); - } - - private static KList getSurfaceOres(IrisBiome biome) { - return getOres(biome, true); - } - - private static KList getUndergroundOres(IrisBiome biome) { - return getOres(biome, false); - } - - private static KList getOres(IrisBiome biome, boolean surface) { - AtomicCache> oreCache = surface ? biome.getSurfaceOreCache() : biome.getUndergroundOreCache(); - KList cached = oreCache.getIfPresent(); - - if (cached != null) { - return cached; - } - - return oreCache.aquire(() -> { - KList filtered = new KList<>(); - KList localOres = biome.getOres(); - int oreCount = localOres.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = localOres.get(oreIndex); - if (oreGenerator.isGenerateSurface() == surface) { - filtered.add(oreGenerator); - } - } - - return filtered; - }); - } - - private static PlatformBlockState generateOres(KList localOres, int x, int y, int z, RNG rng, IrisData data) { - if (localOres.isEmpty()) { - return null; - } - - int oreCount = localOres.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = localOres.get(oreIndex); - PlatformBlockState ore = oreGenerator.generate(x, y, z, rng, data); - if (ore != null) { - return ore; - } - } - return null; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositVariant.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositVariant.java deleted file mode 100644 index 966a751d1..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisDepositVariant.java +++ /dev/null @@ -1,87 +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.procedural.IrisProceduralBlocks; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.data.cache.AtomicCache; -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.volmlib.util.collection.KMap; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import lombok.experimental.Accessors; - -@Snippet("deposit-variant") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Remaps ore block ids to alternate block ids within a vertical band. Ores declared at dimension, region, and biome scope can be rewritten at placement time (for example, iron_ore -> deepslate_iron_ore inside a deep carving band, or yourmod:iron -> yourmod:moon_iron inside a lunar biome).") -@Data -public class IrisDepositVariant { - private final transient AtomicCache> resolved = new AtomicCache<>(); - - @Required - @MinNumber(-2048) - @MaxNumber(8192) - @Desc("Inclusive minimum world Y this variant applies at.") - private int minHeight = 0; - - @Required - @MinNumber(-2048) - @MaxNumber(8192) - @Desc("Inclusive maximum world Y this variant applies at.") - private int maxHeight = 0; - - @Required - @Desc("Source block id (for example `minecraft:iron_ore`) -> replacement block id (for example `minecraft:deepslate_iron_ore`). Any block id the data loader resolves is accepted, including external/mod blocks. Source match is by material only, so block properties on the source key are ignored.") - private KMap remap = new KMap<>(); - - public PlatformBlockState remapOrNull(PlatformBlockState ore, IrisData rdata) { - if (ore == null || remap == null || remap.isEmpty()) { - return null; - } - - KMap map = resolved.aquire(() -> buildResolved(rdata)); - return map.get(IrisProceduralBlocks.materialKey(ore)); - } - - private KMap buildResolved(IrisData rdata) { - KMap out = new KMap<>(); - - for (java.util.Map.Entry entry : remap.entrySet()) { - PlatformBlockState source = B.getStateOrNull(entry.getKey(), false); - PlatformBlockState target = B.getStateOrNull(entry.getValue(), true); - - if (source == null || target == null) { - continue; - } - - out.put(IrisProceduralBlocks.materialKey(source), target); - } - - return out; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGenerator.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGenerator.java deleted file mode 100644 index ed5e9502e..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGenerator.java +++ /dev/null @@ -1,81 +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.IrisMaterialPalette; -import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; -import art.arcane.iris.engine.object.noise.NoiseStyle; -import art.arcane.iris.engine.object.value.IrisRange; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.data.cache.AtomicCache; -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.volmlib.util.math.RNG; -import art.arcane.iris.util.project.noise.CNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import art.arcane.iris.spi.PlatformBlockState; -import lombok.experimental.Accessors; - -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Scatters single ore blocks through terrain by sampling a noise field at every block in a vertical band. Defined on dimensions, regions, or biomes; the most specific level wins.") -@Data -public class IrisOreGenerator { - @Desc("The ore blocks to place. An empty palette generates nothing, so this must be set for the generator to have any effect.") - private IrisMaterialPalette palette = new IrisMaterialPalette().qclear(); - @Desc("The noise style sampled per block to decide where ore appears. STATIC gives independent random speckle; smoother styles give veiny clusters.") - private IrisGeneratorStyle chanceStyle = new IrisGeneratorStyle(NoiseStyle.STATIC); - @Desc("When true this generator also replaces surface-layer blocks (it runs before layers and fluid); when false it only replaces underground rock.") - private boolean generateSurface = false; - @MinNumber(0) - @MaxNumber(1) - @Desc("Noise cutoff: a block becomes ore when the sampled noise is at or below this value, so higher means more ore. 0 disables, 1 replaces everything in range.") - private double threshold = 0.5; - @Desc("Vertical band (min, max) this ore can generate in, in engine-local Y where 0 is the bottom of the dimension, not world Y.") - private IrisRange range = new IrisRange(30, 80); - - private transient AtomicCache chanceCache = new AtomicCache<>(); - - public void warm(RNG rng, IrisData data) { - chanceCache.aquire(() -> chanceStyle.create(rng, data)); - palette.getLayerGenerator(rng, data); - } - - public PlatformBlockState generate(int x, int y, int z, RNG rng, IrisData data) { - if (!range.contains(y)) { - return null; - } - - if (palette.getPalette().isEmpty()) { - return null; - } - - CNG chance = chanceCache.aquire(() -> chanceStyle.create(rng, data)); - - if (chance.noise(x, y, z) > threshold) { - return null; - } - - return palette.get(rng, x, y, z, data); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGeneratorBounds.java b/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGeneratorBounds.java deleted file mode 100644 index aea87f2c0..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/deposit/IrisOreGeneratorBounds.java +++ /dev/null @@ -1,44 +0,0 @@ -package art.arcane.iris.engine.object.terrain.deposit; - -import art.arcane.iris.engine.object.value.IrisRange; -import art.arcane.volmlib.util.collection.KList; - -public final class IrisOreGeneratorBounds { - public static final IrisOreGeneratorBounds EMPTY = new IrisOreGeneratorBounds(false, 0D, 0D); - - private final boolean hasOres; - private final double min; - private final double max; - - private IrisOreGeneratorBounds(boolean hasOres, double min, double max) { - this.hasOres = hasOres; - this.min = min; - this.max = max; - } - - public static IrisOreGeneratorBounds of(KList ores) { - if (ores == null || ores.isEmpty()) { - return EMPTY; - } - - double min = Double.POSITIVE_INFINITY; - double max = Double.NEGATIVE_INFINITY; - int oreCount = ores.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = ores.get(oreIndex); - IrisRange range = oreGenerator.getRange(); - min = Math.min(min, range.getMin()); - max = Math.max(max, range.getMax()); - } - - return new IrisOreGeneratorBounds(true, min, max); - } - - public boolean hasOres() { - return hasOres; - } - - public boolean contains(int y) { - return hasOres && y >= min && y <= max; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java index 2be388ff5..d6da53ad2 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java +++ b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java @@ -31,10 +31,6 @@ import art.arcane.iris.engine.object.procedural.IrisProceduralObjects; import art.arcane.iris.engine.object.structure.IrisStructurePlacement; import art.arcane.iris.engine.object.terrain.IrisBiomeLayerGenerator; import art.arcane.iris.engine.object.terrain.IrisBiomePaletteLayer; -import art.arcane.iris.engine.object.terrain.deposit.IrisBiomeOres; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositVariant; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGenerator; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGeneratorBounds; import art.arcane.iris.engine.object.value.IRare; import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom; import art.arcane.iris.engine.object.world.dimension.IrisDimension; @@ -78,7 +74,7 @@ import java.util.Objects; * Represents a biome in a pack. This type is Gson deserialized straight out of user pack JSON, so * the field block and the transient {@link AtomicCache} block below are load bearing and must not * move. Behavior lives in the same-package companions: - * {@link IrisBiomeLayerGenerator}, {@link IrisBiomeDerivatives}, {@link IrisBiomeOres}, + * {@link IrisBiomeLayerGenerator}, {@link IrisBiomeDerivatives}, * {@link IrisBiomeColorRenderer} and {@link IrisBiomeGenLinks}. */ @Accessors(chain = true) @@ -112,10 +108,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { private final transient AtomicCache> realChildren = new AtomicCache<>(); private final transient AtomicCache> layerHeightGenerators = new AtomicCache<>(); private final transient AtomicCache> layerSeaHeightGenerators = new AtomicCache<>(); - private final transient AtomicCache> surfaceOreCache = new AtomicCache<>(); - private final transient AtomicCache> undergroundOreCache = new AtomicCache<>(); - private final transient AtomicCache surfaceOreBoundsCache = new AtomicCache<>(); - private final transient AtomicCache undergroundOreBoundsCache = new AtomicCache<>(); private final transient AtomicCache derivativeResolved = new AtomicCache<>(); private final transient AtomicCache vanillaDerivativeResolved = new AtomicCache<>(); private final transient AtomicCache> biomeScatterResolved = new AtomicCache<>(); @@ -217,44 +209,10 @@ public class IrisBiome extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = IrisBiomeGeneratorLink.class) @Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.") private KList generators = new KList().qadd(new IrisBiomeGeneratorLink()); - @MinNumber(0) - @MaxNumber(1) - @Desc("Multiplier applied to the frequency of every ore deposit whose center is inside this biome. A value of 0.4 keeps 40% of ore veins while leaving non-ore deposits unchanged.") - private double oreDepositFrequencyMultiplier = 1D; - @MinNumber(0.01) - @MaxNumber(16) - @Desc("Multiplier applied to the block count of every ore deposit whose center is inside this biome. Non-ore deposits are unchanged.") - private double oreDepositSizeMultiplier = 1D; - @ArrayType(min = 1, type = IrisDepositVariant.class) - @Desc("Deposit ore remap rules scoped to this biome. Each entry declares a vertical band and a source->replacement block id map. Applied before regional and dimension rules; first matching biome rule wins.") - private KList depositVariants = new KList<>(); private transient volatile InferredType inferredType; @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) private final transient EnumMap inferredVariants = new EnumMap<>(InferredType.class); - @Desc("Collection of ores to be generated") - @ArrayType(type = IrisOreGenerator.class, min = 1) - private KList ores = new KList<>(); - - public PlatformBlockState generateOres(int x, int y, int z, RNG rng, IrisData data, boolean surface) { - return IrisBiomeOres.generateOres(this, x, y, z, rng, data, surface); - } - - public PlatformBlockState generateSurfaceOres(int x, int y, int z, RNG rng, IrisData data) { - return IrisBiomeOres.generateSurfaceOres(this, x, y, z, rng, data); - } - - public PlatformBlockState generateUndergroundOres(int x, int y, int z, RNG rng, IrisData data) { - return IrisBiomeOres.generateUndergroundOres(this, x, y, z, rng, data); - } - - public boolean hasSurfaceOres() { - return IrisBiomeOres.hasSurfaceOres(this); - } - - public boolean hasUndergroundOres() { - return IrisBiomeOres.hasUndergroundOres(this); - } public synchronized IrisBiome setInferredType(InferredType inferredType) { this.inferredType = inferredType; @@ -292,39 +250,12 @@ public class IrisBiome extends IrisRegistrant implements IRare { variant.setLoader(data); variant.setLoadKey(getLoadKey()); variant.setLoadFile(getLoadFile()); + variant.setModuleSettings(getModuleSettings()); variant.inferredType = type; inferredVariants.put(type, variant); return variant; } - /** - * Hand written override of the Lombok setter. It must stay here because it invalidates the ore - * caches that {@link IrisBiomeOres} reads. - */ - public void setOres(KList ores) { - this.ores = ores == null ? new KList<>() : ores; - surfaceOreCache.reset(); - undergroundOreCache.reset(); - surfaceOreBoundsCache.reset(); - undergroundOreBoundsCache.reset(); - } - - public KList getSurfaceOreGenerators() { - return IrisBiomeOres.getSurfaceOreGenerators(this); - } - - public KList getUndergroundOreGenerators() { - return IrisBiomeOres.getUndergroundOreGenerators(this); - } - - public IrisOreGeneratorBounds getSurfaceOreGeneratorBounds() { - return IrisBiomeOres.getSurfaceOreGeneratorBounds(this); - } - - public IrisOreGeneratorBounds getUndergroundOreGeneratorBounds() { - return IrisBiomeOres.getUndergroundOreGeneratorBounds(this); - } - public Biome getDerivative() { Biome cached = derivativeResolved.getIfPresent(); diff --git a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java index 8f37e4768..b59850df2 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java +++ b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java @@ -35,9 +35,6 @@ import art.arcane.iris.engine.object.procedural.tree.IrisTreeSettings; import art.arcane.iris.engine.object.runtime.StudioMode; import art.arcane.iris.engine.object.structure.IrisStructurePlacement; import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingEntry; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositVariant; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGenerator; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGeneratorBounds; import art.arcane.iris.engine.object.value.IrisRange; import art.arcane.iris.engine.object.world.IrisEnvironment; import art.arcane.iris.engine.object.world.IrisWorldBoundary; @@ -114,10 +111,6 @@ public class IrisDimension extends IrisRegistrant { private final transient AtomicCache rad = new AtomicCache<>(); private final transient AtomicCache featuresUsed = new AtomicCache<>(); private final transient AtomicCache> carvingEntryIndex = new AtomicCache<>(); - private final transient AtomicCache> surfaceOreCache = new AtomicCache<>(); - private final transient AtomicCache> undergroundOreCache = new AtomicCache<>(); - private final transient AtomicCache surfaceOreBoundsCache = new AtomicCache<>(); - private final transient AtomicCache undergroundOreBoundsCache = new AtomicCache<>(); @MinNumber(2) @Required @Desc("The human readable name of this dimension") @@ -176,8 +169,6 @@ public class IrisDimension extends IrisRegistrant { private boolean debugSmartBore = false; @Desc("Generate decorations or not") private boolean decorate = true; - @Desc("When true, every ore block the generator would place (terrain ores, deposits, ores inside objects) is replaced with its base material such as stone, deepslate or netherrack, so drop-control plugins like HiddenOre can manage ore rewards themselves") - private boolean hideOresForHiddenOre = false; @Desc("Use post processing or not") private boolean postProcessing = true; @Desc("Add slabs in post processing") @@ -275,9 +266,6 @@ public class IrisDimension extends IrisRegistrant { private boolean useMantle = true; @Desc("Prevent Leaf decay as if placed in creative mode") private boolean preventLeafDecay = false; - @ArrayType(min = 1, type = IrisDepositVariant.class) - @Desc("Dimension-wide deposit ore remap rules. Each entry declares a vertical band and a source->replacement block id map. Applied after biome and region rules; first matching dimension rule wins.") - private KList depositVariants = new KList<>(); @ArrayType(min = 1, type = IrisShapedGeneratorStyle.class) @Desc("Overlay additional noise on top of the interoplated terrain.") private KList overlayNoise = new KList<>(); @@ -285,9 +273,6 @@ public class IrisDimension extends IrisRegistrant { private IrisMaterialPalette rockPalette = new IrisMaterialPalette().qclear().qadd("stone"); @Desc("The dimension fluid block palette used for ocean columns and cave aquifers.") private IrisMaterialPalette fluidPalette = new IrisMaterialPalette().qclear().qadd("water"); - @Desc("Collection of ores to be generated") - @ArrayType(type = IrisOreGenerator.class, min = 1) - private KList ores = new KList<>(); @Desc("Dimension-wide Iris structure placements, independent of biome/region placements") @ArrayType(type = IrisStructurePlacement.class, min = 1) private KList structures = new KList<>(); @@ -343,92 +328,6 @@ public class IrisDimension extends IrisRegistrant { carvingEntryIndex.reset(); } - public PlatformBlockState generateOres(int x, int y, int z, RNG rng, IrisData data, boolean surface) { - KList localOres = surface ? getSurfaceOres() : getUndergroundOres(); - return generateOres(localOres, x, y, z, rng, data); - } - - public PlatformBlockState generateSurfaceOres(int x, int y, int z, RNG rng, IrisData data) { - return generateOres(getSurfaceOres(), x, y, z, rng, data); - } - - public PlatformBlockState generateUndergroundOres(int x, int y, int z, RNG rng, IrisData data) { - return generateOres(getUndergroundOres(), x, y, z, rng, data); - } - - public boolean hasSurfaceOres() { - return !getSurfaceOres().isEmpty(); - } - - public boolean hasUndergroundOres() { - return !getUndergroundOres().isEmpty(); - } - - private PlatformBlockState generateOres(KList localOres, int x, int y, int z, RNG rng, IrisData data) { - if (localOres.isEmpty()) { - return null; - } - - int oreCount = localOres.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = localOres.get(oreIndex); - PlatformBlockState ore = oreGenerator.generate(x, y, z, rng, data); - if (ore != null) { - return ore; - } - } - return null; - } - - public void setOres(KList ores) { - this.ores = ores == null ? new KList<>() : ores; - surfaceOreCache.reset(); - undergroundOreCache.reset(); - surfaceOreBoundsCache.reset(); - undergroundOreBoundsCache.reset(); - } - - public KList getSurfaceOreGenerators() { - return getOres(true); - } - - public KList getUndergroundOreGenerators() { - return getOres(false); - } - - public IrisOreGeneratorBounds getSurfaceOreGeneratorBounds() { - return surfaceOreBoundsCache.aquire(() -> IrisOreGeneratorBounds.of(getSurfaceOres())); - } - - public IrisOreGeneratorBounds getUndergroundOreGeneratorBounds() { - return undergroundOreBoundsCache.aquire(() -> IrisOreGeneratorBounds.of(getUndergroundOres())); - } - - private KList getSurfaceOres() { - return getOres(true); - } - - private KList getUndergroundOres() { - return getOres(false); - } - - private KList getOres(boolean surface) { - AtomicCache> oreCache = surface ? surfaceOreCache : undergroundOreCache; - return oreCache.aquire(() -> { - KList filtered = new KList<>(); - KList localOres = ores; - int oreCount = localOres.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = localOres.get(oreIndex); - if (oreGenerator.isGenerateSurface() == surface) { - filtered.add(oreGenerator); - } - } - - return filtered; - }); - } - public int getFluidHeight() { return fluidHeight - (int) dimensionHeight.getMin(); } diff --git a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java index 8c03c3310..60b0583ce 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java +++ b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java @@ -26,9 +26,6 @@ import art.arcane.iris.engine.object.loot.IrisLootReference; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.procedural.IrisProceduralObjects; import art.arcane.iris.engine.object.structure.IrisStructurePlacement; -import art.arcane.iris.engine.object.terrain.deposit.IrisDepositVariant; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGenerator; -import art.arcane.iris.engine.object.terrain.deposit.IrisOreGeneratorBounds; import art.arcane.iris.engine.object.value.IRare; import art.arcane.iris.engine.object.world.biome.InferredType; import art.arcane.iris.engine.object.world.biome.IrisBiome; @@ -77,10 +74,6 @@ public class IrisRegion extends IrisRegistrant implements IRare { private final transient AtomicCache> realShoreBiomes = new AtomicCache<>(); private final transient AtomicCache> realCaveBiomes = new AtomicCache<>(); private final transient AtomicCache cacheColor = new AtomicCache<>(); - private final transient AtomicCache> surfaceOreCache = new AtomicCache<>(); - private final transient AtomicCache> undergroundOreCache = new AtomicCache<>(); - private final transient AtomicCache surfaceOreBoundsCache = new AtomicCache<>(); - private final transient AtomicCache undergroundOreBoundsCache = new AtomicCache<>(); @MinNumber(2) @Required @Desc("The name of the region") @@ -149,100 +142,8 @@ public class IrisRegion extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = String.class) @Desc("A list of root-level cave biomes in this region, used for carved cave interiors. Don't specify child biomes of other biomes here. Just the root parents.") private KList caveBiomes = new KList<>(); - @ArrayType(min = 1, type = IrisDepositVariant.class) - @Desc("Deposit ore remap rules scoped to this region. Each entry declares a vertical band and a source->replacement block id map. Applied after biome rules but before dimension rules; first matching region rule wins.") - private KList depositVariants = new KList<>(); @Desc("A color for visualizing this region with a color. I.e. #F13AF5. This will show up on the map.") private String color = null; - @Desc("Collection of ores to be generated") - @ArrayType(type = IrisOreGenerator.class, min = 1) - private KList ores = new KList<>(); - - public PlatformBlockState generateOres(int x, int y, int z, RNG rng, IrisData data, boolean surface) { - KList localOres = surface ? getSurfaceOres() : getUndergroundOres(); - return generateOres(localOres, x, y, z, rng, data); - } - - public PlatformBlockState generateSurfaceOres(int x, int y, int z, RNG rng, IrisData data) { - return generateOres(getSurfaceOres(), x, y, z, rng, data); - } - - public PlatformBlockState generateUndergroundOres(int x, int y, int z, RNG rng, IrisData data) { - return generateOres(getUndergroundOres(), x, y, z, rng, data); - } - - public boolean hasSurfaceOres() { - return !getSurfaceOres().isEmpty(); - } - - public boolean hasUndergroundOres() { - return !getUndergroundOres().isEmpty(); - } - - private PlatformBlockState generateOres(KList localOres, int x, int y, int z, RNG rng, IrisData data) { - if (localOres.isEmpty()) { - return null; - } - - int oreCount = localOres.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = localOres.get(oreIndex); - PlatformBlockState ore = oreGenerator.generate(x, y, z, rng, data); - if (ore != null) { - return ore; - } - } - return null; - } - - public void setOres(KList ores) { - this.ores = ores == null ? new KList<>() : ores; - surfaceOreCache.reset(); - undergroundOreCache.reset(); - surfaceOreBoundsCache.reset(); - undergroundOreBoundsCache.reset(); - } - - public KList getSurfaceOreGenerators() { - return getOres(true); - } - - public KList getUndergroundOreGenerators() { - return getOres(false); - } - - public IrisOreGeneratorBounds getSurfaceOreGeneratorBounds() { - return surfaceOreBoundsCache.aquire(() -> IrisOreGeneratorBounds.of(getSurfaceOres())); - } - - public IrisOreGeneratorBounds getUndergroundOreGeneratorBounds() { - return undergroundOreBoundsCache.aquire(() -> IrisOreGeneratorBounds.of(getUndergroundOres())); - } - - private KList getSurfaceOres() { - return getOres(true); - } - - private KList getUndergroundOres() { - return getOres(false); - } - - private KList getOres(boolean surface) { - AtomicCache> oreCache = surface ? surfaceOreCache : undergroundOreCache; - return oreCache.aquire(() -> { - KList filtered = new KList<>(); - KList localOres = ores; - int oreCount = localOres.size(); - for (int oreIndex = 0; oreIndex < oreCount; oreIndex++) { - IrisOreGenerator oreGenerator = localOres.get(oreIndex); - if (oreGenerator.isGenerateSurface() == surface) { - filtered.add(oreGenerator); - } - } - - return filtered; - }); - } public String getName() { return name; From 23eaa15e86f48fe112880266a516db9f09886d61 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:36:44 +0200 Subject: [PATCH 2/7] Layers, slab, wall, sea and cave ceiling layers, rock and fluid palettes and the post processing switches become iris:terrain and iris:post settings IrisBiomePaletteLayer is the PaletteLayer value, IrisBiomeLayerGenerator is BiomeLayers over ResolvedLayer, the dimension's rock and fluid streams are TerrainPalettes. The decorator slope and SlopeClip are one class. A biome's inferred variants keep its module settings. --- README.md | 9 + source-patterns.txt | 1 + .../iris/builtin/decorant/Decorator.java | 7 +- .../iris/builtin/decorant/DecoratorSlope.java | 64 ---- .../builtin/floating/FloatingChildBiome.java | 6 +- .../builtin/post/PostProcessingSettings.java | 44 +++ .../post/PostProcessingSlabsSettings.java | 43 +++ .../post/PostProcessingWallsSettings.java | 43 +++ .../iris/builtin/prepare/SlopeClip.java | 2 +- .../terrain/CaveCeilingLayersSettings.java | 43 +++ .../builtin/terrain/FluidPaletteSettings.java | 47 +++ .../iris/builtin/terrain/LayersSettings.java | 44 +++ .../terrain/LockLayersMaxSettings.java | 41 ++ .../builtin/terrain/LockLayersSettings.java | 39 ++ .../iris/builtin/terrain/PaletteLayer.java | 103 +++++ .../builtin/terrain/RockPaletteSettings.java | 47 +++ .../builtin/terrain/SeaLayersSettings.java | 43 +++ .../iris/builtin/terrain/SlabSettings.java | 41 ++ .../iris/builtin/terrain/WallSettings.java | 42 ++ .../iris/engine/actuator/TerrainModule.java | 48 ++- .../engine/mantle/components/CaveCarving.java | 7 +- .../iris/engine/modifier/CaveApplying.java | 18 +- .../iris/engine/modifier/FloatingIslands.java | 24 +- .../iris/engine/modifier/PostModule.java | 11 + .../engine/modifier/SurfaceSmoothing.java | 22 +- .../engine/object/placement/VacuumModule.java | 8 +- .../terrain/IrisBiomeLayerGenerator.java | 360 ------------------ .../object/terrain/IrisBiomePaletteLayer.java | 165 -------- .../engine/object/world/biome/IrisBiome.java | 67 +--- .../world/biome/IrisBiomeColorRenderer.java | 6 +- .../object/world/dimension/IrisDimension.java | 11 - .../iris/engine/terrain/BiomeLayers.java | 344 +++++++++++++++++ .../iris/engine/terrain/PaletteBlocks.java | 48 +++ .../iris/engine/terrain/ResolvedLayer.java | 139 +++++++ .../iris/engine/terrain/TerrainPalettes.java | 137 +++++++ 35 files changed, 1412 insertions(+), 712 deletions(-) delete mode 100644 src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java create mode 100644 src/main/java/art/arcane/iris/builtin/post/PostProcessingSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/post/PostProcessingSlabsSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/post/PostProcessingWallsSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/CaveCeilingLayersSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/FluidPaletteSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/LayersSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/LockLayersMaxSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/LockLayersSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/PaletteLayer.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/RockPaletteSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/SeaLayersSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/SlabSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/terrain/WallSettings.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomeLayerGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomePaletteLayer.java create mode 100644 src/main/java/art/arcane/iris/engine/terrain/BiomeLayers.java create mode 100644 src/main/java/art/arcane/iris/engine/terrain/PaletteBlocks.java create mode 100644 src/main/java/art/arcane/iris/engine/terrain/ResolvedLayer.java create mode 100644 src/main/java/art/arcane/iris/engine/terrain/TerrainPalettes.java diff --git a/README.md b/README.md index 4bf62dc47..1cf202039 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,15 @@ seed is the world's decorator seed, its biome's key and its place in the biome's them ahead of generation; `iris:terrain` and `iris:objects` warm their ore generators, placements and procedural objects the same way. +`iris:terrain` and `iris:post` own the fields that shape a column's blocks. Per biome: `layers`, `seaLayers`, `caveCeilingLayers` (lists of +`PaletteLayer`, the old biome palette layer, in `art.arcane.iris.builtin.terrain`), `slab` and `wall` (one `PaletteLayer` each), `lockLayers` (a +boolean) and `lockLayersMax` (a number). Per dimension: `rockPalette` and `fluidPalette` (a `PaletteSpec` each) in `art.arcane.iris.builtin.terrain`, and +`postProcessing`, `postProcessingSlabs`, `postProcessingWalls` (booleans) in `art.arcane.iris.builtin.post`. A key a pack leaves out has the +default Iris always had (one grass layer, no slab or wall, stone and water, post processing on). `ResolvedLayer` resolves one layer's blocks and noise +for a pack, `BiomeLayers`, the world's state, keeps them and stacks a biome's layers into the blocks of a column, and `TerrainPalettes` is the world's +rock and fluid as a block for every column; the terrain, cave, floating and post stages ask them. The slope limit of a layer, a decorator and an +object placement is the one `SlopeClip`. + Packs write each settings feature under the short key it declares: `deposits` (dimension, region, biome; a list), `decorators` (biome; a list) and `importedStructures` (dimension; an object of `disabled`, `adjustments` and the rest). The feature ids (`iris:deposit`, `iris:decorant`, `iris:structure`) stay the modules' identity in the stage graph and logs. A key is unique diff --git a/source-patterns.txt b/source-patterns.txt index 31bac204e..c42d04a72 100644 --- a/source-patterns.txt +++ b/source-patterns.txt @@ -1,5 +1,6 @@ art/arcane/iris/engine/actuator/** art/arcane/iris/engine/decorator/** +art/arcane/iris/engine/terrain/** art/arcane/iris/engine/modifier/** art/arcane/iris/engine/mantle/components/** art/arcane/iris/engine/object/** diff --git a/src/main/java/art/arcane/iris/builtin/decorant/Decorator.java b/src/main/java/art/arcane/iris/builtin/decorant/Decorator.java index 891a7778b..db788c086 100644 --- a/src/main/java/art/arcane/iris/builtin/decorant/Decorator.java +++ b/src/main/java/art/arcane/iris/builtin/decorant/Decorator.java @@ -18,6 +18,7 @@ package art.arcane.iris.builtin.decorant; +import art.arcane.iris.builtin.prepare.SlopeClip; import com.volmit.block.BlockSpec; import com.volmit.config.Desc; import com.volmit.config.MaxNumber; @@ -60,7 +61,7 @@ public final class Decorator { private List blacklist; @Desc("The slope at which this decorator can be placed. Range from 0 to 10 by default. Calculated from a 3-block radius from the center of the decorator placement.") - private DecoratorSlope slopeCondition = new DecoratorSlope(); + private SlopeClip slopeCondition = new SlopeClip(); @Desc("If stackMax is set to true, use this to limit its max height for large caverns") private int absoluteMaxStack = 30; @@ -143,8 +144,8 @@ public final class Decorator { return blacklist != null; } - public DecoratorSlope slopeCondition() { - return slopeCondition == null ? new DecoratorSlope() : slopeCondition; + public SlopeClip slopeCondition() { + return slopeCondition == null ? new SlopeClip() : slopeCondition; } public int absoluteMaxStack() { diff --git a/src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java b/src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java deleted file mode 100644 index f7ea80716..000000000 --- a/src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java +++ /dev/null @@ -1,64 +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 . - */ - -package art.arcane.iris.builtin.decorant; - -import com.volmit.config.Desc; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; - -/** The terrain slopes a decorator may be placed on, as packs write it in a decorator's {@code slopeCondition}. */ -@Desc("Limits placement to a minimum and maximum terrain slope") -public final class DecoratorSlope { - private static final double UNLIMITED_MINIMUM = 0; - private static final double UNLIMITED_MAXIMUM = 10; - - @MinNumber(0) - @MaxNumber(1024) - @Desc("The minimum slope for placement") - private double minimumSlope = UNLIMITED_MINIMUM; - - @MinNumber(0) - @MaxNumber(1024) - @Desc("The maximum slope for placement") - private double maximumSlope = UNLIMITED_MAXIMUM; - - public DecoratorSlope() { - } - - public double minimumSlope() { - return minimumSlope; - } - - public double maximumSlope() { - return maximumSlope; - } - - /** Whether every slope passes: the limits are the defaults, or looser. */ - public boolean isDefault() { - return minimumSlope <= UNLIMITED_MINIMUM && maximumSlope >= UNLIMITED_MAXIMUM; - } - - public boolean isValid(double slope) { - if (isDefault()) { - return true; - } - - return !(minimumSlope > slope) && !(maximumSlope < slope); - } -} diff --git a/src/main/java/art/arcane/iris/builtin/floating/FloatingChildBiome.java b/src/main/java/art/arcane/iris/builtin/floating/FloatingChildBiome.java index 608be30c7..efd8dd462 100644 --- a/src/main/java/art/arcane/iris/builtin/floating/FloatingChildBiome.java +++ b/src/main/java/art/arcane/iris/builtin/floating/FloatingChildBiome.java @@ -19,7 +19,7 @@ package art.arcane.iris.builtin.floating; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; -import art.arcane.iris.engine.object.terrain.IrisBiomePaletteLayer; +import art.arcane.iris.builtin.terrain.PaletteLayer; import com.volmit.config.Desc; import com.volmit.config.MaxNumber; import com.volmit.config.MinItems; @@ -149,7 +149,7 @@ public final class FloatingChildBiome { @MinItems(1) @Desc("Custom palette layers used near the underside when bottomPaletteMode=CUSTOM. The layer format is the same as normal biome layers.") - private List bottomPalette = List.of(); + private List bottomPalette = List.of(); @MinNumber(1) @MaxNumber(512) @@ -315,7 +315,7 @@ public final class FloatingChildBiome { return bottomPaletteMode == null ? FloatingBottomPaletteMode.DEPTH : bottomPaletteMode; } - public List bottomPalette() { + public List bottomPalette() { return bottomPalette == null ? List.of() : Collections.unmodifiableList(bottomPalette); } diff --git a/src/main/java/art/arcane/iris/builtin/post/PostProcessingSettings.java b/src/main/java/art/arcane/iris/builtin/post/PostProcessingSettings.java new file mode 100644 index 000000000..ceb2f1442 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/post/PostProcessingSettings.java @@ -0,0 +1,44 @@ +/* + * 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.post; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** + * Whether a dimension is post processed, written as {@code "postProcessing": true}. Iris has never read this flag: surface smoothing runs + * whatever it says, so it is declared to keep the key valid in packs. + */ +@Desc("Use post processing or not") +@Feature(id = "iris:post/enabled", name = "Post processing", key = "postProcessing", root = "enabled", targets = Target.DIMENSION) +public final class PostProcessingSettings implements IrisFeature { + public static final boolean DEFAULT_ENABLED = true; + + @Desc("Use post processing or not") + private boolean enabled = DEFAULT_ENABLED; + + public PostProcessingSettings() { + } + + public boolean enabled() { + return enabled; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/post/PostProcessingSlabsSettings.java b/src/main/java/art/arcane/iris/builtin/post/PostProcessingSlabsSettings.java new file mode 100644 index 000000000..a6bffc932 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/post/PostProcessingSlabsSettings.java @@ -0,0 +1,43 @@ +/* + * 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.post; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** + * Whether post processing adds slabs on steps in a dimension, written as {@code "postProcessingSlabs": false}. A dimension without the key adds them. + */ +@Desc("Add slabs in post processing") +@Feature(id = "iris:post/slabs", name = "Post processing slabs", key = "postProcessingSlabs", root = "enabled", targets = Target.DIMENSION) +public final class PostProcessingSlabsSettings implements IrisFeature { + public static final boolean DEFAULT_ENABLED = true; + + @Desc("Add slabs in post processing") + private boolean enabled = DEFAULT_ENABLED; + + public PostProcessingSlabsSettings() { + } + + public boolean enabled() { + return enabled; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/post/PostProcessingWallsSettings.java b/src/main/java/art/arcane/iris/builtin/post/PostProcessingWallsSettings.java new file mode 100644 index 000000000..f49e5e6a7 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/post/PostProcessingWallsSettings.java @@ -0,0 +1,43 @@ +/* + * 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.post; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** + * Whether post processing paints walls on steep faces in a dimension, written as {@code "postProcessingWalls": false}. A dimension without the key paints them. + */ +@Desc("Add painted walls in post processing") +@Feature(id = "iris:post/walls", name = "Post processing walls", key = "postProcessingWalls", root = "enabled", targets = Target.DIMENSION) +public final class PostProcessingWallsSettings implements IrisFeature { + public static final boolean DEFAULT_ENABLED = true; + + @Desc("Add painted walls in post processing") + private boolean enabled = DEFAULT_ENABLED; + + public PostProcessingWallsSettings() { + } + + public boolean enabled() { + return enabled; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/prepare/SlopeClip.java b/src/main/java/art/arcane/iris/builtin/prepare/SlopeClip.java index 9d2030c1d..c5686d1c6 100644 --- a/src/main/java/art/arcane/iris/builtin/prepare/SlopeClip.java +++ b/src/main/java/art/arcane/iris/builtin/prepare/SlopeClip.java @@ -23,7 +23,7 @@ import com.volmit.config.MaxNumber; import com.volmit.config.MinNumber; import com.volmit.config.Snippet; -/** The terrain slopes a placement or decorator may sit on, written as its {@code slopeCondition}. */ +/** The terrain slopes an object placement, a decorator or a terrain layer may sit on, written as its {@code slopeCondition}. */ @Snippet("slope-clip") @Desc("Limits placement to a minimum and maximum terrain slope") public final class SlopeClip { diff --git a/src/main/java/art/arcane/iris/builtin/terrain/CaveCeilingLayersSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/CaveCeilingLayersSettings.java new file mode 100644 index 000000000..e8ce22b91 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/CaveCeilingLayersSettings.java @@ -0,0 +1,43 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +import java.util.List; + +/** + * The layers of material on the ceilings of caves in a biome, written as {@code "caveCeilingLayers": [...]}, the list of layers. + */ +@Desc("Layers of materials placed on cave ceilings in this biome, indexed upward from the ceiling surface. Must not have more entries than layers, whose height generators it reuses. Omitting this leaves cave ceilings unchanged.") +@Feature(id = "iris:terrain/cave-ceiling-layers", name = "Cave ceiling layers", key = "caveCeilingLayers", root = "layers", targets = Target.BIOME) +public final class CaveCeilingLayersSettings implements IrisFeature { + @Desc("Layers of materials placed on cave ceilings in this biome, indexed upward from the ceiling surface. Must not have more entries than layers, whose height generators it reuses. Omitting this leaves cave ceilings unchanged.") + private List layers = List.of(); + + public CaveCeilingLayersSettings() { + } + + public List layers() { + return layers == null ? List.of() : layers; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/FluidPaletteSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/FluidPaletteSettings.java new file mode 100644 index 000000000..3dbaef879 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/FluidPaletteSettings.java @@ -0,0 +1,47 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.block.BlockSpec; +import com.volmit.block.PaletteSpec; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +import java.util.List; + +/** + * The blocks that fill ocean columns and cave aquifers of a dimension, written as {@code "fluidPalette": {...}}, a palette. A dimension without the key is water. + */ +@Desc("The dimension fluid block palette used for ocean columns and cave aquifers.") +@Feature(id = "iris:terrain/fluid-palette", name = "Fluid palette", key = "fluidPalette", root = "palette", targets = Target.DIMENSION) +public final class FluidPaletteSettings implements IrisFeature { + private static final String DEFAULT_BLOCK = "water"; + + @Desc("The dimension fluid block palette used for ocean columns and cave aquifers.") + private PaletteSpec palette = PaletteSpec.of(List.of(BlockSpec.of(DEFAULT_BLOCK))); + + public FluidPaletteSettings() { + } + + public PaletteSpec palette() { + return palette == null ? PaletteSpec.of(List.of(BlockSpec.of(DEFAULT_BLOCK))) : palette; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/LayersSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/LayersSettings.java new file mode 100644 index 000000000..02f2ba399 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/LayersSettings.java @@ -0,0 +1,44 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +import java.util.List; + +/** + * The layers of material a biome is made of below its surface, written as {@code "layers": [...]}, the list of layers. A biome + * that declares none gets one layer of grass, so the settings class default is what a biome without the key has. + */ +@Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") +@Feature(id = "iris:terrain/layers", name = "Layers", key = "layers", root = "layers", targets = Target.BIOME) +public final class LayersSettings implements IrisFeature { + @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") + private List layers = List.of(new PaletteLayer()); + + public LayersSettings() { + } + + public List layers() { + return layers == null ? List.of() : layers; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/LockLayersMaxSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/LockLayersMaxSettings.java new file mode 100644 index 000000000..9b18cf7f1 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/LockLayersMaxSettings.java @@ -0,0 +1,41 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** How many layers a locked biome iterates below the surface, written as {@code "lockLayersMax": 7}. A biome without the key iterates seven. */ +@Desc("The max layers to iterate below the surface for locked layer biomes (mesa).") +@Feature(id = "iris:terrain/lock-layers-max", name = "Lock layers max", key = "lockLayersMax", root = "layers", targets = Target.BIOME) +public final class LockLayersMaxSettings implements IrisFeature { + public static final int DEFAULT_LAYERS = 7; + + @Desc("The max layers to iterate below the surface for locked layer biomes (mesa).") + private int layers = DEFAULT_LAYERS; + + public LockLayersMaxSettings() { + } + + public int layers() { + return layers; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/LockLayersSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/LockLayersSettings.java new file mode 100644 index 000000000..a8a98063c --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/LockLayersSettings.java @@ -0,0 +1,39 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** Whether a biome's layers are locked to its highest possible height, written as {@code "lockLayers": true}. A biome without the key is not locked. */ +@Desc("Layers no longer descend from the surface block, they descend from the max possible height the biome can produce (constant) creating mesa like layers.") +@Feature(id = "iris:terrain/lock-layers", name = "Lock layers", key = "lockLayers", root = "locked", targets = Target.BIOME) +public final class LockLayersSettings implements IrisFeature { + @Desc("Layers no longer descend from the surface block, they descend from the max possible height the biome can produce (constant) creating mesa like layers.") + private boolean locked = false; + + public LockLayersSettings() { + } + + public boolean locked() { + return locked; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/PaletteLayer.java b/src/main/java/art/arcane/iris/builtin/terrain/PaletteLayer.java new file mode 100644 index 000000000..a6d68d388 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/PaletteLayer.java @@ -0,0 +1,103 @@ +/* + * 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.terrain; + +import art.arcane.iris.builtin.prepare.SlopeClip; +import com.volmit.block.BlockSpec; +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinItems; +import com.volmit.config.MinNumber; +import com.volmit.config.Required; +import com.volmit.config.Snippet; +import com.volmit.noise.NoiseStyle; + +import java.util.List; + +/** + * One layer of surface or subsurface material of a biome, as packs write it in the biome's layers, sea layers, cave + * ceiling layers, slab and wall, in a floating island's bottom palette or under {@code snippet/biome-palette/}. A value of + * IrisApi types only; the terrain module resolves the blocks and builds the noise. + */ +@Snippet("biome-palette") +@Desc("A layer of surface / subsurface material in biomes") +public final class PaletteLayer { + private static final String STATIC_NOISE = "STATIC"; + private static final String DEFAULT_BLOCK = "grass_block"; + + @Desc("The style of noise") + private NoiseStyle style = NoiseStyle.of(STATIC_NOISE); + + @MinNumber(0) + @MaxNumber(2032) + @Desc("The min thickness of this layer") + private int minHeight = 1; + + @MinNumber(1) + @MaxNumber(2032) + @Desc("The max thickness of this layer") + private int maxHeight = 1; + + @Desc("If set, this layer only shows where the terrain slope is within these bounds; outside them the layer is skipped entirely. Thickness is not scaled by slope.") + private SlopeClip slopeCondition = new SlopeClip(); + + @MinNumber(0.0001) + @Desc("The terrain zoom mostly for zooming in on a wispy palette") + private double zoom = 5; + + @Required + @MinItems(1) + @Desc("The palette of blocks to be used in this layer") + private List palette = List.of(BlockSpec.of(DEFAULT_BLOCK)); + + /** A layer with every option at its default, as packs get it from {@code {}}. */ + public PaletteLayer() { + } + + /** A layer with the default options and no block to place, which is what a biome without a slab or wall has. */ + public static PaletteLayer withoutBlocks() { + PaletteLayer layer = new PaletteLayer(); + layer.palette = List.of(); + return layer; + } + + public NoiseStyle style() { + return style == null ? NoiseStyle.of(STATIC_NOISE) : style; + } + + public int minHeight() { + return minHeight; + } + + public int maxHeight() { + return maxHeight; + } + + public SlopeClip slopeCondition() { + return slopeCondition == null ? new SlopeClip() : slopeCondition; + } + + public double zoom() { + return zoom; + } + + public List palette() { + return palette == null ? List.of() : palette; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/RockPaletteSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/RockPaletteSettings.java new file mode 100644 index 000000000..786c25326 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/RockPaletteSettings.java @@ -0,0 +1,47 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.block.BlockSpec; +import com.volmit.block.PaletteSpec; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +import java.util.List; + +/** + * The blocks that fill terrain below the layers of a dimension, written as {@code "rockPalette": {...}}, a palette. A dimension without the key is stone. + */ +@Desc("The palette of blocks for 'stone'") +@Feature(id = "iris:terrain/rock-palette", name = "Rock palette", key = "rockPalette", root = "palette", targets = Target.DIMENSION) +public final class RockPaletteSettings implements IrisFeature { + private static final String DEFAULT_BLOCK = "stone"; + + @Desc("The palette of blocks for 'stone'") + private PaletteSpec palette = PaletteSpec.of(List.of(BlockSpec.of(DEFAULT_BLOCK))); + + public RockPaletteSettings() { + } + + public PaletteSpec palette() { + return palette == null ? PaletteSpec.of(List.of(BlockSpec.of(DEFAULT_BLOCK))) : palette; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/SeaLayersSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/SeaLayersSettings.java new file mode 100644 index 000000000..d6693e572 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/SeaLayersSettings.java @@ -0,0 +1,43 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +import java.util.List; + +/** + * The layers of material filling the water column of a sea biome, written as {@code "seaLayers": [...]}, the list of layers. + */ +@Desc("Layers of materials filling the water column of sea biomes, indexed downward from the water surface. Anything below the last layer is filled with the dimension fluid palette, not stone.") +@Feature(id = "iris:terrain/sea-layers", name = "Sea layers", key = "seaLayers", root = "layers", targets = Target.BIOME) +public final class SeaLayersSettings implements IrisFeature { + @Desc("Layers of materials filling the water column of sea biomes, indexed downward from the water surface. Anything below the last layer is filled with the dimension fluid palette, not stone.") + private List layers = List.of(); + + public SeaLayersSettings() { + } + + public List layers() { + return layers == null ? List.of() : layers; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/SlabSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/SlabSettings.java new file mode 100644 index 000000000..a9f1d9f0d --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/SlabSettings.java @@ -0,0 +1,41 @@ +/* + * 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.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** + * The slab post processing places on steps in a biome, written as {@code "slab": {...}}, one layer. A biome without the key has no slab. + */ +@Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.") +@Feature(id = "iris:terrain/slab", name = "Slab", key = "slab", root = "layer", targets = Target.BIOME) +public final class SlabSettings implements IrisFeature { + @Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.") + private PaletteLayer layer = PaletteLayer.withoutBlocks(); + + public SlabSettings() { + } + + public PaletteLayer layer() { + return layer == null ? PaletteLayer.withoutBlocks() : layer; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/terrain/WallSettings.java b/src/main/java/art/arcane/iris/builtin/terrain/WallSettings.java new file mode 100644 index 000000000..4c700b1e4 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/terrain/WallSettings.java @@ -0,0 +1,42 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.builtin.terrain; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** + * The wall post processing paints on steep faces, and caves paint on their walls, in a biome, written as {@code "wall": {...}}, one layer. + * A biome without the key has no wall. + */ +@Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)") +@Feature(id = "iris:terrain/wall", name = "Wall", key = "wall", root = "layer", targets = Target.BIOME) +public final class WallSettings implements IrisFeature { + @Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)") + private PaletteLayer layer = PaletteLayer.withoutBlocks(); + + public WallSettings() { + } + + public PaletteLayer layer() { + return layer == null ? PaletteLayer.withoutBlocks() : layer; + } +} diff --git a/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java b/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java index 7926c0357..e0068796d 100644 --- a/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java +++ b/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java @@ -19,6 +19,15 @@ package art.arcane.iris.engine.actuator; import art.arcane.iris.builtin.IrisStages; +import art.arcane.iris.builtin.terrain.CaveCeilingLayersSettings; +import art.arcane.iris.builtin.terrain.FluidPaletteSettings; +import art.arcane.iris.builtin.terrain.LayersSettings; +import art.arcane.iris.builtin.terrain.LockLayersMaxSettings; +import art.arcane.iris.builtin.terrain.LockLayersSettings; +import art.arcane.iris.builtin.terrain.RockPaletteSettings; +import art.arcane.iris.builtin.terrain.SeaLayersSettings; +import art.arcane.iris.builtin.terrain.SlabSettings; +import art.arcane.iris.builtin.terrain.WallSettings; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.modules.IrisChunk; import art.arcane.iris.core.modules.IrisPackWorld; @@ -30,6 +39,8 @@ import art.arcane.iris.engine.object.terrain.deposit.IrisOreGeneratorBounds; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.world.region.IrisRegion; +import art.arcane.iris.engine.terrain.BiomeLayers; +import art.arcane.iris.engine.terrain.TerrainPalettes; import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.util.common.data.B; import art.arcane.iris.util.project.context.ChunkContext; @@ -51,7 +62,7 @@ import com.volmit.world.PackWorld; * Module {@code iris:terrain}: the chunk's ground, fluids and biome layers. Each column is filled from bedrock up * to its height and the fluid height with its biome's layers, with ore generators of the dimension, region and * biome replacing blocks on the way and the upper dimension's ground filled in from the top. The ore generators' noise - * is built ahead of generation, in {@link #warmUp}. + * and the rock and fluid palettes' noise are built ahead of generation, in {@link #warmUp}. */ public final class TerrainModule implements IrisModule, ModuleLifecycle { private static final String VERSION = "built-in"; @@ -63,12 +74,23 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { @Override public void register(FeatureRegistry registry) { + registry.registerSettings(LayersSettings.class); + registry.registerSettings(SeaLayersSettings.class); + registry.registerSettings(CaveCeilingLayersSettings.class); + registry.registerSettings(SlabSettings.class); + registry.registerSettings(WallSettings.class); + registry.registerSettings(LockLayersSettings.class); + registry.registerSettings(LockLayersMaxSettings.class); + registry.registerSettings(RockPaletteSettings.class); + registry.registerSettings(FluidPaletteSettings.class); registry.registerLifecycle(this); } @Override public void warmUp(PackWorld world) { - new OreWarmUp(IrisPackWorld.of(world).engine()).warm(); + Engine engine = IrisPackWorld.of(world).engine(); + TerrainPalettes.of(engine).warm(); + new OreWarmUp(engine).warm(); } @Override @@ -86,10 +108,18 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { private static final PlatformBlockState BEDROCK = B.getState("BEDROCK"); private final Engine engine; + private final TerrainPalettes palettes; + private final BiomeLayers layers; private final RNG rng; TerrainShaper(Engine engine) { + this(engine, TerrainPalettes.of(engine), BiomeLayers.of(engine)); + } + + TerrainShaper(Engine engine, TerrainPalettes palettes, BiomeLayers layers) { this.engine = engine; + this.palettes = palettes; + this.layers = layers; this.rng = new RNG(engine.getSeedManager().getTerrain()); } @@ -118,8 +148,6 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { boolean hideOres = dimension.isHideOresForHiddenOre(); ChunkedDataCache biomeCache = context.getBiome(); ChunkedDataCache regionCache = context.getRegion(); - ChunkedDataCache fluidCache = context.getFluid(); - ChunkedDataCache rockCache = context.getRock(); int realX = xf + x; UpperDimensionContext upperContext = engine.getUpperContext(); // Dimension-level ore lookups are chunk-invariant; resolving them per column paid @@ -140,8 +168,8 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { } int topY = Math.min(hf, chunkHeight - 1); - PlatformBlockState fluid = fluidCache.get(xf, zf); - PlatformBlockState rock = rockCache.get(xf, zf); + PlatformBlockState fluid = palettes.fluidAt(realX, realZ); + PlatformBlockState rock = palettes.rockAt(realX, realZ); PlatformBlockState mappedSurfaceBlock = complex.getImageMapRuntime().sampleSurfaceBlock(realX, realZ); KList biomeSurfaceOres = hideOres ? null : biome.getSurfaceOreGenerators(); KList regionSurfaceOres = hideOres ? null : region.getSurfaceOreGenerators(); @@ -182,7 +210,7 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { if (i > he && i <= hf) { int fdepth = hf - i; if (fblocks == null) { - fblocks = biome.generateSeaLayers(realX, realZ, localRng, hf - he, data); + fblocks = layers.generateSeaLayers(biome, realX, realZ, localRng, hf - he, data); } if (fblocks.hasIndex(fdepth)) { @@ -200,7 +228,7 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { continue; } if (blocks == null) { - blocks = biome.generateLayers(dimension, realX, realZ, localRng, he, he, data, complex); + blocks = layers.generateLayers(biome, dimension, realX, realZ, localRng, he, he, data, complex); } if (blocks.hasIndex(depth)) { @@ -235,11 +263,11 @@ public final class TerrainModule implements IrisModule, ModuleLifecycle { if (upperSurfaceY < chunkHeight - 1) { IrisBiome upperBiome = upperContext.getUpperBiome(realX, realZ); - PlatformBlockState upperRock = upperContext.getRockBlock(realX, realZ); + PlatformBlockState upperRock = palettes.upperRockAt(upperContext, realX, realZ); PlatformBlockState upperMappedSurface = upperContext.getSurfaceBlock(realX, realZ); int upperThickness = chunkHeight - 1 - upperSurfaceY; KList upperBlocks = upperBiome != null - ? upperBiome.generateLayers(upperContext.getDimension(), + ? layers.generateLayers(upperBiome, upperContext.getDimension(), realX, realZ, localRng, upperThickness, upperThickness, upperContext.getData(), complex) : null; diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java b/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java index 2660dc3f2..9ece76776 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java @@ -23,6 +23,7 @@ import art.arcane.iris.engine.IrisComplex; import art.arcane.iris.engine.UpperDimensionContext; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.mantle.MantleWriter; +import art.arcane.iris.engine.terrain.TerrainPalettes; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingEntry; import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver; @@ -466,7 +467,7 @@ public class CaveCarving { private void prefillProfileFieldSamples(int startX, int startZ, IrisComplex complex, BlendScratch blendScratch) { fillFieldHeights(complex.getHeightStream(), startX, startZ, blendScratch.fieldSurfaceHeights); - fillFieldFluidPresence(complex.getFluidStream(), startX, startZ, blendScratch.fieldHasFluid); + fillFieldFluidPresence(TerrainPalettes.of(engine), startX, startZ, blendScratch.fieldHasFluid); fillFieldObjects(complex.getRegionStream(), startX, startZ, blendScratch.fieldRegions); fillFieldObjects(complex.getTrueBiomeStream(), startX, startZ, blendScratch.fieldSurfaceBiomes); fillFieldObjects(complex.getCaveBiomeStream(), startX, startZ, blendScratch.fieldCaveBiomes); @@ -490,11 +491,11 @@ public class CaveCarving { } } - private void fillFieldFluidPresence(ProceduralStream stream, int startX, int startZ, boolean[] target) { + private void fillFieldFluidPresence(TerrainPalettes palettes, int startX, int startZ, boolean[] target) { for (int fieldX = 0; fieldX < FIELD_SIZE; fieldX++) { int worldX = startX + fieldX; for (int fieldZ = 0; fieldZ < FIELD_SIZE; fieldZ++) { - target[(fieldX * FIELD_SIZE) + fieldZ] = B.isFluid(stream.get(worldX, startZ + fieldZ)); + target[(fieldX * FIELD_SIZE) + fieldZ] = B.isFluid(palettes.fluidAt(worldX, startZ + fieldZ)); } } } diff --git a/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java b/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java index 15242fee5..9ecd42df6 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java +++ b/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java @@ -21,6 +21,8 @@ package art.arcane.iris.engine.modifier; import art.arcane.iris.engine.UpperDimensionContext; import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.engine.decorator.BiomeDecorators; +import art.arcane.iris.engine.terrain.BiomeLayers; +import art.arcane.iris.engine.terrain.TerrainPalettes; import art.arcane.iris.engine.decorator.IrisCeilingDecorator; import art.arcane.iris.engine.decorator.IrisSurfaceDecorator; import art.arcane.iris.engine.framework.Engine; @@ -66,6 +68,8 @@ public class CaveApplying { private final PlatformBlockState AIR = B.getState("CAVE_AIR"); private final PlatformBlockState LAVA = B.getState("LAVA"); private final BiomeDecorators decorators; + private final BiomeLayers layers; + private final TerrainPalettes palettes; private final IrisSurfaceDecorator surfaceDecorator; private final IrisCeilingDecorator ceilingDecorator; @@ -73,6 +77,8 @@ public class CaveApplying { this.engine = engine; rng = new RNG(engine.getSeedManager().getCarve()); decorators = BiomeDecorators.of(engine); + layers = BiomeLayers.of(engine); + palettes = TerrainPalettes.of(engine); surfaceDecorator = new IrisSurfaceDecorator(engine); ceilingDecorator = new IrisCeilingDecorator(engine); } @@ -151,7 +157,7 @@ public class CaveApplying { if (explicitCarveIntent) { // Only a fluid cavern consumes the fluid sample, and on the maintenance path that // sample is a full procedural stream evaluation, so never take it per voxel. - PlatformBlockState fluid = isFluidIntent(cavern) ? context.getFluid().get(rx, rz) : null; + PlatformBlockState fluid = isFluidIntent(cavern) ? palettes.fluidAt(chunkBlockX + rx, chunkBlockZ + rz) : null; output.setRaw(rx, yy, rz, resolveExplicitCarveState(cavern, fluid, LAVA, AIR)); } else if (usesDefaultLava(caveLavaHeight, yy)) { output.setRaw(rx, yy, rz, LAVA); @@ -178,7 +184,7 @@ public class CaveApplying { : resolveCustomBiome(customBiomeCache, customBiome); if (biome != null) { - PlatformBlockState data = biome.getWall().get(rng, worldX, yy, worldZ, engine.getData()); + PlatformBlockState data = layers.wall(biome, engine.getData()).get(rng, worldX, yy, worldZ); int columnIndex = PowerOfTwoCoordinates.packLocal16(rx, rz); if (data != null && B.isSolid(output.getRaw(rx, yy, rz)) && yy < surfaceHeights[columnIndex]) { @@ -516,7 +522,7 @@ public class CaveApplying { } if (floorBiome != null) { - KList floorLayers = floorBiome.generateLayers( + KList floorLayers = layers.generateLayers(floorBiome, engine.getDimension(), worldX, worldZ, rng, 3, zoneFloor, engine.getData(), engine.getComplex()); for (int i = 0; i < zoneFloor - 1; i++) { if (!floorLayers.hasIndex(i)) { @@ -541,7 +547,7 @@ public class CaveApplying { if (ceilingBiome != null) { int worldMaxY = engine.getWorld().maxHeight() - engine.getWorld().minHeight(); - KList ceilingLayers = ceilingBiome.generateCeilingLayers( + KList ceilingLayers = layers.generateCeilingLayers(ceilingBiome, engine.getDimension(), worldX, worldZ, rng, 3, zoneCeiling, engine.getData(), engine.getComplex()); for (int i = 0; i < ceilingLayers.size(); i++) { int ceilingY = zoneCeiling + i + 1; @@ -603,7 +609,7 @@ public class CaveApplying { } if (floorBiome != null) { - KList floorBlocks = floorBiome.generateLayers(engine.getDimension(), xx, zz, rng, 3, zone.floor, engine.getData(), engine.getComplex()); + KList floorBlocks = layers.generateLayers(floorBiome, engine.getDimension(), xx, zz, rng, 3, zone.floor, engine.getData(), engine.getComplex()); for (int i = 0; i < zone.floor - 1; i++) { if (!floorBlocks.hasIndex(i)) { break; @@ -623,7 +629,7 @@ public class CaveApplying { } if (ceilingBiome != null) { - KList ceilingBlocks = ceilingBiome.generateCeilingLayers(engine.getDimension(), xx, zz, rng, 3, zone.ceiling, engine.getData(), engine.getComplex()); + KList ceilingBlocks = layers.generateCeilingLayers(ceilingBiome, engine.getDimension(), xx, zz, rng, 3, zone.ceiling, engine.getData(), engine.getComplex()); for (int i = 0; i < ceilingBlocks.size(); i++) { int cy = zone.ceiling + i + 1; if (cy >= maxY) { diff --git a/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java b/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java index 70ee4b567..90f51a6e0 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java +++ b/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java @@ -22,6 +22,7 @@ package art.arcane.iris.engine.modifier; import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild; import art.arcane.iris.builtin.floating.FloatingBottomPaletteMode; import art.arcane.iris.builtin.prepare.SlopeClip; +import art.arcane.iris.builtin.terrain.PaletteLayer; import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.IrisComplex; @@ -32,7 +33,8 @@ import art.arcane.iris.engine.framework.EngineDecorator; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.terrain.IrisBiomePaletteLayer; +import art.arcane.iris.engine.terrain.BiomeLayers; +import art.arcane.iris.engine.terrain.ResolvedLayer; import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.spi.IrisLogging; @@ -64,15 +66,16 @@ public class FloatingIslands { private final Engine engine; private final RNG rng; private final EngineDecorator seaSurfaceDecorator; + private final BiomeLayers biomeLayers; - private static KList generateBottomPaletteLayers(ResolvedFloatingChild entry, IrisDimension dimension, double wx, double wz, RNG random, int paletteDepth, IrisData data, IrisComplex complex) { + private KList generateBottomPaletteLayers(ResolvedFloatingChild entry, IrisDimension dimension, double wx, double wz, RNG random, int paletteDepth, IrisData data, IrisComplex complex) { if (entry == null || entry.settings().bottomPaletteMode() != FloatingBottomPaletteMode.CUSTOM || entry.settings().bottomPalette() == null || entry.settings().bottomPalette().isEmpty()) { return null; } return generatePaletteLayers(dimension, new KList<>(entry.settings().bottomPalette()), wx, wz, random.nextParallelRNG(0xB0770B), paletteDepth, data, complex); } - private static KList generatePaletteLayers(IrisDimension dimension, KList layers, double wx, double wz, RNG random, int maxDepth, IrisData data, IrisComplex complex) { + private KList generatePaletteLayers(IrisDimension dimension, KList layers, double wx, double wz, RNG random, int maxDepth, IrisData data, IrisComplex complex) { KList generated = new KList<>(); if (layers == null || layers.isEmpty() || maxDepth <= 0) { return generated; @@ -80,13 +83,13 @@ public class FloatingIslands { int generatorSeed = 7235; for (int i = 0; i < layers.size(); i++) { - IrisBiomePaletteLayer layer = layers.get(i); - CNG heightGenerator = layer.getHeightGenerator(random.nextParallelRNG((generatorSeed++) * generatorSeed * generatorSeed * generatorSeed), data); + ResolvedLayer layer = biomeLayers.resolve(layers.get(i), data); + CNG heightGenerator = layer.heightNoise(random.nextParallelRNG((generatorSeed++) * generatorSeed * generatorSeed * generatorSeed)); if (heightGenerator == null) { continue; } - double layerDepth = heightGenerator.fit(layer.getMinHeight(), layer.getMaxHeight(), wx / layer.getZoom(), wz / layer.getZoom()); - SlopeClip slopeClip = layer.getSlopeCondition(); + double layerDepth = heightGenerator.fit(layer.minHeight(), layer.maxHeight(), wx / layer.zoom(), wz / layer.zoom()); + SlopeClip slopeClip = layer.slopeCondition(); if (slopeClip != null && !slopeClip.isDefault() && complex != null && !slopeClip.isValid(complex.getSlopeStream().get(wx, wz))) { layerDepth = 0; @@ -102,7 +105,7 @@ public class FloatingIslands { } try { - generated.add(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.getZoom(), j, (wz - j) / layer.getZoom(), data)); + generated.add(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.zoom(), j, (wz - j) / layer.zoom())); } catch (Throwable e) { IrisLogging.reportError(e); } @@ -183,9 +186,9 @@ public class FloatingIslands { IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, data); int entrySeed = entry == null || entry.settings().biome() == null ? 0 : entry.settings().biome().hashCode(); RNG layerRng = rng.nextParallelRNG((int) (colSeed ^ 0x7A4E ^ entrySeed)); - KList topBlocks = target == null ? null : target.generateLayers(dimension, wx, wz, layerRng, paletteDepth, paletteDepth, data, complex); + KList topBlocks = target == null ? null : biomeLayers.generateLayers(target, dimension, wx, wz, layerRng, paletteDepth, paletteDepth, data, complex); if (topBlocks == null || topBlocks.isEmpty()) { - topBlocks = parent.generateLayers(dimension, wx, wz, layerRng, paletteDepth, paletteDepth, data, complex); + topBlocks = biomeLayers.generateLayers(parent, dimension, wx, wz, layerRng, paletteDepth, paletteDepth, data, complex); } KList bottomBlocks = generateBottomPaletteLayers(entry, dimension, wx, wz, layerRng, paletteDepth, data, complex); return new PaletteContext(topBlocks, bottomBlocks, B.getState("minecraft:stone")); @@ -207,6 +210,7 @@ public class FloatingIslands { this.engine = engine; rng = new RNG(engine.getSeedManager().getTerrain() ^ 0x7EB0A73F1DCE514DL); seaSurfaceDecorator = new IrisSeaSurfaceDecorator(engine); + biomeLayers = BiomeLayers.of(engine); } /** Fills the islands' solids into the chunk whose first block is {@code x}, {@code z}. */ diff --git a/src/main/java/art/arcane/iris/engine/modifier/PostModule.java b/src/main/java/art/arcane/iris/engine/modifier/PostModule.java index a39f8546f..98b595594 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/PostModule.java +++ b/src/main/java/art/arcane/iris/engine/modifier/PostModule.java @@ -19,7 +19,11 @@ package art.arcane.iris.engine.modifier; import art.arcane.iris.builtin.IrisStages; +import art.arcane.iris.builtin.post.PostProcessingSettings; +import art.arcane.iris.builtin.post.PostProcessingSlabsSettings; +import art.arcane.iris.builtin.post.PostProcessingWallsSettings; import art.arcane.iris.core.modules.IrisChunk; +import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; import com.volmit.stage.ChunkStageContext; @@ -37,6 +41,13 @@ public final class PostModule implements IrisModule { return ModuleInfo.of("iris:post", "Post-processing", VERSION); } + @Override + public void register(FeatureRegistry registry) { + registry.registerSettings(PostProcessingSettings.class); + registry.registerSettings(PostProcessingSlabsSettings.class); + registry.registerSettings(PostProcessingWallsSettings.class); + } + @Override public void install(StageGraph graph) { graph.define(IrisStages.Post.SMOOTH).requires(IrisStages.Carve.APPLY).run(PostModule::smooth); diff --git a/src/main/java/art/arcane/iris/engine/modifier/SurfaceSmoothing.java b/src/main/java/art/arcane/iris/engine/modifier/SurfaceSmoothing.java index 6b15edda1..fad2f2b66 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/SurfaceSmoothing.java +++ b/src/main/java/art/arcane/iris/engine/modifier/SurfaceSmoothing.java @@ -18,12 +18,16 @@ package art.arcane.iris.engine.modifier; +import art.arcane.iris.builtin.post.PostProcessingSlabsSettings; +import art.arcane.iris.builtin.post.PostProcessingWallsSettings; import art.arcane.iris.builtin.prepare.SlopeClip; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.mantle.EngineMantle; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; +import art.arcane.iris.engine.terrain.BiomeLayers; +import art.arcane.iris.engine.terrain.ResolvedLayer; import art.arcane.iris.util.project.context.ChunkContext; import art.arcane.iris.util.common.data.B; import art.arcane.iris.util.project.hunk.Hunk; @@ -42,10 +46,12 @@ public class SurfaceSmoothing { } private final Engine engine; + private final BiomeLayers layers; private final RNG rng; public SurfaceSmoothing(Engine engine) { this.engine = engine; + layers = BiomeLayers.of(engine); rng = new RNG(engine.getSeedManager().getPost()); } @@ -60,8 +66,10 @@ public class SurfaceSmoothing { int planeWidth = width + 2; int[] heights = heightPlane(x, z, width, depth, planeWidth); IrisDimension dimension = engine.getDimension(); - boolean walls = dimension.isPostProcessingWalls(); - boolean slabs = dimension.isPostProcessingSlabs(); + boolean walls = dimension.getModuleSettings().find(PostProcessingWallsSettings.class) + .map(PostProcessingWallsSettings::enabled).orElse(PostProcessingWallsSettings.DEFAULT_ENABLED); + boolean slabs = dimension.getModuleSettings().find(PostProcessingSlabsSettings.class) + .map(PostProcessingSlabsSettings::enabled).orElse(PostProcessingSlabsSettings.DEFAULT_ENABLED); int fluidHeight = dimension.getFluidHeight(); for (int i = 0; i < width; i++) { for (int j = 0; j < depth; j++) { @@ -176,13 +184,14 @@ public class SurfaceSmoothing { IrisBiome biome = context.getBiome().get(currentPostX, currentPostZ); if (walls) { - if (!biome.getWall().getPalette().isEmpty()) { + ResolvedLayer wall = layers.wall(biome, engine.getData()); + if (wall.hasPalette()) { if (ha < h - 2 || hb < h - 2 || hc < h - 2 || hd < h - 2) { boolean brokeGround = false; int max = Math.abs(Math.max(h - ha, Math.max(h - hb, Math.max(h - hc, h - hd)))); for (int i = h; i > h - max; i--) { - PlatformBlockState d = biome.getWall().get(rng, x + i, i + h, z + i, engine.getData()); + PlatformBlockState d = wall.get(rng, x + i, i + h, z + i); if (d != null) { if (isAirOrWater(x, i, z, originX, originZ, currentData)) { @@ -210,8 +219,9 @@ public class SurfaceSmoothing { || (hd == h + 1 && isSolidNonSlab(x, hd, z - 1, originX, originZ, currentData))) //@done { - SlopeClip sc = biome.getSlab().getSlopeCondition(); - PlatformBlockState d = sc.isValid(engine.getComplex().getSlopeStream().get(x, z)) ? biome.getSlab().get(rng, x, h, z, engine.getData()) : null; + ResolvedLayer slab = layers.slab(biome, engine.getData()); + SlopeClip sc = slab.slopeCondition(); + PlatformBlockState d = sc.isValid(engine.getComplex().getSlopeStream().get(x, z)) ? slab.get(rng, x, h, z) : null; if (d != null) { boolean cancel = B.isAir(d); diff --git a/src/main/java/art/arcane/iris/engine/object/placement/VacuumModule.java b/src/main/java/art/arcane/iris/engine/object/placement/VacuumModule.java index e3c199da8..35d1b7cb6 100644 --- a/src/main/java/art/arcane/iris/engine/object/placement/VacuumModule.java +++ b/src/main/java/art/arcane/iris/engine/object/placement/VacuumModule.java @@ -24,9 +24,9 @@ import art.arcane.iris.builtin.vacuum.VacuumSettings; import art.arcane.iris.builtin.IrisStages; import art.arcane.iris.builtin.blocks.WrittenBlocks; import art.arcane.iris.core.modules.IrisPlacement; -import art.arcane.iris.engine.IrisComplex; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.prefab.IrisObject; +import art.arcane.iris.engine.terrain.TerrainPalettes; import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.util.common.data.B; import art.arcane.iris.util.project.noise.SimplexNoise; @@ -82,7 +82,7 @@ public final class VacuumModule implements IrisModule { private final IrisPlacement placement; private final PreparedPlacement prepared; private final PlacementWorld world; - private final IrisComplex complex; + private final TerrainPalettes palettes; private final int radius; private final int step; private final double falloff; @@ -98,7 +98,7 @@ public final class VacuumModule implements IrisModule { this.placement = IrisPlacement.current(); this.prepared = prepared; this.world = new PlacementWorld(context.access(), placement.states()); - this.complex = engine.getComplex(); + this.palettes = engine.getComplex() == null ? null : TerrainPalettes.of(engine); VacuumSettings settings = prepared.config().getVacuumSettings(); this.radius = IrisObjectVacuum.resolveRadius(vacuum, settings); this.step = vacuum.columnStepBlocks(); @@ -161,7 +161,7 @@ public final class VacuumModule implements IrisModule { } private void raise(int x, int z, int fromY, int toY) { - PlatformBlockState fill = complex != null ? complex.getRockStream().get(x, z) : null; + PlatformBlockState fill = palettes != null ? palettes.rockAt(x, z) : null; if (B.isAir(fill)) { fill = IrisObject.States.STONE; } diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomeLayerGenerator.java b/src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomeLayerGenerator.java deleted file mode 100644 index e9b04809a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomeLayerGenerator.java +++ /dev/null @@ -1,360 +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; - -import art.arcane.iris.builtin.prepare.SlopeClip; -import art.arcane.iris.engine.object.placement.IrisObjectPlacement; -import art.arcane.iris.engine.object.prefab.IrisObject; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.world.biome.IrisBiomeGeneratorLink; -import art.arcane.iris.engine.object.world.dimension.IrisDimension; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.IrisComplex; -import art.arcane.iris.engine.data.cache.AtomicCache; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.spi.IrisLogging; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.iris.util.common.data.B; -import art.arcane.iris.util.project.noise.CNG; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.RNG; - -/** - * Layer (block palette) generation for {@link IrisBiome}. IrisBiome is Gson deserialized from pack - * JSON, so its fields stay put and only the behavior lives here. - */ -public final class IrisBiomeLayerGenerator { - private static final class States { - private static final PlatformBlockState BARRIER = B.getState("BARRIER"); - } - - private IrisBiomeLayerGenerator() { - } - - public static KList generateLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) { - if (biome.isLockLayers()) { - return generateLockedLayers(biome, wx, wz, random, maxDepth, height, rdata, complex); - } - - KList data = new KList<>(); - - if (maxDepth <= 0) { - return data; - } - - KList layers = biome.getLayers(); - int layerCount = layers.size(); - - if (layerCount <= 0) { - return data; - } - - KList heightGenerators = getLayerHeightGenerators(biome, random, rdata); - - for (int i = 0; i < layerCount; i++) { - IrisBiomePaletteLayer layer = layers.get(i); - double zoom = layer.getZoom(); - CNG hgen = heightGenerators.get(i); - double d = hgen.fit(layer.getMinHeight(), layer.getMaxHeight(), wx / zoom, wz / zoom); - - SlopeClip sc = layer.getSlopeCondition(); - - if (!sc.isDefault()) { - if (!sc.isValid(complex.getSlopeStream().get(wx, wz))) { - d = 0; - } - } - - if (d <= 0) { - continue; - } - - for (int j = 0; j < d; j++) { - if (data.size() >= maxDepth) { - break; - } - - try { - data.add(layer.get(random, i + j, (wx + j) / zoom, j, (wz - j) / zoom, rdata)); - } catch (Throwable e) { - IrisLogging.reportError(e); - } - } - - if (data.size() >= maxDepth) { - break; - } - - if (dim.isExplodeBiomePalettes()) { - for (int j = 0; j < dim.getExplodeBiomePaletteSize(); j++) { - data.add(States.BARRIER); - - if (data.size() >= maxDepth) { - break; - } - } - } - } - - return data; - } - - public static KList generateCeilingLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) { - KList data = new KList<>(); - - if (maxDepth <= 0) { - return data; - } - - KList ceilingLayers = biome.getCaveCeilingLayers(); - int layerCount = ceilingLayers.size(); - - if (layerCount <= 0) { - return data; - } - - KList heightGenerators = getLayerHeightGenerators(biome, random, rdata); - // Ceiling layers reuse the surface-layer height generators, so entries beyond layers.size() have no generator; skip them. - int usableLayers = Math.min(layerCount, heightGenerators.size()); - - for (int i = 0; i < usableLayers; i++) { - IrisBiomePaletteLayer layer = ceilingLayers.get(i); - double zoom = layer.getZoom(); - CNG hgen = heightGenerators.get(i); - double d = hgen.fit(layer.getMinHeight(), layer.getMaxHeight(), wx / zoom, wz / zoom); - - if (d <= 0) { - continue; - } - - for (int j = 0; j < d; j++) { - if (data.size() >= maxDepth) { - break; - } - - try { - data.add(layer.get(random, i + j, (wx + j) / zoom, j, (wz - j) / zoom, rdata)); - } catch (Throwable e) { - IrisLogging.reportError(e); - } - } - - if (data.size() >= maxDepth) { - break; - } - - if (dim.isExplodeBiomePalettes()) { - for (int j = 0; j < dim.getExplodeBiomePaletteSize(); j++) { - data.add(States.BARRIER); - - if (data.size() >= maxDepth) { - break; - } - } - } - } - - return data; - } - - public static KList generateLockedLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepthf, int height, IrisData rdata, IrisComplex complex) { - KList data = new KList<>(); - KList real = new KList<>(); - int maxDepth = Math.min(maxDepthf, biome.getLockLayersMax()); - if (maxDepth <= 0) { - return data; - } - - KList layers = biome.getLayers(); - int layerCount = layers.size(); - - if (layerCount > 0) { - KList heightGenerators = getLayerHeightGenerators(biome, random, rdata); - - for (int i = 0; i < layerCount; i++) { - IrisBiomePaletteLayer layer = layers.get(i); - double zoom = layer.getZoom(); - CNG hgen = heightGenerators.get(i); - double d = hgen.fit(layer.getMinHeight(), layer.getMaxHeight(), wx / zoom, wz / zoom); - - SlopeClip sc = layer.getSlopeCondition(); - - if (!sc.isDefault()) { - if (!sc.isValid(complex.getSlopeStream().get(wx, wz))) { - d = 0; - } - } - - if (d <= 0) { - continue; - } - - for (int j = 0; j < d; j++) { - try { - data.add(layer.get(random, i + j, (wx + j) / zoom, j, (wz - j) / zoom, rdata)); - } catch (Throwable e) { - IrisLogging.reportError(e); - } - } - } - } - - if (data.isEmpty()) { - return real; - } - - for (int i = 0; i < maxDepth; i++) { - int offset = (512 - height) - i; - int index = offset % data.size(); - real.add(data.get(Math.max(index, 0))); - } - - return real; - } - - public static KList generateSeaLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepth, IrisData rdata) { - KList data = new KList<>(); - - KList seaLayers = biome.getSeaLayers(); - int layerCount = seaLayers.size(); - - if (layerCount <= 0) { - return data; - } - - KList heightGenerators = getLayerSeaHeightGenerators(biome, random, rdata); - - for (int i = 0; i < layerCount; i++) { - IrisBiomePaletteLayer layer = seaLayers.get(i); - double zoom = layer.getZoom(); - CNG hgen = heightGenerators.get(i); - int d = hgen.fit(layer.getMinHeight(), layer.getMaxHeight(), wx / zoom, wz / zoom); - - if (d < 0) { - continue; - } - - for (int j = 0; j < d; j++) { - if (data.size() >= maxDepth) { - break; - } - - try { - data.add(layer.get(random, i + j, (wx + j) / zoom, j, (wz - j) / zoom, rdata)); - } catch (Throwable e) { - IrisLogging.reportError(e); - } - } - - if (data.size() >= maxDepth) { - break; - } - } - - return data; - } - - public static KList getLayerHeightGenerators(IrisBiome biome, RNG rng, IrisData rdata) { - AtomicCache> cache = biome.getLayerHeightGenerators(); - KList cached = cache.getIfPresent(); - - if (cached != null) { - return cached; - } - - return cache.aquire(() -> - { - KList layerHeightGenerators = new KList<>(); - - int m = 7235; - - for (IrisBiomePaletteLayer i : biome.getLayers()) { - layerHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m), rdata)); - } - - return layerHeightGenerators; - }); - } - - public static KList getLayerSeaHeightGenerators(IrisBiome biome, RNG rng, IrisData data) { - AtomicCache> cache = biome.getLayerSeaHeightGenerators(); - KList cached = cache.getIfPresent(); - - if (cached != null) { - return cached; - } - - return cache.aquire(() -> - { - KList layerSeaHeightGenerators = new KList<>(); - - int m = 7735; - - for (IrisBiomePaletteLayer i : biome.getSeaLayers()) { - layerSeaHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m), data)); - } - - return layerSeaHeightGenerators; - }); - } - - public static PlatformBlockState getSurfaceBlock(IrisBiome biome, int x, int z, RNG rng, IrisData idm) { - KList layers = biome.getLayers(); - - if (layers.isEmpty()) { - return B.getState("AIR"); - } - - return layers.get(0).get(rng, x, 0, z, idm); - } - - public static int getMaxHeight(IrisBiome biome, Engine engine) { - return biome.getMaxHeight().aquire(() -> - { - int maxHeight = 0; - - for (IrisBiomeGeneratorLink i : biome.getGenerators()) { - maxHeight += i.getMax(); - } - - return maxHeight; - }); - } - - public static int getMaxWithObjectHeight(IrisBiome biome, IrisData data, Engine engine) { - return biome.getMaxWithObjectHeight().aquire(() -> - { - int maxHeight = 0; - - for (IrisBiomeGeneratorLink i : biome.getGenerators()) { - maxHeight += i.getMax(); - } - - int gg = 0; - - for (IrisObjectPlacement i : biome.getObjects()) { - for (IrisObject j : data.getObjectLoader().loadAll(i.getPlace())) { - gg = Math.max(gg, j.getH()); - } - } - - return maxHeight + gg + 3; - }); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomePaletteLayer.java b/src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomePaletteLayer.java deleted file mode 100644 index 1825e7863..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/IrisBiomePaletteLayer.java +++ /dev/null @@ -1,165 +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; - -import art.arcane.iris.builtin.prepare.SlopeClip; -import art.arcane.iris.engine.object.material.IrisBlockData; -import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; -import art.arcane.iris.engine.object.noise.NoiseStyle; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.data.cache.AtomicCache; -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.DependsOn; -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.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.RNG; -import art.arcane.iris.util.project.noise.CNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import art.arcane.iris.spi.PlatformBlockState; -import lombok.experimental.Accessors; - -@Snippet("biome-palette") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("A layer of surface / subsurface material in biomes") -@Data -public class IrisBiomePaletteLayer { - private final transient AtomicCache> blockData = new AtomicCache<>(); - private final transient AtomicCache layerGenerator = new AtomicCache<>(); - private final transient AtomicCache heightGenerator = new AtomicCache<>(); - @Desc("The style of noise") - private IrisGeneratorStyle style = NoiseStyle.STATIC.style(); - @DependsOn({"minHeight", "maxHeight"}) - @MinNumber(0) - @MaxNumber(2032) - - @Desc("The min thickness of this layer") - private int minHeight = 1; - @DependsOn({"minHeight", "maxHeight"}) - @MinNumber(1) - @MaxNumber(2032) - - @Desc("The max thickness of this layer") - private int maxHeight = 1; - @Desc("If set, this layer only shows where the terrain slope is within these bounds; outside them the layer is skipped entirely. Thickness is not scaled by slope.") - private SlopeClip slopeCondition = new SlopeClip(); - @MinNumber(0.0001) - @Desc("The terrain zoom mostly for zooming in on a wispy palette") - private double zoom = 5; - @Required - @ArrayType(min = 1, type = IrisBlockData.class) - @Desc("The palette of blocks to be used in this layer") - private KList palette = new KList().qadd(new IrisBlockData("GRASS_BLOCK")); - - public CNG getHeightGenerator(RNG rng, IrisData data) { - CNG cached = heightGenerator.getIfPresent(); - - if (cached != null) { - return cached; - } - - return heightGenerator.aquire(() -> CNG.signature(rng.nextParallelRNG(minHeight * maxHeight + getBlockData(data).size()))); - } - - public PlatformBlockState get(RNG rng, double x, double y, double z, IrisData data) { - return get(rng, 0, x, y, z, data); - } - - /** - * Resolves a block for this layer without allocating a child RNG per call. The child RNG is - * only built inside the lazy layer generator initializer, using the exact same seed derivation - * as {@code parent.nextParallelRNG(signature)} followed by the generator signature. - */ - public PlatformBlockState get(RNG parent, int signature, double x, double y, double z, IrisData data) { - KList localBlockData = getBlockData(data); - - if (localBlockData.isEmpty()) { - return null; - } - - if (localBlockData.size() == 1) { - return localBlockData.get(0); - } - - double localZoom = zoom; - double scaledX = x / localZoom; - double scaledY = y / localZoom; - double scaledZ = z / localZoom; - return getLayerGenerator(parent, signature, data).fit(localBlockData, scaledX, scaledY, scaledZ); - } - - public CNG getLayerGenerator(RNG rng, IrisData data) { - return getLayerGenerator(rng, 0, data); - } - - public CNG getLayerGenerator(RNG parent, int signature, IrisData data) { - CNG cached = layerGenerator.getIfPresent(); - - if (cached != null) { - return cached; - } - - return layerGenerator.aquire(() -> - { - RNG rngx = parent.nextParallelRNG(signature).nextParallelRNG(minHeight + maxHeight + getBlockData(data).size()); - return style.create(rngx, data); - }); - } - - public KList add(String b) { - palette.add(new IrisBlockData(b)); - - return palette; - } - - public KList getBlockData(IrisData data) { - KList cached = blockData.getIfPresent(); - - if (cached != null) { - return cached; - } - - return blockData.aquire(() -> - { - KList blockData = new KList<>(); - for (IrisBlockData ix : palette) { - PlatformBlockState bx = ix.getBlockData(data); - if (bx != null) { - for (int i = 0; i < ix.getWeight(); i++) { - blockData.add(bx); - } - } - } - - return blockData; - }); - } - - public IrisBiomePaletteLayer zero() { - palette.clear(); - return this; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java index 2be388ff5..aaca52db8 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java +++ b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java @@ -29,8 +29,6 @@ import art.arcane.iris.engine.object.noise.NoiseStyle; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.procedural.IrisProceduralObjects; import art.arcane.iris.engine.object.structure.IrisStructurePlacement; -import art.arcane.iris.engine.object.terrain.IrisBiomeLayerGenerator; -import art.arcane.iris.engine.object.terrain.IrisBiomePaletteLayer; import art.arcane.iris.engine.object.terrain.deposit.IrisBiomeOres; import art.arcane.iris.engine.object.terrain.deposit.IrisDepositVariant; import art.arcane.iris.engine.object.terrain.deposit.IrisOreGenerator; @@ -78,7 +76,7 @@ import java.util.Objects; * Represents a biome in a pack. This type is Gson deserialized straight out of user pack JSON, so * the field block and the transient {@link AtomicCache} block below are load bearing and must not * move. Behavior lives in the same-package companions: - * {@link IrisBiomeLayerGenerator}, {@link IrisBiomeDerivatives}, {@link IrisBiomeOres}, + * {@link IrisBiomeDerivatives}, {@link IrisBiomeOres}, * {@link IrisBiomeColorRenderer} and {@link IrisBiomeGenLinks}. */ @Accessors(chain = true) @@ -106,12 +104,8 @@ public class IrisBiome extends IrisRegistrant implements IRare { @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) private transient volatile SeededBiomeGenerator recentBiomeGenerator; - private final transient AtomicCache maxHeight = new AtomicCache<>(); - private final transient AtomicCache maxWithObjectHeight = new AtomicCache<>(); private final transient AtomicCache realCarveBiome = new AtomicCache<>(); private final transient AtomicCache> realChildren = new AtomicCache<>(); - private final transient AtomicCache> layerHeightGenerators = new AtomicCache<>(); - private final transient AtomicCache> layerSeaHeightGenerators = new AtomicCache<>(); private final transient AtomicCache> surfaceOreCache = new AtomicCache<>(); private final transient AtomicCache> undergroundOreCache = new AtomicCache<>(); private final transient AtomicCache surfaceOreBoundsCache = new AtomicCache<>(); @@ -142,10 +136,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { private KList blockDrops = new KList<>(); @Desc("Reference loot tables in this area") private IrisLootReference loot = new IrisLootReference(); - @Desc("Layers no longer descend from the surface block, they descend from the max possible height the biome can produce (constant) creating mesa like layers.") - private boolean lockLayers = false; - @Desc("The max layers to iterate below the surface for locked layer biomes (mesa).") - private int lockLayersMax = 7; @Desc("Profile-driven 3D cave configuration") private CaveProfile caveProfile = new CaveProfile(); @MinNumber(1) @@ -187,20 +177,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { @MaxNumber(256) @Desc("Minimum depth below terrain surface required before this cave biome can be selected.") private int caveMinDepthBelowSurface = 0; - @Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.") - private IrisBiomePaletteLayer slab = new IrisBiomePaletteLayer().zero(); - @Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)") - private IrisBiomePaletteLayer wall = new IrisBiomePaletteLayer().zero(); - @Required - @ArrayType(type = IrisBiomePaletteLayer.class) - @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") - private KList layers = new KList().qadd(new IrisBiomePaletteLayer()); - @ArrayType(type = IrisBiomePaletteLayer.class) - @Desc("Layers of materials placed on cave ceilings in this biome, indexed upward from the ceiling surface. Must not have more entries than layers, whose height generators it reuses. Omitting this leaves cave ceilings unchanged.") - private KList caveCeilingLayers = new KList<>(); - @ArrayType(type = IrisBiomePaletteLayer.class) - @Desc("Layers of materials filling the water column of sea biomes, indexed downward from the water surface. Anything below the last layer is filled with the dimension fluid palette, not stone.") - private KList seaLayers = new KList<>(); @ArrayType(min = 1, type = IrisObjectPlacement.class) @Desc("Objects define what schematics (iob files) iris will place in this biome") private KList objects = new KList<>(); @@ -292,6 +268,7 @@ public class IrisBiome extends IrisRegistrant implements IRare { variant.setLoader(data); variant.setLoadKey(getLoadKey()); variant.setLoadFile(getLoadFile()); + variant.setModuleSettings(getModuleSettings()); variant.inferredType = type; inferredVariants.put(type, variant); return variant; @@ -483,46 +460,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { return childrenCell.aquire(() -> getChildStyle().create(random.nextParallelRNG(sig * 2137), getLoader()).bake().scale(scale).bake()); } - public KList generateLayers(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) { - return IrisBiomeLayerGenerator.generateLayers(this, dim, wx, wz, random, maxDepth, height, rdata, complex); - } - - public KList generateCeilingLayers(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) { - return IrisBiomeLayerGenerator.generateCeilingLayers(this, dim, wx, wz, random, maxDepth, height, rdata, complex); - } - - public KList generateLockedLayers(double wx, double wz, RNG random, int maxDepthf, int height, IrisData rdata, IrisComplex complex) { - return IrisBiomeLayerGenerator.generateLockedLayers(this, wx, wz, random, maxDepthf, height, rdata, complex); - } - - public KList generateSeaLayers(double wx, double wz, RNG random, int maxDepth, IrisData rdata) { - return IrisBiomeLayerGenerator.generateSeaLayers(this, wx, wz, random, maxDepth, rdata); - } - - /** - * Note the arity split: {@code getMaxHeight()} is the Lombok getter for the height cache field, - * {@code getMaxHeight(Engine)} is the resolved biome height. - */ - public int getMaxHeight(Engine engine) { - return IrisBiomeLayerGenerator.getMaxHeight(this, engine); - } - - public int getMaxWithObjectHeight(IrisData data, Engine engine) { - return IrisBiomeLayerGenerator.getMaxWithObjectHeight(this, data, engine); - } - - public KList getLayerHeightGenerators(RNG rng, IrisData rdata) { - return IrisBiomeLayerGenerator.getLayerHeightGenerators(this, rng, rdata); - } - - public KList getLayerSeaHeightGenerators(RNG rng, IrisData data) { - return IrisBiomeLayerGenerator.getLayerSeaHeightGenerators(this, rng, data); - } - - public PlatformBlockState getSurfaceBlock(int x, int z, RNG rng, IrisData idm) { - return IrisBiomeLayerGenerator.getSurfaceBlock(this, x, z, rng, idm); - } - public boolean isLand() { if (inferredType == null) { return true; diff --git a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiomeColorRenderer.java b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiomeColorRenderer.java index 44e9ce0fe..e99ff02aa 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiomeColorRenderer.java +++ b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiomeColorRenderer.java @@ -19,6 +19,7 @@ package art.arcane.iris.engine.object.world.biome; import art.arcane.iris.engine.decorator.BiomeDecorators; +import art.arcane.iris.engine.terrain.BiomeLayers; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.render.RenderType; @@ -81,7 +82,10 @@ final class IrisBiomeColorRenderer { }); } case LAYER_LOAD -> { - return biome.getCacheColorLayerLoad().aquire(() -> Color.getHSBColor(0.625f, (float) (biome.getLayers().size() / engine.getMaxBiomeLayerDensity()), 1f)); + return biome.getCacheColorLayerLoad().aquire(() -> { + BiomeLayers layers = BiomeLayers.of(engine); + return Color.getHSBColor(0.625f, (float) (BiomeLayers.layersOf(biome).size() / layers.busiestLayerCount(engine)), 1f); + }); } } diff --git a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java index 8f37e4768..591b46744 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java +++ b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java @@ -27,7 +27,6 @@ import art.arcane.iris.engine.object.image.IrisImageMapApplication; import art.arcane.iris.engine.object.image.IrisImageMapBinding; import art.arcane.iris.engine.object.loot.IrisBlockDrops; import art.arcane.iris.engine.object.loot.IrisLootReference; -import art.arcane.iris.engine.object.material.IrisMaterialPalette; import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; import art.arcane.iris.engine.object.noise.IrisShapedGeneratorStyle; import art.arcane.iris.engine.object.noise.NoiseStyle; @@ -178,12 +177,6 @@ public class IrisDimension extends IrisRegistrant { private boolean decorate = true; @Desc("When true, every ore block the generator would place (terrain ores, deposits, ores inside objects) is replaced with its base material such as stone, deepslate or netherrack, so drop-control plugins like HiddenOre can manage ore rewards themselves") private boolean hideOresForHiddenOre = false; - @Desc("Use post processing or not") - private boolean postProcessing = true; - @Desc("Add slabs in post processing") - private boolean postProcessingSlabs = true; - @Desc("Add painted walls in post processing") - private boolean postProcessingWalls = true; @Desc("Enable or disable all carving for this dimension") private boolean carvingEnabled = true; @ArrayType(type = IrisDimensionCarvingEntry.class, min = 1) @@ -281,10 +274,6 @@ public class IrisDimension extends IrisRegistrant { @ArrayType(min = 1, type = IrisShapedGeneratorStyle.class) @Desc("Overlay additional noise on top of the interoplated terrain.") private KList overlayNoise = new KList<>(); - @Desc("The palette of blocks for 'stone'") - private IrisMaterialPalette rockPalette = new IrisMaterialPalette().qclear().qadd("stone"); - @Desc("The dimension fluid block palette used for ocean columns and cave aquifers.") - private IrisMaterialPalette fluidPalette = new IrisMaterialPalette().qclear().qadd("water"); @Desc("Collection of ores to be generated") @ArrayType(type = IrisOreGenerator.class, min = 1) private KList ores = new KList<>(); diff --git a/src/main/java/art/arcane/iris/engine/terrain/BiomeLayers.java b/src/main/java/art/arcane/iris/engine/terrain/BiomeLayers.java new file mode 100644 index 000000000..7d38a6ca4 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/terrain/BiomeLayers.java @@ -0,0 +1,344 @@ +/* + * 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.terrain; + +import art.arcane.iris.builtin.prepare.SlopeClip; +import art.arcane.iris.builtin.terrain.CaveCeilingLayersSettings; +import art.arcane.iris.builtin.terrain.LayersSettings; +import art.arcane.iris.builtin.terrain.LockLayersMaxSettings; +import art.arcane.iris.builtin.terrain.LockLayersSettings; +import art.arcane.iris.builtin.terrain.PaletteLayer; +import art.arcane.iris.builtin.terrain.SeaLayersSettings; +import art.arcane.iris.builtin.terrain.SlabSettings; +import art.arcane.iris.builtin.terrain.WallSettings; +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.core.modules.IrisValues; +import art.arcane.iris.engine.IrisComplex; +import art.arcane.iris.engine.data.cache.AtomicCache; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.noise.NoiseStyle; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import art.arcane.iris.engine.object.world.dimension.IrisDimension; +import art.arcane.iris.spi.IrisLogging; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import art.arcane.iris.util.project.noise.CNG; +import art.arcane.volmlib.util.collection.KList; +import art.arcane.volmlib.util.math.RNG; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * What the terrain module keeps for one world about the layers of its biomes: each layer made ready ({@link ResolvedLayer}) + * and the noise that sets the thickness of a biome's layers, and the blocks the layers of a biome stack up to at a column. + * A biome's layers are its {@link LayersSettings}, {@link SeaLayersSettings} and {@link CaveCeilingLayersSettings}; a biome + * that declares no layers has the one layer of grass the settings default to. + * + *

The noise of a biome's layers is built once, from the random of the first column asked for, as it always was. + */ +public final class BiomeLayers { + private static final int SURFACE_HEIGHT_SEED = 7235; + private static final int SEA_HEIGHT_SEED = 7735; + private static final int LOCKED_LAYERS_REFERENCE_HEIGHT = 512; + private static final LayersSettings DEFAULT_LAYERS = new LayersSettings(); + private static final PaletteLayer NO_LAYER = PaletteLayer.withoutBlocks(); + + private static final class States { + private static final PlatformBlockState BARRIER = B.getState("BARRIER"); + } + + private final Map resolved = new ConcurrentHashMap<>(); + private final Map>> surfaceHeights = new ConcurrentHashMap<>(); + private final Map>> seaHeights = new ConcurrentHashMap<>(); + private volatile Double busiestBiomeLayerCount; + + /** The layers of the world {@code engine} generates now. */ + public static BiomeLayers of(Engine engine) { + return engine.getGeneration().state(BiomeLayers.class, ignored -> new BiomeLayers()); + } + + /** {@code layer} ready for the pack of {@code data}; the pack of the first caller is the one kept. */ + public ResolvedLayer resolve(PaletteLayer layer, IrisData data) { + return resolved.computeIfAbsent(layer, declared -> ResolvedLayer.of(declared, data)); + } + + /** The biome's slab, which places no block when the biome declares none. */ + public ResolvedLayer slab(IrisBiome biome, IrisData data) { + PaletteLayer layer = biome.getModuleSettings().find(SlabSettings.class).map(SlabSettings::layer).orElse(NO_LAYER); + return resolve(layer, data); + } + + /** The biome's wall, which places no block when the biome declares none. */ + public ResolvedLayer wall(IrisBiome biome, IrisData data) { + PaletteLayer layer = biome.getModuleSettings().find(WallSettings.class).map(WallSettings::layer).orElse(NO_LAYER); + return resolve(layer, data); + } + + /** The layers of the biome's surface, top first. */ + public static List layersOf(IrisBiome biome) { + return surfaceSettings(biome).layers(); + } + + /** The noise style of each layer of the biome's surface, top first, as Iris's generators know them. */ + public static List layerStyles(IrisBiome biome) { + return layersOf(biome).stream().map(layer -> IrisValues.generatorStyle(layer.style()).getStyle()).toList(); + } + + /** The most layers any biome the dimension reaches has, which is what studio's layer load view compares a biome with. */ + public double busiestLayerCount(Engine engine) { + Double cached = busiestBiomeLayerCount; + if (cached != null) { + return cached; + } + + double busiest = 0D; + for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) { + busiest = Math.max(busiest, layersOf(biome).size()); + } + busiestBiomeLayerCount = busiest; + return busiest; + } + + /** The blocks the biome's layers stack up to at the column, top first, at most {@code maxDepth} of them. */ + public KList generateLayers(IrisBiome biome, IrisDimension dimension, double wx, double wz, RNG random, int maxDepth, int height, IrisData data, IrisComplex complex) { + if (isLocked(biome)) { + return generateLockedLayers(biome, wx, wz, random, maxDepth, height, data, complex); + } + + KList blocks = new KList<>(); + if (maxDepth <= 0) { + return blocks; + } + + LayersSettings settings = surfaceSettings(biome); + List layers = settings.layers(); + if (layers.isEmpty()) { + return blocks; + } + + KList heightNoises = surfaceHeightNoises(settings, random, data); + for (int i = 0; i < layers.size(); i++) { + ResolvedLayer layer = resolve(layers.get(i), data); + double depth = layerDepth(layer, heightNoises.get(i), wx, wz, complex); + if (depth <= 0) { + continue; + } + + stackLayer(blocks, layer, i, depth, wx, wz, random, maxDepth); + if (blocks.size() >= maxDepth) { + break; + } + + separateLayers(blocks, dimension, maxDepth); + } + + return blocks; + } + + /** The blocks the biome's cave ceiling layers stack up to at the column, nearest the ceiling first, at most {@code maxDepth} of them. */ + public KList generateCeilingLayers(IrisBiome biome, IrisDimension dimension, double wx, double wz, RNG random, int maxDepth, int height, IrisData data, IrisComplex complex) { + KList blocks = new KList<>(); + if (maxDepth <= 0) { + return blocks; + } + + List ceilingLayers = biome.getModuleSettings().find(CaveCeilingLayersSettings.class) + .map(CaveCeilingLayersSettings::layers).orElse(List.of()); + if (ceilingLayers.isEmpty()) { + return blocks; + } + + KList heightNoises = surfaceHeightNoises(surfaceSettings(biome), random, data); + // Ceiling layers reuse the surface-layer height noise, so entries beyond the surface layers have none; skip them. + int usableLayers = Math.min(ceilingLayers.size(), heightNoises.size()); + for (int i = 0; i < usableLayers; i++) { + ResolvedLayer layer = resolve(ceilingLayers.get(i), data); + double depth = layerThickness(layer, heightNoises.get(i), wx, wz); + if (depth <= 0) { + continue; + } + + stackLayer(blocks, layer, i, depth, wx, wz, random, maxDepth); + if (blocks.size() >= maxDepth) { + break; + } + + separateLayers(blocks, dimension, maxDepth); + } + + return blocks; + } + + /** The blocks of the biome's sea layers at the column, from the water surface down, at most {@code maxDepth} of them. */ + public KList generateSeaLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepth, IrisData data) { + KList blocks = new KList<>(); + SeaLayersSettings settings = biome.getModuleSettings().find(SeaLayersSettings.class).orElse(null); + if (settings == null || settings.layers().isEmpty()) { + return blocks; + } + + List layers = settings.layers(); + KList heightNoises = seaHeightNoises(settings, random, data); + for (int i = 0; i < layers.size(); i++) { + ResolvedLayer layer = resolve(layers.get(i), data); + int depth = heightNoises.get(i).fit(layer.minHeight(), layer.maxHeight(), wx / layer.zoom(), wz / layer.zoom()); + if (depth < 0) { + continue; + } + + stackLayer(blocks, layer, i, depth, wx, wz, random, maxDepth); + if (blocks.size() >= maxDepth) { + break; + } + } + + return blocks; + } + + private KList generateLockedLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepthLimit, int height, IrisData data, IrisComplex complex) { + KList stacked = new KList<>(); + KList locked = new KList<>(); + int maxDepth = Math.min(maxDepthLimit, lockedLayersMax(biome)); + if (maxDepth <= 0) { + return stacked; + } + + LayersSettings settings = surfaceSettings(biome); + List layers = settings.layers(); + if (!layers.isEmpty()) { + KList heightNoises = surfaceHeightNoises(settings, random, data); + for (int i = 0; i < layers.size(); i++) { + ResolvedLayer layer = resolve(layers.get(i), data); + double depth = layerDepth(layer, heightNoises.get(i), wx, wz, complex); + if (depth <= 0) { + continue; + } + + stackLayerUnlimited(stacked, layer, i, depth, wx, wz, random); + } + } + + if (stacked.isEmpty()) { + return locked; + } + + for (int i = 0; i < maxDepth; i++) { + int offset = (LOCKED_LAYERS_REFERENCE_HEIGHT - height) - i; + locked.add(stacked.get(Math.max(offset % stacked.size(), 0))); + } + + return locked; + } + + private void stackLayer(KList blocks, ResolvedLayer layer, int index, double depth, double wx, double wz, RNG random, int maxDepth) { + for (int j = 0; j < depth; j++) { + if (blocks.size() >= maxDepth) { + break; + } + + addBlock(blocks, layer, index, j, wx, wz, random); + } + } + + private void stackLayerUnlimited(KList blocks, ResolvedLayer layer, int index, double depth, double wx, double wz, RNG random) { + for (int j = 0; j < depth; j++) { + addBlock(blocks, layer, index, j, wx, wz, random); + } + } + + /** Adds the layer's block {@code j} blocks down; a layer that fails to pick adds nothing. */ + private void addBlock(KList blocks, ResolvedLayer layer, int index, int j, double wx, double wz, RNG random) { + double zoom = layer.zoom(); + try { + blocks.add(layer.get(random, index + j, (wx + j) / zoom, j, (wz - j) / zoom)); + } catch (Throwable e) { + IrisLogging.reportError(e); + } + } + + /** The barrier blocks a dimension puts between layers to show them apart. */ + private void separateLayers(KList blocks, IrisDimension dimension, int maxDepth) { + if (!dimension.isExplodeBiomePalettes()) { + return; + } + + for (int j = 0; j < dimension.getExplodeBiomePaletteSize(); j++) { + blocks.add(States.BARRIER); + if (blocks.size() >= maxDepth) { + break; + } + } + } + + /** How thick the layer is at the column: nothing where the slope is outside the layer's limits. */ + private double layerDepth(ResolvedLayer layer, CNG heightNoise, double wx, double wz, IrisComplex complex) { + double depth = layerThickness(layer, heightNoise, wx, wz); + SlopeClip slope = layer.slopeCondition(); + if (!slope.isDefault() && !slope.isValid(complex.getSlopeStream().get(wx, wz))) { + return 0; + } + + return depth; + } + + private double layerThickness(ResolvedLayer layer, CNG heightNoise, double wx, double wz) { + double zoom = layer.zoom(); + return heightNoise.fit(layer.minHeight(), layer.maxHeight(), wx / zoom, wz / zoom); + } + + private KList surfaceHeightNoises(LayersSettings settings, RNG rng, IrisData data) { + AtomicCache> cache = surfaceHeights.computeIfAbsent(settings, declared -> new AtomicCache<>()); + return heightNoises(cache, settings.layers(), SURFACE_HEIGHT_SEED, rng, data); + } + + private KList seaHeightNoises(SeaLayersSettings settings, RNG rng, IrisData data) { + AtomicCache> cache = seaHeights.computeIfAbsent(settings, declared -> new AtomicCache<>()); + return heightNoises(cache, settings.layers(), SEA_HEIGHT_SEED, rng, data); + } + + private KList heightNoises(AtomicCache> cache, List layers, int firstSeed, RNG rng, IrisData data) { + KList cached = cache.getIfPresent(); + if (cached != null) { + return cached; + } + + return cache.aquire(() -> { + KList noises = new KList<>(); + int seed = firstSeed; + for (PaletteLayer layer : layers) { + noises.add(resolve(layer, data).heightNoise(rng.nextParallelRNG((seed++) * seed * seed * seed))); + } + return noises; + }); + } + + private static LayersSettings surfaceSettings(IrisBiome biome) { + return biome.getModuleSettings().find(LayersSettings.class).orElse(DEFAULT_LAYERS); + } + + private static boolean isLocked(IrisBiome biome) { + return biome.getModuleSettings().find(LockLayersSettings.class).map(LockLayersSettings::locked).orElse(false); + } + + private static int lockedLayersMax(IrisBiome biome) { + return biome.getModuleSettings().find(LockLayersMaxSettings.class).map(LockLayersMaxSettings::layers).orElse(LockLayersMaxSettings.DEFAULT_LAYERS); + } +} diff --git a/src/main/java/art/arcane/iris/engine/terrain/PaletteBlocks.java b/src/main/java/art/arcane/iris/engine/terrain/PaletteBlocks.java new file mode 100644 index 000000000..3cedf3006 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/terrain/PaletteBlocks.java @@ -0,0 +1,48 @@ +/* + * 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.terrain; + +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.common.data.B; +import com.volmit.block.BlockRegistry; +import com.volmit.block.BlockSpec; + +import java.util.ArrayList; +import java.util.List; + +/** A palette's blocks as the platform's, the way terrain layers and palettes always picked from them. */ +final class PaletteBlocks { + private PaletteBlocks() { + } + + /** The platform's block of each spec that has one, each repeated by its weight. */ + static List weighted(BlockRegistry registry, List palette) { + List weighted = new ArrayList<>(); + for (BlockSpec spec : palette) { + PlatformBlockState state = B.getState(registry.resolve(spec).key()); + if (state == null) { + continue; + } + for (int n = 0; n < spec.weight(); n++) { + weighted.add(state); + } + } + return List.copyOf(weighted); + } +} diff --git a/src/main/java/art/arcane/iris/engine/terrain/ResolvedLayer.java b/src/main/java/art/arcane/iris/engine/terrain/ResolvedLayer.java new file mode 100644 index 000000000..94d8fd5ef --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/terrain/ResolvedLayer.java @@ -0,0 +1,139 @@ +/* + * 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.terrain; + +import art.arcane.iris.builtin.prepare.SlopeClip; +import art.arcane.iris.builtin.terrain.PaletteLayer; +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.core.modules.IrisPackResources; +import art.arcane.iris.engine.data.cache.AtomicCache; +import art.arcane.iris.spi.IrisLogging; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.iris.util.project.noise.CNG; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.noise.NoiseFactory; +import com.volmit.noise.NoiseSampler; + +import java.util.List; + +/** + * One {@link PaletteLayer} made ready for one pack: its palette resolved to the platform's blocks, and the noise that + * decides how thick it is here and which block of the palette it picks, built when first asked for. What the layer + * describes stays in the settings; everything that needs the platform, the pack or a seed is here. + * + *

Both noises are built once, from the random of whoever asks first, as the layers of a biome always were: a layer's + * noise is a function of that random, the signature it was first asked with and the layer's own size. + */ +public final class ResolvedLayer { + private final PaletteLayer settings; + private final IrisPackResources resources; + private final AtomicCache> blocks = new AtomicCache<>(); + private final AtomicCache blockNoise = new AtomicCache<>(); + private final AtomicCache heightNoise = new AtomicCache<>(); + + private ResolvedLayer(PaletteLayer settings, IrisPackResources resources) { + this.settings = settings; + this.resources = resources; + } + + /** {@code settings} ready for the blocks and noise of the pack of {@code data}. */ + static ResolvedLayer of(PaletteLayer settings, IrisData data) { + return new ResolvedLayer(settings, data.getPackResources()); + } + + public PaletteLayer settings() { + return settings; + } + + public int minHeight() { + return settings.minHeight(); + } + + public int maxHeight() { + return settings.maxHeight(); + } + + public double zoom() { + return settings.zoom(); + } + + public SlopeClip slopeCondition() { + return settings.slopeCondition(); + } + + /** Whether the layer lists any block, which is not the same as picking one: a listed block may have no weight. */ + public boolean hasPalette() { + return !settings.palette().isEmpty(); + } + + /** The noise that sets the layer's thickness, built from {@code rng} unless an earlier caller's is already kept. */ + public CNG heightNoise(RNG rng) { + CNG cached = heightNoise.getIfPresent(); + if (cached != null) { + return cached; + } + + return heightNoise.aquire(() -> CNG.signature(rng.nextParallelRNG(settings.minHeight() * settings.maxHeight() + blocks().size()))); + } + + /** The layer's block at the position, picked with the noise seeded from {@code parent} and {@code signature}, or null when the palette has no block. */ + public PlatformBlockState get(RNG parent, int signature, double x, double y, double z) { + List palette = blocks(); + if (palette.isEmpty()) { + return null; + } + if (palette.size() == 1) { + return palette.get(0); + } + + double zoom = settings.zoom(); + double noise = blockNoise(parent, signature, palette.size()).sample(x / zoom, y / zoom, z / zoom); + try { + return palette.get((int) Math.round(noise * (palette.size() - 1))); + } catch (IndexOutOfBoundsException outOfRange) { + IrisLogging.reportError(outOfRange); + return palette.get(0); + } + } + + /** {@link #get(RNG, int, double, double, double)} for a layer asked once per column, such as a slab or a wall. */ + public PlatformBlockState get(RNG rng, double x, double y, double z) { + return get(rng, 0, x, y, z); + } + + private List blocks() { + List cached = blocks.getIfPresent(); + if (cached != null) { + return cached; + } + + return blocks.aquire(() -> PaletteBlocks.weighted(resources.blocks(), settings.palette())); + } + + private NoiseSampler blockNoise(RNG parent, int signature, int paletteSize) { + NoiseSampler cached = blockNoise.getIfPresent(); + if (cached != null) { + return cached; + } + + NoiseFactory noise = resources.noise(); + long seed = parent.nextParallelRNG(signature).nextParallelRNG(settings.minHeight() + settings.maxHeight() + paletteSize).getSeed(); + return blockNoise.aquireOrThrow(() -> noise.sampler(settings.style(), seed)); + } +} diff --git a/src/main/java/art/arcane/iris/engine/terrain/TerrainPalettes.java b/src/main/java/art/arcane/iris/engine/terrain/TerrainPalettes.java new file mode 100644 index 000000000..2046a38c6 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/terrain/TerrainPalettes.java @@ -0,0 +1,137 @@ +/* + * 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.terrain; + +import art.arcane.iris.builtin.terrain.FluidPaletteSettings; +import art.arcane.iris.builtin.terrain.RockPaletteSettings; +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.core.modules.IrisPackResources; +import art.arcane.iris.engine.UpperDimensionContext; +import art.arcane.iris.engine.data.cache.AtomicCache; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.world.dimension.IrisDimension; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.block.PaletteSpec; +import com.volmit.noise.NoiseSampler; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * What the terrain module keeps for one world about the palettes that fill its terrain: the rock below the biomes' layers + * and the fluid of its oceans and aquifers, as a block for every column, and the rock of an upper dimension. They are the + * dimension's {@link RockPaletteSettings} and {@link FluidPaletteSettings}. + * + *

The noise of a palette is seeded from the world's complex seed and a signature of its own, as the complex always did, so + * a column's rock and fluid do not depend on who asks first. + */ +public final class TerrainPalettes { + private static final int ROCK_SIGNATURE = 45; + private static final int FLUID_SIGNATURE = 78; + /** The salt Iris's material palettes always added to the seed of the noise that picks their blocks. */ + private static final int PALETTE_NOISE_SALT = -23_498_896; + + /** A block for every column. */ + @FunctionalInterface + public interface ColumnBlocks { + /** The block at the column, or null when the palette has no block. */ + PlatformBlockState at(double x, double z); + } + + private final Engine engine; + private final AtomicCache rock = new AtomicCache<>(); + private final AtomicCache fluid = new AtomicCache<>(); + private final Map upperRocks = new ConcurrentHashMap<>(); + + TerrainPalettes(Engine engine) { + this.engine = engine; + } + + /** The palettes of the world {@code engine} generates now. */ + public static TerrainPalettes of(Engine engine) { + return engine.getGeneration().state(TerrainPalettes.class, TerrainPalettes::new); + } + + /** Builds the rock and fluid noise now instead of when first asked for. */ + public void warm() { + rock(); + fluid(); + } + + /** The rock at the column, below the biome's layers. */ + public PlatformBlockState rockAt(double x, double z) { + return rock().at(x, z); + } + + /** The fluid at the column, above the terrain up to the fluid height. */ + public PlatformBlockState fluidAt(double x, double z) { + return fluid().at(x, z); + } + + /** The rock at the column of the upper dimension: the world's own when the upper dimension is the dimension itself. */ + public PlatformBlockState upperRockAt(UpperDimensionContext upper, double x, double z) { + return upperRocks.computeIfAbsent(upper, this::upperRock).at(x, z); + } + + private ColumnBlocks rock() { + return rock.aquireOrThrow(() -> columns(rockPalette(engine.getDimension()), complexRng().nextParallelRNG(ROCK_SIGNATURE), engine.getData())); + } + + private ColumnBlocks fluid() { + return fluid.aquireOrThrow(() -> columns(fluidPalette(engine.getDimension()), complexRng().nextParallelRNG(FLUID_SIGNATURE), engine.getData())); + } + + private RNG complexRng() { + return new RNG(engine.getSeedManager().getComplex()); + } + + private ColumnBlocks upperRock(UpperDimensionContext upper) { + if (upper.isSelfReferencing()) { + return rock(); + } + + long seedOffset = upper.getDimension().getLoadKey().hashCode(); + RNG rng = new RNG(engine.getSeedManager().getComplex() ^ seedOffset); + return columns(rockPalette(upper.getDimension()), rng.nextParallelRNG(ROCK_SIGNATURE), upper.getData()); + } + + private static PaletteSpec rockPalette(IrisDimension dimension) { + return dimension.getModuleSettings().find(RockPaletteSettings.class).orElseGet(RockPaletteSettings::new).palette(); + } + + private static PaletteSpec fluidPalette(IrisDimension dimension) { + return dimension.getModuleSettings().find(FluidPaletteSettings.class).orElseGet(FluidPaletteSettings::new).palette(); + } + + /** The palette's blocks over the columns, picked by its noise: the noise at a column, from 0 to 1, is how far down the weighted list the block is. */ + private static ColumnBlocks columns(PaletteSpec palette, RNG rng, IrisData data) { + IrisPackResources resources = data.getPackResources(); + List blocks = PaletteBlocks.weighted(resources.blocks(), palette.palette()); + if (blocks.isEmpty()) { + return (x, z) -> null; + } + + long seed = rng.getSeed() + (PALETTE_NOISE_SALT + blocks.size()); + NoiseSampler noise = resources.noise().sampler(palette.style(), seed); + int last = blocks.size() - 1; + return (x, z) -> blocks.get((int) Math.round(noise.sample(x, z) * last)); + } +} From df88a4a0509a415225c0408385000ef9d70a07ea Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:46:32 +0200 Subject: [PATCH 3/7] Loot, block drops, entity spawners and effects become settings of iris:loot and iris:spawn; their classes become module types of IrisApi annotations --- .../arcane/iris/builtin/loot/BlockDrop.java | 73 +++++ .../iris/builtin/loot/BlockDropSettings.java | 48 +++ .../loot/ItemAttributeModifier.java} | 56 ++-- .../loot/LootEnchantment.java} | 55 ++-- .../arcane/iris/builtin/loot/LootEntry.java | 181 +++++++++++ .../loot/LootMode.java} | 10 +- .../iris/builtin/loot/LootSettings.java | 72 +++++ .../loot/LootSlot.java} | 10 +- .../loot/LootTable.java} | 68 +++-- .../iris/builtin/spawn/AmbientEffect.java | 247 +++++++++++++++ .../iris/builtin/spawn/EffectCommands.java | 100 ++++++ .../iris/builtin/spawn/EffectSettings.java | 47 +++ .../spawn/EntityDefinition.java} | 212 ++++++++++--- .../iris/builtin/spawn/EntitySpawn.java | 66 ++++ .../spawn/SpawnCommand.java} | 68 +++-- .../spawn/SpawnDuration.java} | 44 +-- .../spawn/SpawnGroup.java} | 10 +- .../spawn/SpawnMarker.java} | 60 ++-- .../spawn/SpawnRate.java} | 39 +-- .../spawn/SpawnSurface.java} | 12 +- .../spawn/SpawnTimeBlock.java} | 25 +- .../spawn/SpawnWeather.java} | 20 +- .../arcane/iris/builtin/spawn/Spawner.java | 98 ++++++ .../iris/builtin/spawn/SpawnerSettings.java | 49 +++ .../iris/engine/loot/BlockDropping.java | 59 +++- .../arcane/iris/engine/loot/LootGiving.java | 62 ++-- .../arcane/iris/engine/loot/LootItems.java | 83 ++--- .../arcane/iris/engine/loot/LootModule.java | 11 +- .../iris/engine/loot/LootResources.java | 19 +- .../arcane/iris/engine/loot/LootTables.java | 102 +++---- .../iris/engine/loot/LootValidator.java | 20 +- .../iris/engine/loot/PlacementLoot.java | 153 ++++++++++ .../iris/engine/loot/ResolvedBlockDrop.java | 72 +++++ .../annotations/RegistryListResource.java | 5 +- .../iris/engine/object/entity/IrisEffect.java | 288 ------------------ .../engine/object/entity/IrisEntitySpawn.java | 66 ---- .../object/entity/IrisPotionEffect.java | 102 ------- .../object/entity/PotionEffectTypes.java | 98 ------ .../spawn/IrisEngineSpawnerCooldown.java | 8 +- .../object/entity/spawn/IrisSpawner.java | 142 --------- .../entity/spawn/IrisSpawnerCooldowns.java | 9 +- .../engine/object/loot/IrisBlockDrops.java | 105 ------- .../iris/engine/object/loot/IrisLoot.java | 113 ------- .../engine/object/loot/IrisLootReference.java | 69 ----- .../engine/object/loot/IrisObjectLoot.java | 3 +- .../object/loot/IrisVanillaLootTable.java | 73 ----- .../object/marker/IrisCommandRegistry.java | 94 ------ .../object/marker/IrisObjectMarker.java | 3 +- .../engine/object/placement/BlocksModule.java | 6 +- .../object/placement/IrisObjectPlacement.java | 143 --------- .../object/structure/IrisStructure.java | 4 +- .../engine/object/world/biome/IrisBiome.java | 16 - .../object/world/dimension/IrisDimension.java | 12 - .../object/world/region/IrisRegion.java | 16 - .../iris/engine/spawn/AmbientEffecting.java | 135 ++++++++ .../iris/engine/spawn/EffectTimers.java | 40 +++ .../iris/engine/spawn/EntityResolution.java | 82 ++--- .../iris/engine/spawn/EntitySpawning.java | 114 ++++--- .../iris/engine/spawn/SpawnConditions.java | 42 +++ .../arcane/iris/engine/spawn/SpawnModule.java | 14 +- .../iris/engine/spawn/SpawnResources.java | 32 +- .../arcane/iris/engine/spawn/SpawnerGate.java | 97 ++++++ 62 files changed, 2278 insertions(+), 1904 deletions(-) create mode 100644 src/main/java/art/arcane/iris/builtin/loot/BlockDrop.java create mode 100644 src/main/java/art/arcane/iris/builtin/loot/BlockDropSettings.java rename src/main/java/art/arcane/iris/{engine/object/entity/IrisAttributeModifier.java => builtin/loot/ItemAttributeModifier.java} (74%) rename src/main/java/art/arcane/iris/{engine/object/loot/IrisEnchantment.java => builtin/loot/LootEnchantment.java} (52%) create mode 100644 src/main/java/art/arcane/iris/builtin/loot/LootEntry.java rename src/main/java/art/arcane/iris/{engine/object/loot/IrisLootMode.java => builtin/loot/LootMode.java} (84%) create mode 100644 src/main/java/art/arcane/iris/builtin/loot/LootSettings.java rename src/main/java/art/arcane/iris/{engine/object/loot/InventorySlotType.java => builtin/loot/LootSlot.java} (82%) rename src/main/java/art/arcane/iris/{engine/object/loot/IrisLootTable.java => builtin/loot/LootTable.java} (58%) create mode 100644 src/main/java/art/arcane/iris/builtin/spawn/AmbientEffect.java create mode 100644 src/main/java/art/arcane/iris/builtin/spawn/EffectCommands.java create mode 100644 src/main/java/art/arcane/iris/builtin/spawn/EffectSettings.java rename src/main/java/art/arcane/iris/{engine/object/entity/IrisEntity.java => builtin/spawn/EntityDefinition.java} (50%) create mode 100644 src/main/java/art/arcane/iris/builtin/spawn/EntitySpawn.java rename src/main/java/art/arcane/iris/{engine/object/marker/IrisCommand.java => builtin/spawn/SpawnCommand.java} (51%) rename src/main/java/art/arcane/iris/{engine/object/value/IrisDuration.java => builtin/spawn/SpawnDuration.java} (58%) rename src/main/java/art/arcane/iris/{engine/object/entity/spawn/IrisSpawnGroup.java => builtin/spawn/SpawnGroup.java} (79%) rename src/main/java/art/arcane/iris/{engine/object/marker/IrisMarker.java => builtin/spawn/SpawnMarker.java} (51%) rename src/main/java/art/arcane/iris/{engine/object/value/IrisRate.java => builtin/spawn/SpawnRate.java} (54%) rename src/main/java/art/arcane/iris/{engine/object/entity/spawn/IrisSurface.java => builtin/spawn/SpawnSurface.java} (79%) rename src/main/java/art/arcane/iris/{engine/object/world/IrisTimeBlock.java => builtin/spawn/SpawnTimeBlock.java} (71%) rename src/main/java/art/arcane/iris/{engine/object/world/IrisWeather.java => builtin/spawn/SpawnWeather.java} (65%) create mode 100644 src/main/java/art/arcane/iris/builtin/spawn/Spawner.java create mode 100644 src/main/java/art/arcane/iris/builtin/spawn/SpawnerSettings.java create mode 100644 src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java create mode 100644 src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/entity/IrisEffect.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/entity/IrisEntitySpawn.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/entity/IrisPotionEffect.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/entity/PotionEffectTypes.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawner.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/loot/IrisBlockDrops.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/loot/IrisLoot.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/loot/IrisLootReference.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/loot/IrisVanillaLootTable.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/marker/IrisCommandRegistry.java create mode 100644 src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java create mode 100644 src/main/java/art/arcane/iris/engine/spawn/EffectTimers.java create mode 100644 src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java create mode 100644 src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java diff --git a/src/main/java/art/arcane/iris/builtin/loot/BlockDrop.java b/src/main/java/art/arcane/iris/builtin/loot/BlockDrop.java new file mode 100644 index 000000000..75151041e --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/loot/BlockDrop.java @@ -0,0 +1,73 @@ +/* + * 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.loot; + +import com.volmit.block.BlockSpec; +import com.volmit.config.Desc; +import com.volmit.config.MinItems; +import com.volmit.config.Required; +import com.volmit.config.Snippet; + +import java.util.Collections; +import java.util.List; + +@Snippet("block-drops") +@Desc("Represents a block drop list") +public final class BlockDrop { + @Required + @MinItems(1) + @Desc("The blocks that drop loot") + private List blocks = List.of(); + + @Desc("If exact blocks is set to true, minecraft:barrel[axis=x] will only drop for that axis. When exact is false (default) any barrel will drop the defined drops.") + private boolean exactBlocks = false; + + @MinItems(1) + @Desc("Add in specific items to drop") + private List drops = List.of(); + + @Desc("If this is in a biome, setting skipParents to true will ignore the drops in the region and dimension for this block type. The default (false) will allow all three nodes to fire and add to a list of drops.") + private boolean skipParents = false; + + @Desc("Removes the default vanilla block drops and only drops the given items & any parent loot tables specified for this block type.") + private boolean replaceVanillaDrops = false; + + public BlockDrop() { + } + + public List blocks() { + return blocks == null ? List.of() : Collections.unmodifiableList(blocks); + } + + public boolean exactBlocks() { + return exactBlocks; + } + + public List drops() { + return drops == null ? List.of() : Collections.unmodifiableList(drops); + } + + public boolean skipParents() { + return skipParents; + } + + public boolean replaceVanillaDrops() { + return replaceVanillaDrops; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/loot/BlockDropSettings.java b/src/main/java/art/arcane/iris/builtin/loot/BlockDropSettings.java new file mode 100644 index 000000000..a58786622 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/loot/BlockDropSettings.java @@ -0,0 +1,48 @@ +/* + * 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.loot; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MinItems; + +import java.util.Collections; +import java.util.List; + +/** + * The block drops one dimension, region or biome declares, written as {@code "blockDrops": [...]}, the list of + * {@link BlockDrop}s. A broken block drops those of its biome, then, unless one of them skips its parents, those of its + * region and dimension. + */ +@Desc("Define custom block drops for this area") +@Feature(id = "iris:loot/drops", name = "Block drops", key = "blockDrops", root = "drops", targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) +public final class BlockDropSettings implements IrisFeature { + @MinItems(1) + @Desc("Define custom block drops for this area") + private List drops = List.of(); + + public BlockDropSettings() { + } + + public List drops() { + return drops == null ? List.of() : Collections.unmodifiableList(drops); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/entity/IrisAttributeModifier.java b/src/main/java/art/arcane/iris/builtin/loot/ItemAttributeModifier.java similarity index 74% rename from src/main/java/art/arcane/iris/engine/object/entity/IrisAttributeModifier.java rename to src/main/java/art/arcane/iris/builtin/loot/ItemAttributeModifier.java index 52e4d068c..f5a87fe35 100644 --- a/src/main/java/art/arcane/iris/engine/object/entity/IrisAttributeModifier.java +++ b/src/main/java/art/arcane/iris/builtin/loot/ItemAttributeModifier.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,32 +16,21 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.entity; - -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.volmlib.util.math.RNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; +package art.arcane.iris.builtin.loot; +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; @Snippet("attribute-modifier") -@Accessors(chain = true) -@AllArgsConstructor -@NoArgsConstructor @Desc("Represents an attribute modifier for an item or an entity. This allows you to create modifications to basic game attributes such as MAX_HEALTH or ARMOR_VALUE.") -@Data -public class IrisAttributeModifier { +public final class ItemAttributeModifier { @Required @Desc("The Attribute type key such as max_health or minecraft:armor. This type is pulled from the game attributes. Zombie & Horse attributes will not work on non-zombie/horse entities.\nUsing an attribute on an item will have affects when held, or worn. There is no way to specify further granularity as the game picks this depending on the item type.") private String attribute = null; - @MinNumber(2) @Required @Desc("The Attribute Name is used internally only for the game. This value should be unique to all other attributes applied to this item/entity. It is not shown in game.") private String name = ""; @@ -60,7 +49,30 @@ public class IrisAttributeModifier { @Desc("The chance that this attribute is applied (0 to 1). If the chance is 0.5 (50%), then Iris will only apply this attribute 50% of the time.") private double chance = 1; - public double getAmount(RNG rng) { - return rng.d(getMinAmount(), getMaxAmount()); + public ItemAttributeModifier() { + } + + public String attribute() { + return attribute; + } + + public String name() { + return name; + } + + public String operation() { + return operation; + } + + public double minAmount() { + return minAmount; + } + + public double maxAmount() { + return maxAmount; + } + + public double chance() { + return chance; } } diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisEnchantment.java b/src/main/java/art/arcane/iris/builtin/loot/LootEnchantment.java similarity index 52% rename from src/main/java/art/arcane/iris/engine/object/loot/IrisEnchantment.java rename to src/main/java/art/arcane/iris/builtin/loot/LootEnchantment.java index b3253cc09..0e8d2d405 100644 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisEnchantment.java +++ b/src/main/java/art/arcane/iris/builtin/loot/LootEnchantment.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,33 +16,21 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.loot; - -import art.arcane.iris.engine.framework.LootResolver; -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.RegistryListEnchantment; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.spi.IrisLogging; -import art.arcane.volmlib.util.math.RNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - +package art.arcane.iris.builtin.loot; +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; +import com.volmit.config.Ref; +import com.volmit.config.Reference; +import com.volmit.config.Required; +import com.volmit.config.Snippet; @Snippet("enchantment") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor @Desc("Represents an enchantment & level") -@Data -public class IrisEnchantment { +public final class LootEnchantment { @Required - @RegistryListEnchantment + @Ref(Reference.ENCHANTMENT) @Desc("The enchantment") private String enchantment; @@ -59,7 +47,22 @@ public class IrisEnchantment { @Desc("The chance that this enchantment is applied (0 to 1)") private double chance = 1; - public int getLevel(RNG rng) { - return LootResolver.inclusive(rng, getMinLevel(), getMaxLevel()); + public LootEnchantment() { + } + + public String enchantment() { + return enchantment; + } + + public int minLevel() { + return minLevel; + } + + public int maxLevel() { + return maxLevel; + } + + public double chance() { + return chance; } } diff --git a/src/main/java/art/arcane/iris/builtin/loot/LootEntry.java b/src/main/java/art/arcane/iris/builtin/loot/LootEntry.java new file mode 100644 index 000000000..b90fa6d8d --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/loot/LootEntry.java @@ -0,0 +1,181 @@ +/* + * 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.loot; + +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinItems; +import com.volmit.config.MinNumber; +import com.volmit.config.Ref; +import com.volmit.config.Reference; +import com.volmit.config.Required; +import com.volmit.config.Snippet; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +@Snippet("loot") +@Desc("Represents a loot entry") +public final class LootEntry { + public static final int MAX_AMOUNT = 64; + + @Desc("The target inventory slot types to fill this loot with. World generation only ever fills STORAGE; the other values are inert during worldgen.") + private LootSlot slotTypes = LootSlot.STORAGE; + + @MinNumber(1) + @Desc("The sub rarity of this loot. Calculated after this loot table has been picked.") + private int rarity = 1; + + @MinNumber(1) + @MaxNumber(MAX_AMOUNT) + @Desc("Minimum amount of this loot, from 1 to 64") + private int minAmount = 1; + + @MinNumber(1) + @MaxNumber(MAX_AMOUNT) + @Desc("Maximum amount of this loot, from 1 to 64") + private int maxAmount = 1; + + @Desc("The display name of this item") + private String displayName = null; + + @MinNumber(0) + @MaxNumber(1) + @Desc("Minimum durability percent") + private double minDurability = 0; + + @MinNumber(0) + @MaxNumber(1) + @Desc("Maximum durability percent") + private double maxDurability = 1; + + @Desc("Define a custom model identifier 1.14+ only") + private Integer customModel = null; + + @Desc("Set this to true to prevent it from being broken") + private boolean unbreakable = false; + + @MinItems(1) + @Desc("The item flags to add") + private List itemFlags = List.of(); + + @MinItems(1) + @Desc("Apply enchantments to this item") + private List enchantments = List.of(); + + @MinItems(1) + @Desc("Apply attribute modifiers to this item") + private List attributes = List.of(); + + @MinItems(1) + @Desc("Add lore to this item") + private List lore = List.of(); + + @Ref(Reference.ITEM) + @Required + @Desc("This is the item or block type. Does not accept minecraft:*, only materials such as DIAMOND_SWORD or DIRT. The exception are modded materials, as they require a namespace.") + private String type = ""; + + @Desc("The dye color") + private String dyeColor = null; + + @Desc("The leather armor color") + private String leatherColor = null; + + @Desc("Defines a custom NBT Tag for the item.") + private Map customNbt; + + public LootEntry() { + } + + public LootSlot slotTypes() { + return slotTypes == null ? LootSlot.STORAGE : slotTypes; + } + + public int rarity() { + return rarity; + } + + public int minAmount() { + return minAmount; + } + + public int maxAmount() { + return maxAmount; + } + + public String displayName() { + return displayName; + } + + public double minDurability() { + return minDurability; + } + + public double maxDurability() { + return maxDurability; + } + + public Integer customModel() { + return customModel; + } + + public boolean unbreakable() { + return unbreakable; + } + + public List itemFlags() { + return listOrEmpty(itemFlags); + } + + public List enchantments() { + return listOrEmpty(enchantments); + } + + public List attributes() { + return listOrEmpty(attributes); + } + + public List lore() { + return listOrEmpty(lore); + } + + /** The authored item key, exactly as written in the pack. Each platform resolves it against its own item registry. */ + public String type() { + return type; + } + + public String dyeColor() { + return dyeColor; + } + + public String leatherColor() { + return leatherColor; + } + + /** The custom data of the item; empty when unset. */ + public Map customNbt() { + return customNbt == null ? Map.of() : Collections.unmodifiableMap(customNbt); + } + + private static List listOrEmpty(List list) { + return list == null ? List.of() : Collections.unmodifiableList(list); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisLootMode.java b/src/main/java/art/arcane/iris/builtin/loot/LootMode.java similarity index 84% rename from src/main/java/art/arcane/iris/engine/object/loot/IrisLootMode.java rename to src/main/java/art/arcane/iris/builtin/loot/LootMode.java index 622d7f825..7fe817478 100644 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisLootMode.java +++ b/src/main/java/art/arcane/iris/builtin/loot/LootMode.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.loot; +package art.arcane.iris.builtin.loot; -import art.arcane.iris.engine.object.annotations.Desc; +import com.volmit.config.Desc; @Desc("A loot mode is used to describe what to do with the existing loot layers before adding this loot. ADD appends to the building list of tables (dimension tables, then region tables, then biome tables). REPLACE swaps the parent tables for this reference's tables. CLEAR suppresses loot entirely at this point.") -public enum IrisLootMode { +public enum LootMode { @Desc("Add to the existing parent loot tables") ADD, @Desc("Clear all parent loot tables and contribute nothing at this level. Any tables listed here are ignored.") diff --git a/src/main/java/art/arcane/iris/builtin/loot/LootSettings.java b/src/main/java/art/arcane/iris/builtin/loot/LootSettings.java new file mode 100644 index 000000000..5d9b12ae7 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/loot/LootSettings.java @@ -0,0 +1,72 @@ +/* + * 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.loot; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; +import com.volmit.config.ResourceRef; +import com.volmit.config.Snippet; + +import java.util.Collections; +import java.util.List; + +/** + * The loot tables one dimension, region or biome adds to the containers it covers, written as + * {@code "loot": {"mode": "ADD", "tables": [...], "multiplier": 1}}. Levels stack, dimension first, then region and + * biome; {@link LootMode} says what each does with the tables before it. An entity's {@code loot} has the same shape. + */ +@Snippet("loot-registry") +@Desc("Reference loot tables in this area") +@Feature(id = "iris:loot", name = "Loot", key = "loot", targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) +public final class LootSettings implements IrisFeature { + public static final double MAX_MULTIPLIER = 16D; + + @Desc("ADD = add on top of parent tables. REPLACE = clear parent tables, then add these. CLEAR = clear parent tables and add nothing, even if tables are listed. FALLBACK = only used when nothing else defined a table.") + private LootMode mode = LootMode.ADD; + + @ResourceRef(LootTable.class) + @Desc("Add loot table registries here") + private List tables = List.of(); + + @MinNumber(0) + @MaxNumber(MAX_MULTIPLIER) + @Desc("Scale loot sources in this area from 0 to 16 times their normal count") + private double multiplier = 1D; + + /** Nothing added, nothing scaled: what a level without loot settings means. */ + public LootSettings() { + } + + public LootMode mode() { + return mode == null ? LootMode.ADD : mode; + } + + /** The keys of the loot tables, in order. */ + public List tables() { + return tables == null ? List.of() : Collections.unmodifiableList(tables); + } + + public double multiplier() { + return multiplier; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/loot/InventorySlotType.java b/src/main/java/art/arcane/iris/builtin/loot/LootSlot.java similarity index 82% rename from src/main/java/art/arcane/iris/engine/object/loot/InventorySlotType.java rename to src/main/java/art/arcane/iris/builtin/loot/LootSlot.java index 574fc301f..6723d461a 100644 --- a/src/main/java/art/arcane/iris/engine/object/loot/InventorySlotType.java +++ b/src/main/java/art/arcane/iris/builtin/loot/LootSlot.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.loot; +package art.arcane.iris.builtin.loot; -import art.arcane.iris.engine.object.annotations.Desc; +import com.volmit.config.Desc; @Desc("An inventory slot type is used to represent a type of slot for items to fit into in any given inventory.") -public enum InventorySlotType { +public enum LootSlot { @Desc("Typically the one you want to go with. Storage represnents most slots in inventories.") STORAGE, diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisLootTable.java b/src/main/java/art/arcane/iris/builtin/loot/LootTable.java similarity index 58% rename from src/main/java/art/arcane/iris/engine/object/loot/IrisLootTable.java rename to src/main/java/art/arcane/iris/builtin/loot/LootTable.java index d92ff93ee..5c495b3db 100644 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisLootTable.java +++ b/src/main/java/art/arcane/iris/builtin/loot/LootTable.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,34 +16,25 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.loot; +package art.arcane.iris.builtin.loot; -import art.arcane.iris.core.loader.IrisRegistrant; -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.volmlib.util.collection.KList; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinItems; +import com.volmit.config.MinNumber; +import com.volmit.config.Required; -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor +import java.util.Collections; +import java.util.List; + +/** A loot table of the pack, one file of {@code loot/}. */ @Desc("Represents a loot table. Biomes, Regions & Objects can add or replace the virtual table with these loot tables") -@Data -@EqualsAndHashCode(callSuper = false) -public class IrisLootTable extends IrisRegistrant { +public final class LootTable { public static final int MAX_PICKED = 64; public static final int MAX_TRIES = 256; @Required @Desc("The name of this loot table") - @MinNumber(2) private String name = ""; @MinNumber(1) @@ -65,17 +56,34 @@ public class IrisLootTable extends IrisRegistrant { @Desc("The maximum amount of tries to generate loot, from 1 to 256") private int maxTries = 10; + @MinItems(1) @Desc("The loot in this table") - @ArrayType(min = 1, type = IrisLoot.class) - private KList loot = new KList<>(); + private List loot = List.of(); - @Override - public String getFolderName() { - return "loot"; + public LootTable() { } - @Override - public String getTypeName() { - return "Loot"; + public String name() { + return name == null ? "" : name; + } + + public int rarity() { + return rarity; + } + + public int maxPicked() { + return maxPicked; + } + + public int minPicked() { + return minPicked; + } + + public int maxTries() { + return maxTries; + } + + public List loot() { + return loot == null ? List.of() : Collections.unmodifiableList(loot); } } diff --git a/src/main/java/art/arcane/iris/builtin/spawn/AmbientEffect.java b/src/main/java/art/arcane/iris/builtin/spawn/AmbientEffect.java new file mode 100644 index 000000000..090e3ee97 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/spawn/AmbientEffect.java @@ -0,0 +1,247 @@ +/* + * 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.spawn; + +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; +import com.volmit.config.Ref; +import com.volmit.config.Reference; +import com.volmit.config.Required; +import com.volmit.config.Snippet; + +/** + * A sound, particles, potion effect or commands that play now and then around the players in an area. The same + * settings make the effect an entity shows when it appears ({@link EntityDefinition#spawnEffect()}). + */ +@Snippet("effect") +@Desc("An iris effect") +public final class AmbientEffect { + @Ref(Reference.POTION_EFFECT) + @Desc("The potion effect to apply in this area") + private String potionEffect = ""; + + @Desc("The particle effect to apply in the area") + private String particleEffect = null; + + @MinNumber(-32) + @MaxNumber(32) + @Desc("Randomly offset from the surface to this surface+value") + private int particleOffset = 0; + + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") + private double particleAltX = 0; + + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") + private double particleAltY = 0; + + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") + private double particleAltZ = 0; + + @Desc("Randomize the altX by -altX to altX") + private boolean randomAltX = true; + + @Desc("Randomize the altY by -altY to altY") + private boolean randomAltY = false; + + @Desc("Randomize the altZ by -altZ to altZ") + private boolean randomAltZ = true; + + @Desc("The sound to play") + private String sound = null; + + @MinNumber(0) + @MaxNumber(512) + @Desc("The max distance from the player the sound will play") + private int soundDistance = 12; + + @MinNumber(0.01) + @MaxNumber(1.99) + @Desc("The minimum sound pitch") + private double minPitch = 0.5D; + + @MinNumber(0.01) + @MaxNumber(1.99) + @Desc("The max sound pitch") + private double maxPitch = 1.5D; + + @MinNumber(0.001) + @MaxNumber(512) + @Desc("The sound volume.") + private double volume = 1.5D; + + @MinNumber(0) + @MaxNumber(512) + @Desc("The particle count. Try setting to zero for using the alt xyz to a motion value instead of an offset") + private int particleCount = 0; + + @MinNumber(0) + @MaxNumber(64) + @Desc("How far away from the player particles can play") + private int particleDistance = 20; + + @MinNumber(0) + @MaxNumber(128) + @Desc("How wide the particles can play (player's view left and right) RADIUS") + private int particleDistanceWidth = 24; + + @Desc("An extra value for some particles... Which bukkit doesn't even document.") + private double extra = 0; + + @MinNumber(-1) + @MaxNumber(1024) + @Desc("The Potion Strength or -1 to disable") + private int potionStrength = -1; + + @MinNumber(1) + @Desc("The max time the potion will last for") + private int potionTicksMax = 155; + + @MinNumber(1) + @Desc("The min time the potion will last for") + private int potionTicksMin = 75; + + @Required + @MinNumber(0) + @Desc("The effect interval in milliseconds") + private int interval = 150; + + @MinNumber(0) + @MaxNumber(16) + @Desc("The effect distance start away") + private int particleAway = 5; + + @Required + @MinNumber(1) + @Desc("The chance is 1 in CHANCE per interval") + private int chance = 50; + + @Desc("Run commands, with configurable location parameters") + private EffectCommands commandRegistry = null; + + public AmbientEffect() { + } + + public String potionEffect() { + return potionEffect; + } + + public String particleEffect() { + return particleEffect; + } + + public int particleOffset() { + return particleOffset; + } + + public double particleAltX() { + return particleAltX; + } + + public double particleAltY() { + return particleAltY; + } + + public double particleAltZ() { + return particleAltZ; + } + + public boolean randomAltX() { + return randomAltX; + } + + public boolean randomAltY() { + return randomAltY; + } + + public boolean randomAltZ() { + return randomAltZ; + } + + public String sound() { + return sound; + } + + public int soundDistance() { + return soundDistance; + } + + public double minPitch() { + return minPitch; + } + + public double maxPitch() { + return maxPitch; + } + + public double volume() { + return volume; + } + + public int particleCount() { + return particleCount; + } + + public int particleDistance() { + return particleDistance; + } + + public int particleDistanceWidth() { + return particleDistanceWidth; + } + + public double extra() { + return extra; + } + + public int potionStrength() { + return potionStrength; + } + + public int potionTicksMax() { + return potionTicksMax; + } + + public int potionTicksMin() { + return potionTicksMin; + } + + public int interval() { + return interval; + } + + public int particleAway() { + return particleAway; + } + + public int chance() { + return chance; + } + + /** The commands the effect runs; null for none. */ + public EffectCommands commandRegistry() { + return commandRegistry; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/spawn/EffectCommands.java b/src/main/java/art/arcane/iris/builtin/spawn/EffectCommands.java new file mode 100644 index 000000000..48ed35cc8 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/spawn/EffectCommands.java @@ -0,0 +1,100 @@ +/* + * 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.spawn; + +import com.volmit.config.Desc; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinItems; +import com.volmit.config.MinNumber; +import com.volmit.config.Required; +import com.volmit.config.Snippet; + +import java.util.Collections; +import java.util.List; + +@Snippet("command-registry") +@Desc("Represents a casting location for a command") +public final class EffectCommands { + @Required + @MinItems(1) + @Desc("Run commands, at the exact location of the player") + private List rawCommands = List.of(); + + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetX = 0; + + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetY = 0; + + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetZ = 0; + + @Desc("Randomize the altX from -altX to altX") + private boolean commandRandomAltX = true; + + @Desc("Randomize the altY from -altY to altY") + private boolean commandRandomAltY = false; + + @Desc("Randomize the altZ from -altZ to altZ") + private boolean commandRandomAltZ = true; + + @Desc("Randomize location for all separate commands (true), or run all on the same location (false)") + private boolean commandAllRandomLocations = true; + + public EffectCommands() { + } + + public List rawCommands() { + return rawCommands == null ? List.of() : Collections.unmodifiableList(rawCommands); + } + + public double commandOffsetX() { + return commandOffsetX; + } + + public double commandOffsetY() { + return commandOffsetY; + } + + public double commandOffsetZ() { + return commandOffsetZ; + } + + public boolean commandRandomAltX() { + return commandRandomAltX; + } + + public boolean commandRandomAltY() { + return commandRandomAltY; + } + + public boolean commandRandomAltZ() { + return commandRandomAltZ; + } + + public boolean commandAllRandomLocations() { + return commandAllRandomLocations; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/spawn/EffectSettings.java b/src/main/java/art/arcane/iris/builtin/spawn/EffectSettings.java new file mode 100644 index 000000000..49f90914c --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/spawn/EffectSettings.java @@ -0,0 +1,47 @@ +/* + * 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.spawn; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MinItems; + +import java.util.Collections; +import java.util.List; + +/** + * The ambient effects one region or biome declares, written as {@code "effects": [...]}, the list of + * {@link AmbientEffect}s. They play around every player in the area. + */ +@Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play arround the player even if where the effect was played is no longer in the biome the player is in.") +@Feature(id = "iris:spawn/effects", name = "Effects", key = "effects", root = "effects", targets = {Target.REGION, Target.BIOME}) +public final class EffectSettings implements IrisFeature { + @MinItems(1) + @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player.") + private List effects = List.of(); + + public EffectSettings() { + } + + public List effects() { + return effects == null ? List.of() : Collections.unmodifiableList(effects); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/entity/IrisEntity.java b/src/main/java/art/arcane/iris/builtin/spawn/EntityDefinition.java similarity index 50% rename from src/main/java/art/arcane/iris/engine/object/entity/IrisEntity.java rename to src/main/java/art/arcane/iris/builtin/spawn/EntityDefinition.java index 709d4c2b1..a1258af7d 100644 --- a/src/main/java/art/arcane/iris/engine/object/entity/IrisEntity.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/EntityDefinition.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,34 +16,25 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.entity; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.entity.spawn.IrisSurface; -import art.arcane.iris.engine.object.loot.IrisLoot; -import art.arcane.iris.engine.object.loot.IrisLootReference; -import art.arcane.iris.engine.object.marker.IrisCommand; -import art.arcane.iris.core.loader.IrisRegistrant; -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.RegistryListEntityType; -import art.arcane.iris.engine.object.annotations.RegistryListSpecialEntity; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.volmlib.util.collection.KList; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; +import art.arcane.iris.builtin.loot.ItemAttributeModifier; +import art.arcane.iris.builtin.loot.LootEntry; +import art.arcane.iris.builtin.loot.LootSettings; +import com.volmit.config.Desc; +import com.volmit.config.MinItems; +import com.volmit.config.Ref; +import com.volmit.config.Reference; +import com.volmit.config.Required; -@SuppressWarnings("ALL") -@Accessors(chain = true) -@NoArgsConstructor +import java.util.Collections; +import java.util.List; +/** An entity of the pack, one file of {@code entities/}: what spawners and markers spawn, with its equipment, attributes, passengers and loot. */ @Desc("Represents an iris entity.") -@Data -@EqualsAndHashCode(callSuper = false) -public class IrisEntity extends IrisRegistrant { +public final class EntityDefinition { @Required - @RegistryListEntityType + @Ref(Reference.ENTITY) @Desc("The namespaced key of the entity type to spawn, such as minecraft:zombie or alexsmobs:grizzly_bear. To spawn a mob from another plugin or provider, set this type to unknown and define the special type.") private String type = null; @@ -81,39 +72,39 @@ public class IrisEntity extends IrisRegistrant { private boolean removable = false; @Desc("Entity helmet equipment") - private IrisLoot helmet = null; + private LootEntry helmet = null; @Desc("Entity chestplate equipment") - private IrisLoot chestplate = null; + private LootEntry chestplate = null; @Desc("Entity boots equipment") - private IrisLoot boots = null; + private LootEntry boots = null; @Desc("Entity leggings equipment") - private IrisLoot leggings = null; + private LootEntry leggings = null; @Desc("Entity main hand equipment") - private IrisLoot mainHand = null; + private LootEntry mainHand = null; @Desc("Entity off hand equipment") - private IrisLoot offHand = null; + private LootEntry offHand = null; + @MinItems(1) @Desc("Make other entities ride this entity") - @ArrayType(min = 1, type = IrisEntity.class) - private KList passengers = new KList<>(); + private List passengers = List.of(); + @MinItems(1) @Desc("Attribute modifiers for this entity") - @ArrayType(min = 1, type = IrisAttributeModifier.class) - private KList attributes = new KList<>(); + private List attributes = List.of(); @Desc("Loot tables for drops. Only the tables list is honored for entities; mode and multiplier are ignored, and the tables replace vanilla drops entirely.") - private IrisLootReference loot = new IrisLootReference(); + private LootSettings loot = new LootSettings(); @Desc("If specified, this entity will be leashed by this entity. I.e. THIS ENTITY Leashed by SPECIFIED. This has no effect on EnderDragons, Withers, Players, or Bats.Non-living entities excluding leashes will not persist as leashholders.") - private IrisEntity leashHolder = null; + private EntityDefinition leashHolder = null; @Desc("If specified, this entity will spawn with an effect") - private IrisEffect spawnEffect = null; + private AmbientEffect spawnEffect = null; @Desc("Simply moves the entity from below the surface slowly out of the ground as a spawn-in effect") private boolean spawnEffectRiseOutOfGround = false; @@ -131,30 +122,153 @@ public class IrisEntity extends IrisRegistrant { private boolean keepEntity = false; @Desc("The surface type to spawn this mob on") - private IrisSurface surface = IrisSurface.LAND; + private SpawnSurface surface = SpawnSurface.LAND; - @RegistryListSpecialEntity + @Ref(Reference.SPECIAL_ENTITY) @Desc("Create a mob from another plugin, such as Mythic Mobs. Should be in the format of a namespace of PluginName:MobName") private String specialType = ""; @Desc("Set to true if you want to apply all of the settings here to the mob, even though an external plugin has already done so.") private boolean applySettingsToCustomMobAnyways = false; - @ArrayType(min = 1, type = IrisCommand.class) + @MinItems(1) @Desc("Run raw commands when this entity is spawned. Use {x}, {y}, and {z} for location. /summon pig {x} {y} {z}") - private KList rawCommands = new KList<>(); + private List rawCommands = List.of(); + public EntityDefinition() { + } + + public String type() { + return type; + } + + public String reason() { + return reason; + } + + public String customName() { + return customName; + } + + public boolean customNameVisible() { + return customNameVisible; + } + + public boolean aware() { + return aware; + } + + public boolean ai() { + return ai; + } + + public boolean glowing() { + return glowing; + } + + public boolean gravity() { + return gravity; + } + + public boolean invulnerable() { + return invulnerable; + } + + public boolean silent() { + return silent; + } + + public boolean pickupItems() { + return pickupItems; + } + + public boolean removable() { + return removable; + } + + public LootEntry helmet() { + return helmet; + } + + public LootEntry chestplate() { + return chestplate; + } + + public LootEntry boots() { + return boots; + } + + public LootEntry leggings() { + return leggings; + } + + public LootEntry mainHand() { + return mainHand; + } + + public LootEntry offHand() { + return offHand; + } + + public List passengers() { + return passengers == null ? List.of() : Collections.unmodifiableList(passengers); + } + + public List attributes() { + return attributes == null ? List.of() : Collections.unmodifiableList(attributes); + } + + /** The loot the entity drops when it dies; only its tables count. */ + public LootSettings loot() { + return loot == null ? new LootSettings() : loot; + } + + public EntityDefinition leashHolder() { + return leashHolder; + } + + public AmbientEffect spawnEffect() { + return spawnEffect; + } + + public boolean spawnEffectRiseOutOfGround() { + return spawnEffectRiseOutOfGround; + } + + public String pandaMainGene() { + return pandaMainGene; + } + + public String pandaHiddenGene() { + return pandaHiddenGene; + } + + public boolean baby() { + return baby; + } + + public boolean keepEntity() { + return keepEntity; + } + + public SpawnSurface surface() { + return surface == null ? SpawnSurface.LAND : surface; + } + + public String specialType() { + return specialType; + } + + /** Whether the entity is a mob of another plugin. */ public boolean isSpecialType() { - return specialType != null && !specialType.equals(""); + return specialType != null && !specialType.isEmpty(); } - @Override - public String getFolderName() { - return "entities"; + public boolean applySettingsToCustomMobAnyways() { + return applySettingsToCustomMobAnyways; } - @Override - public String getTypeName() { - return "Entity"; + public List rawCommands() { + return rawCommands == null ? List.of() : Collections.unmodifiableList(rawCommands); } } diff --git a/src/main/java/art/arcane/iris/builtin/spawn/EntitySpawn.java b/src/main/java/art/arcane/iris/builtin/spawn/EntitySpawn.java new file mode 100644 index 000000000..34acbcae5 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/spawn/EntitySpawn.java @@ -0,0 +1,66 @@ +/* + * 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.spawn; + +import com.volmit.config.Desc; +import com.volmit.config.MinNumber; +import com.volmit.config.Required; +import com.volmit.config.ResourceRef; +import com.volmit.config.Snippet; + +@Snippet("entity-spawn") +@Desc("Represents an entity spawn during initial chunk generation") +public final class EntitySpawn { + @ResourceRef(EntityDefinition.class) + @Required + @Desc("The entity") + private String entity = ""; + + @MinNumber(1) + @Desc("The 1 in RARITY chance for this entity to spawn") + private int rarity = 1; + + @MinNumber(1) + @Desc("The minumum of this entity to spawn") + private int minSpawns = 1; + + @MinNumber(1) + @Desc("The max of this entity to spawn") + private int maxSpawns = 1; + + public EntitySpawn() { + } + + /** The key of the entity of the pack. */ + public String entity() { + return entity; + } + + public int rarity() { + return rarity; + } + + public int minSpawns() { + return minSpawns; + } + + public int maxSpawns() { + return maxSpawns; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/marker/IrisCommand.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnCommand.java similarity index 51% rename from src/main/java/art/arcane/iris/engine/object/marker/IrisCommand.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnCommand.java index 5062b80b5..cfd8f5b64 100644 --- a/src/main/java/art/arcane/iris/engine/object/marker/IrisCommand.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnCommand.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,32 +16,23 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.marker; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.world.IrisTimeBlock; -import art.arcane.iris.engine.object.world.IrisWeather; -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.spi.PlatformWorld; -import art.arcane.iris.util.common.scheduling.ConsoleCommands; -import art.arcane.volmlib.util.collection.KList; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; +import com.volmit.config.Desc; +import com.volmit.config.MinItems; +import com.volmit.config.Required; +import com.volmit.config.Snippet; + +import java.util.Collections; +import java.util.List; @Snippet("command") -@Accessors(chain = true) -@NoArgsConstructor @Desc("Represents a set of Iris commands") -@Data -public class IrisCommand { - +public final class SpawnCommand { @Required - @ArrayType(min = 1, type = String.class) + @MinItems(1) @Desc("List of commands. Iris replaces {x} {y} and {z} with the location of the entity spawn") - private KList commands = new KList<>(); + private List commands = List.of(); @Desc("The delay for running the command. Instant by default") private long delay = 0; @@ -53,20 +44,35 @@ public class IrisCommand { private long repeatDelay = 100; @Desc("The block of 24 hour time in which the command should execute.") - private IrisTimeBlock timeBlock = new IrisTimeBlock(); + private SpawnTimeBlock timeBlock = new SpawnTimeBlock(); @Desc("The weather that is required for the command to execute.") - private IrisWeather weather = IrisWeather.ANY; + private SpawnWeather weather = SpawnWeather.ANY; - public boolean isValid(PlatformWorld world) { - return timeBlock.isWithin(world) && weather.is(world); + public SpawnCommand() { } - public void run(PlatformWorld world, int x, int y, int z) { - if (!isValid(world)) { - return; - } + public List commands() { + return commands == null ? List.of() : Collections.unmodifiableList(commands); + } - ConsoleCommands.run(commands, delay, repeat, repeatDelay, x, y, z); + public long delay() { + return delay; + } + + public boolean repeat() { + return repeat; + } + + public long repeatDelay() { + return repeatDelay; + } + + public SpawnTimeBlock timeBlock() { + return timeBlock == null ? new SpawnTimeBlock() : timeBlock; + } + + public SpawnWeather weather() { + return weather == null ? SpawnWeather.ANY : weather; } } diff --git a/src/main/java/art/arcane/iris/engine/object/value/IrisDuration.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnDuration.java similarity index 58% rename from src/main/java/art/arcane/iris/engine/object/value/IrisDuration.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnDuration.java index 822bd6962..afe1263b5 100644 --- a/src/main/java/art/arcane/iris/engine/object/value/IrisDuration.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnDuration.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,19 +16,22 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.value; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.volmlib.util.format.Form; -import lombok.Data; +import com.volmit.config.Desc; +import com.volmit.config.Snippet; import java.util.concurrent.TimeUnit; @Snippet("duration") -@Data @Desc("Represents a combined duration. Fill each property to add time into a single duration") -public class IrisDuration { +public final class SpawnDuration { + private static final long MILLISECONDS_PER_MINECRAFT_TICK = 50L; + private static final long MILLISECONDS_PER_MINECRAFT_HOUR = 50_000L; + private static final long MILLISECONDS_PER_MINECRAFT_DAY = 1_200_000L; + private static final long MILLISECONDS_PER_MINECRAFT_WEEK = 8_400_000L; + private static final long MILLISECONDS_PER_MINECRAFT_LUNAR_CYCLE = 9_600_000L; + @Desc("Milliseconds (1000ms = 1 second)") private int milliseconds = 0; @@ -59,20 +62,19 @@ public class IrisDuration { @Desc("REAL (not minecraft) Days") private int days = 0; - public String toString() { - return Form.duration((double) toMilliseconds(), 2); + public SpawnDuration() { } public long toMilliseconds() { - return getMilliseconds() - + TimeUnit.SECONDS.toMillis(getSeconds()) - + TimeUnit.MINUTES.toMillis(getMinutes()) - + TimeUnit.HOURS.toMillis(getHours()) - + TimeUnit.DAYS.toMillis(getDays()) - + (getMinecraftTicks() * 50L) - + (getMinecraftHours() * 50000L) - + (getMinecraftDays() * 1_200_000L) - + (getMinecraftWeeks() * 8_400_000L) - + (getMinecraftLunarCycles() * 9_600_000L); + return milliseconds + + TimeUnit.SECONDS.toMillis(seconds) + + TimeUnit.MINUTES.toMillis(minutes) + + TimeUnit.HOURS.toMillis(hours) + + TimeUnit.DAYS.toMillis(days) + + (minecraftTicks * MILLISECONDS_PER_MINECRAFT_TICK) + + (minecraftHours * MILLISECONDS_PER_MINECRAFT_HOUR) + + (minecraftDays * MILLISECONDS_PER_MINECRAFT_DAY) + + (minecraftWeeks * MILLISECONDS_PER_MINECRAFT_WEEK) + + (minecraftLunarCycles * MILLISECONDS_PER_MINECRAFT_LUNAR_CYCLE); } } diff --git a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnGroup.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnGroup.java similarity index 79% rename from src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnGroup.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnGroup.java index 20f8b65f1..0e2b1abd8 100644 --- a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnGroup.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnGroup.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.entity.spawn; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.annotations.Desc; +import com.volmit.config.Desc; @Desc("Terrain modes are used to decide the generator type currently used") -public enum IrisSpawnGroup { +public enum SpawnGroup { @Desc("Spawns on the terrain surface") NORMAL, diff --git a/src/main/java/art/arcane/iris/engine/object/marker/IrisMarker.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnMarker.java similarity index 51% rename from src/main/java/art/arcane/iris/engine/object/marker/IrisMarker.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnMarker.java index 1cb419299..249b8fb5a 100644 --- a/src/main/java/art/arcane/iris/engine/object/marker/IrisMarker.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnMarker.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,32 +16,22 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.marker; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; -import art.arcane.iris.core.loader.IrisRegistrant; -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.RegistryListResource; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.RNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; +import com.volmit.config.Desc; +import com.volmit.config.MinItems; +import com.volmit.config.ResourceRef; -@Accessors(chain = true) -@AllArgsConstructor -@NoArgsConstructor +import java.util.Collections; +import java.util.List; + +/** A marker of the pack, one file of {@code markers/}: object placements put markers in the world and a marker names the spawners that fire there. */ @Desc("Represents a marker") -@Data -@EqualsAndHashCode(callSuper = false) -public class IrisMarker extends IrisRegistrant { +public final class SpawnMarker { @Desc("A list of spawners to add to anywhere this marker is.") - @RegistryListResource(IrisSpawner.class) - @ArrayType(type = String.class, min = 1) - private KList spawners = new KList<>(); + @ResourceRef(Spawner.class) + @MinItems(1) + private List spawners = List.of(); @Desc("Remove this marker when the block it's assigned to is changed.") private boolean removeOnChange = true; @@ -52,17 +42,23 @@ public class IrisMarker extends IrisRegistrant { @Desc("If this marker is used, what is the chance it removes itself. For example 25% (0.25) would mean that on average 4 uses will remove a specific marker. Set this below 0 (-1) to never exhaust & set this to 1 or higher to always exhaust on first use.") private double exhaustionChance = 0; - public boolean shouldExhaust() { - return exhaustionChance > RNG.r.nextDouble(); + public SpawnMarker() { } - @Override - public String getFolderName() { - return "markers"; + /** The keys of the spawners that fire at the marker. */ + public List spawners() { + return spawners == null ? List.of() : Collections.unmodifiableList(spawners); } - @Override - public String getTypeName() { - return "Marker"; + public boolean removeOnChange() { + return removeOnChange; + } + + public boolean emptyAbove() { + return emptyAbove; + } + + public double exhaustionChance() { + return exhaustionChance; } } diff --git a/src/main/java/art/arcane/iris/engine/object/value/IrisRate.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnRate.java similarity index 54% rename from src/main/java/art/arcane/iris/engine/object/value/IrisRate.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnRate.java index f347b6085..05e226551 100644 --- a/src/main/java/art/arcane/iris/engine/object/value/IrisRate.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnRate.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,42 +16,35 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.value; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.volmlib.util.format.Form; -import art.arcane.volmlib.util.scheduling.ChronoLatch; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import com.volmit.config.Desc; +import com.volmit.config.Snippet; @Snippet("rate") -@NoArgsConstructor -@AllArgsConstructor -@Data @Desc("Represents a count of something per time duration") -public class IrisRate { +public final class SpawnRate { @Desc("The amount of things. Leave 0 for infinite (meaning always spawn whenever)") private int amount = 0; @Desc("The time interval. Leave blank for infinite 0 (meaning always spawn all the time)") - private IrisDuration per = new IrisDuration(); + private SpawnDuration per = new SpawnDuration(); - public String toString() { - return Form.f(amount) + "/" + per; + public SpawnRate() { } - public long getInterval() { - long t = per.toMilliseconds() / (amount == 0 ? 1 : amount); + /** The milliseconds between two things: the interval divided by the amount, at least 1. */ + public long interval() { + long t = duration().toMilliseconds() / (amount == 0 ? 1 : amount); return Math.abs(t <= 0 ? 1 : t); } - public ChronoLatch toChronoLatch() { - return new ChronoLatch(getInterval()); + /** Whether there is no limit: no interval was given. */ + public boolean isInfinite() { + return duration().toMilliseconds() == 0; } - public boolean isInfinite() { - return per.toMilliseconds() == 0; + private SpawnDuration duration() { + return per == null ? new SpawnDuration() : per; } } diff --git a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSurface.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnSurface.java similarity index 79% rename from src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSurface.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnSurface.java index 8a7677d15..45a9ad3c8 100644 --- a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSurface.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnSurface.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.entity.spawn; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.annotations.Desc; +import com.volmit.config.Desc; @Desc("The type of surface entities should spawn on") -public enum IrisSurface { +public enum SpawnSurface { @Desc("Land surfaces") LAND, @@ -36,5 +36,5 @@ public enum IrisSurface { OVERWORLD, @Desc("Within lava") - LAVA; + LAVA } diff --git a/src/main/java/art/arcane/iris/engine/object/world/IrisTimeBlock.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnTimeBlock.java similarity index 71% rename from src/main/java/art/arcane/iris/engine/object/world/IrisTimeBlock.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnTimeBlock.java index b4035203c..5fc38b4b9 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/IrisTimeBlock.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnTimeBlock.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,30 +16,29 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.world; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.spi.PlatformWorld; -import lombok.Data; +import com.volmit.config.Desc; +import com.volmit.config.Snippet; @Snippet("time-block") -@Data @Desc("Represents a time of day (24h time, not 12h am/pm). Set both to the same number for any time. If they are both set to -1, it will always be not allowed.") -public class IrisTimeBlock { +public final class SpawnTimeBlock { + private static final double NEVER = -1; + @Desc("The beginning hour. Set both to the same number for any time. If they are both set to -1, it will always be not allowed.") private double startHour = 0; @Desc("The ending hour. Set both to the same number for any time. If they are both set to -1, it will always be not allowed.") private double endHour = 0; - public boolean isWithin(PlatformWorld world) { - return isWithin(((world.getTime() / 1000D) + 6) % 24); + public SpawnTimeBlock() { } - public boolean isWithin(double hour) { + /** Whether {@code hour}, a time of day from 0 to 24, lies in the block; a block that wraps past midnight includes both ends. */ + public boolean contains(double hour) { if (startHour == endHour) { - return endHour != -1; + return endHour != NEVER; } if (startHour > endHour) { diff --git a/src/main/java/art/arcane/iris/engine/object/world/IrisWeather.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnWeather.java similarity index 65% rename from src/main/java/art/arcane/iris/engine/object/world/IrisWeather.java rename to src/main/java/art/arcane/iris/builtin/spawn/SpawnWeather.java index db242e502..a19bd6eda 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/IrisWeather.java +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnWeather.java @@ -1,6 +1,6 @@ /* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 Arcane Arts (Volmit Software) + * 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 @@ -16,13 +16,12 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.world; +package art.arcane.iris.builtin.spawn; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.spi.PlatformWorld; +import com.volmit.config.Desc; @Desc("Represents a weather type") -public enum IrisWeather { +public enum SpawnWeather { @Desc("Represents when weather is not causing downfall") NONE, @@ -35,11 +34,12 @@ public enum IrisWeather { @Desc("Any weather") ANY; - public boolean is(PlatformWorld world) { + /** Whether the weather of a world, which is {@code storming} and {@code thundering} or neither, is this one. */ + public boolean matches(boolean storming, boolean thundering) { return switch (this) { - case NONE -> !world.isStorming() && !world.isThundering(); - case DOWNFALL -> world.isStorming(); - case DOWNFALL_WITH_THUNDER -> world.isStorming() && world.isThundering(); + case NONE -> !storming && !thundering; + case DOWNFALL -> storming; + case DOWNFALL_WITH_THUNDER -> storming && thundering; case ANY -> true; }; } diff --git a/src/main/java/art/arcane/iris/builtin/spawn/Spawner.java b/src/main/java/art/arcane/iris/builtin/spawn/Spawner.java new file mode 100644 index 000000000..e688df757 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/spawn/Spawner.java @@ -0,0 +1,98 @@ +/* + * 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.spawn; + +import com.volmit.config.Desc; +import com.volmit.config.MinItems; +import com.volmit.config.Range; + +import java.util.Collections; +import java.util.List; + +/** A spawner of the pack, one file of {@code spawners/}: which entities appear where, when and how often. */ +@Desc("Represents an entity spawn during initial chunk generation") +public final class Spawner { + @MinItems(1) + @Desc("The entity spawns to add") + private List spawns = List.of(); + + @MinItems(1) + @Desc("The entity spawns to add initially. EXECUTES PER CHUNK!") + private List initialSpawns = List.of(); + + @Desc("This spawner will not spawn in a given chunk if that chunk has more than the defined amount of living entities.") + private int maxEntitiesPerChunk = 1; + + @Desc("The block of 24 hour time to contain this spawn in.") + private SpawnTimeBlock timeBlock = new SpawnTimeBlock(); + + @Desc("The weather condition required for this spawner to fire.") + private SpawnWeather weather = SpawnWeather.ANY; + + @Desc("The maximum rate this spawner can fire") + private SpawnRate maximumRate = new SpawnRate(); + + @Desc("The maximum rate this spawner can fire on a specific chunk") + private SpawnRate maximumRatePerChunk = new SpawnRate(); + + @Desc("The light levels this spawn is allowed to run in (0-15 inclusive)") + private Range allowedLightLevels = Range.of(0, 15); + + @Desc("Where should these spawns be placed") + private SpawnGroup group = SpawnGroup.NORMAL; + + public Spawner() { + } + + public List spawns() { + return spawns == null ? List.of() : Collections.unmodifiableList(spawns); + } + + public List initialSpawns() { + return initialSpawns == null ? List.of() : Collections.unmodifiableList(initialSpawns); + } + + public int maxEntitiesPerChunk() { + return maxEntitiesPerChunk; + } + + public SpawnTimeBlock timeBlock() { + return timeBlock == null ? new SpawnTimeBlock() : timeBlock; + } + + public SpawnWeather weather() { + return weather == null ? SpawnWeather.ANY : weather; + } + + public SpawnRate maximumRate() { + return maximumRate == null ? new SpawnRate() : maximumRate; + } + + public SpawnRate maximumRatePerChunk() { + return maximumRatePerChunk == null ? new SpawnRate() : maximumRatePerChunk; + } + + public Range allowedLightLevels() { + return allowedLightLevels == null ? Range.of(0, 15) : allowedLightLevels; + } + + public SpawnGroup group() { + return group == null ? SpawnGroup.NORMAL : group; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/spawn/SpawnerSettings.java b/src/main/java/art/arcane/iris/builtin/spawn/SpawnerSettings.java new file mode 100644 index 000000000..b4e976c52 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/spawn/SpawnerSettings.java @@ -0,0 +1,49 @@ +/* + * 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.spawn; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MinItems; +import com.volmit.config.ResourceRef; + +import java.util.Collections; +import java.util.List; + +/** + * The spawners one dimension, region or biome lists, written as {@code "entitySpawners": [...]}, the keys of the + * {@link Spawner}s. A chunk may fire the spawners of its dimension, region and biome. + */ +@Desc("Entity spawners that fire in this area") +@Feature(id = "iris:spawn", name = "Entity spawners", key = "entitySpawners", root = "spawners", targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) +public final class SpawnerSettings implements IrisFeature { + @MinItems(1) + @ResourceRef(Spawner.class) + @Desc("Entity spawners to add to this area") + private List spawners = List.of(); + + public SpawnerSettings() { + } + + public List spawners() { + return spawners == null ? List.of() : Collections.unmodifiableList(spawners); + } +} diff --git a/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java b/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java index e1ff26a61..55b501500 100644 --- a/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java +++ b/src/main/java/art/arcane/iris/engine/loot/BlockDropping.java @@ -18,20 +18,25 @@ package art.arcane.iris.engine.loot; +import art.arcane.iris.builtin.loot.BlockDrop; +import art.arcane.iris.builtin.loot.BlockDropSettings; +import art.arcane.iris.builtin.loot.LootEntry; +import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.core.modules.IrisPackWorld; import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.object.loot.IrisBlockDrops; +import art.arcane.iris.engine.framework.LootResolver; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.spi.IrisPlatforms; -import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.volmlib.util.collection.KList; +import art.arcane.volmlib.util.math.RNG; import com.volmit.item.ItemDrop; import com.volmit.service.BlockDrops; import com.volmit.world.PackWorld; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; /** * How {@code iris:loot} drops items for broken blocks: the block drops of the biome, the region and the dimension, the @@ -44,23 +49,53 @@ public final class BlockDropping implements BlockDrops { int x = broken.position().x(); int y = broken.position().y(); int z = broken.position().z(); - PlatformBlockState block = IrisPlatforms.get().registries().block(broken.block().key()); + String brokenKey = IrisPlatforms.get().registries().block(broken.block().key()).key(); + ResolvedDrops resolved = world.state(ResolvedDrops.class, ignored -> new ResolvedDrops()); IrisBiome biome = engine.getBiome(x, y, z); - List providers = dropsFor(biome.getBlockDrops(), block, engine); - if (providers.stream().noneMatch(IrisBlockDrops::isSkipParents)) { + List providers = dropsFor(biome, brokenKey, resolved, world); + if (providers.stream().noneMatch(provider -> provider.drop().skipParents())) { IrisRegion region = engine.getRegion(x, z); - providers.addAll(dropsFor(region.getBlockDrops(), block, engine)); - providers.addAll(dropsFor(engine.getDimension().getBlockDrops(), block, engine)); + providers.addAll(dropsFor(region, brokenKey, resolved, world)); + providers.addAll(dropsFor(engine.getDimension(), brokenKey, resolved, world)); } LootItems items = new LootItems(world.resources().items(), false); List drops = new ArrayList<>(); - providers.forEach(provider -> provider.fillDrops(items, drops)); - return new Result(drops, providers.stream().anyMatch(IrisBlockDrops::isReplaceVanillaDrops)); + providers.forEach(provider -> fillDrops(provider.drop(), items, drops)); + return new Result(drops, providers.stream().anyMatch(provider -> provider.drop().replaceVanillaDrops())); } - private static List dropsFor(KList candidates, PlatformBlockState block, Engine engine) { - return new KList<>(candidates.stream().filter(drops -> drops.shouldDropFor(block, engine.getData())).toList()); + /** Adds the items of the drops that pass their rarity to {@code into}. */ + private static void fillDrops(BlockDrop drop, LootItems items, List into) { + for (LootEntry entry : drop.drops()) { + if (!LootResolver.oneIn(RNG.r, entry.rarity())) { + continue; + } + ItemDrop given = items.give(entry, RNG.r); + if (given != null) { + into.add(given); + } + } + } + + private static List dropsFor(IrisRegistrant owner, String brokenKey, ResolvedDrops resolved, PackWorld world) { + List matching = new ArrayList<>(); + for (BlockDrop drop : owner.getModuleSettings().find(BlockDropSettings.class).map(BlockDropSettings::drops).orElse(List.of())) { + ResolvedBlockDrop candidate = resolved.of(drop, world); + if (candidate.dropsFor(brokenKey)) { + matching.add(candidate); + } + } + return matching; + } + + /** The drops of the world with their blocks resolved, once per drop. */ + private static final class ResolvedDrops { + private final ConcurrentMap byDrop = new ConcurrentHashMap<>(); + + private ResolvedBlockDrop of(BlockDrop drop, PackWorld world) { + return byDrop.computeIfAbsent(drop, key -> ResolvedBlockDrop.of(key, world.resources().blocks())); + } } } diff --git a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java index 3613ff1cb..94af45f91 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java @@ -18,22 +18,22 @@ package art.arcane.iris.engine.loot; +import art.arcane.iris.builtin.loot.LootTable; import art.arcane.iris.core.modules.IrisPackWorld; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.LootResolver; import art.arcane.iris.engine.framework.PlacedObject; -import art.arcane.iris.engine.object.loot.IrisLootTable; -import art.arcane.iris.engine.object.loot.IrisVanillaLootTable; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.spi.IrisPlatforms; import art.arcane.iris.spi.PlatformBlockState; -import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.math.RNG; import com.volmit.item.ItemDrop; import com.volmit.service.Loot; import com.volmit.world.PackWorld; +import java.util.ArrayList; import java.util.List; +import java.util.Set; /** * How {@code iris:loot} fills containers: the tables of the object placed around a container, then those of the @@ -47,36 +47,42 @@ public final class LootGiving implements Loot { int x = site.position().x(); int z = site.position().z(); int relativeY = site.position().y(); - RNG rng = LootResolver.containerRng(lootSeed(engine), x, relativeY + engine.getMinHeight(), z); + int worldY = relativeY + engine.getMinHeight(); + RNG rng = LootResolver.containerRng(lootSeed(engine), x, worldY, z); - List tables = new KList<>(); + List sources = new ArrayList<>(); boolean objectLootDefined = site.nativeLootDefined(); IrisObjectPlacement placement = site.container() == null ? null : placementAt(engine, x, relativeY, z); if (placement != null) { objectLootDefined = objectLootDefined || placement.getLoot().isNotEmpty() || placement.getVanillaLoot().isNotEmpty(); - IrisLootTable table = placement.getTable(platformState(site), engine.getData(), rng); - if (table != null) { - tables.add(table); + Source picked = placementLoot(world, engine).pick(placement, platformState(site), rng, x, worldY, z); + if (picked != null) { + sources.add(picked); if (placement.isOverrideGlobalLoot()) { - return sourcesOf(engine, site, List.of(table)); + return sources; } } } - LootTables.resolveEnvironmentSources(tables, engine, rng, x, relativeY, z, objectLootDefined, table -> table); - return sourcesOf(engine, site, tables); + LootTables.resolveEnvironmentSources(sources, engine, rng, x, relativeY, z, objectLootDefined, Table::new); + return sources; } @Override public List items(PackWorld world, Site site, String key) { Engine engine = engine(world); - IrisLootTable table = LootResources.table(engine.getData(), key); + LootTable table = LootResources.table(engine.getData(), key); if (table == null) { return List.of(); } int worldY = site.position().y() + engine.getMinHeight(); return new LootItems(world.resources().items(), site.debug()) - .draw(table, lootSeed(engine), site.position().x(), worldY, site.position().z()); + .draw(key, table, lootSeed(engine), site.position().x(), worldY, site.position().z()); + } + + private static PlacementLoot placementLoot(PackWorld world, Engine engine) { + PlatformLootTables platformTables = world.state(PlatformLootTables.class, ignored -> new PlatformLootTables()); + return new PlacementLoot(engine.getData(), platformTables::keys, lootSeed(engine)); } private static IrisObjectPlacement placementAt(Engine engine, int x, int relativeY, int z) { @@ -84,22 +90,6 @@ public final class LootGiving implements Loot { return placed == null ? null : placed.getPlacement(); } - private static List sourcesOf(Engine engine, Site site, List tables) { - int worldY = site.position().y() + engine.getMinHeight(); - List sources = new KList<>(); - for (IrisLootTable table : tables) { - if (table instanceof IrisVanillaLootTable vanilla) { - long seed = LootTables.seed(lootSeed(engine), vanilla, site.position().x(), worldY, site.position().z()); - sources.add(new PlatformTable(vanilla.getLootTableKey(), seed)); - continue; - } - if (table != null && table.getLoadKey() != null) { - sources.add(new Table(table.getLoadKey())); - } - } - return sources; - } - private static PlatformBlockState platformState(Site site) { return IrisPlatforms.get().registries().block(site.container().key()); } @@ -111,4 +101,18 @@ public final class LootGiving implements Loot { private static Engine engine(PackWorld world) { return IrisPackWorld.of(world).engine(); } + + /** The loot table keys of the platform, which do not change while a world runs. */ + private static final class PlatformLootTables { + private volatile Set keys; + + private Set keys() { + Set known = keys; + if (known == null) { + known = PlacementLoot.platformTableKeys(); + keys = known; + } + return known; + } + } } diff --git a/src/main/java/art/arcane/iris/engine/loot/LootItems.java b/src/main/java/art/arcane/iris/engine/loot/LootItems.java index d1b3247d5..1c2300261 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootItems.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootItems.java @@ -18,12 +18,12 @@ package art.arcane.iris.engine.loot; +import art.arcane.iris.builtin.loot.ItemAttributeModifier; +import art.arcane.iris.builtin.loot.LootEnchantment; +import art.arcane.iris.builtin.loot.LootEntry; +import art.arcane.iris.builtin.loot.LootSlot; +import art.arcane.iris.builtin.loot.LootTable; import art.arcane.iris.engine.framework.LootResolver; -import art.arcane.iris.engine.object.entity.IrisAttributeModifier; -import art.arcane.iris.engine.object.loot.IrisEnchantment; -import art.arcane.iris.engine.object.loot.InventorySlotType; -import art.arcane.iris.engine.object.loot.IrisLoot; -import art.arcane.iris.engine.object.loot.IrisLootTable; import art.arcane.volmlib.util.math.RNG; import com.volmit.item.ItemAttribute; import com.volmit.item.ItemDrop; @@ -54,26 +54,28 @@ public final class LootItems { } /** - * The items {@code table} gives at the spot {@code x}, {@code y}, {@code z} (world coordinates): picks entries - * from the table's own random stream until it has the number of items the table asks for or runs out of tries. + * The items {@code table}, which the pack names {@code tableKey}, gives at the spot {@code x}, {@code y}, {@code z} + * (world coordinates): picks entries from the table's own random stream until it has the number of items the table + * asks for or runs out of tries. */ - public List draw(IrisLootTable table, long lootSeed, int x, int y, int z) { + public List draw(String tableKey, LootTable table, long lootSeed, int x, int y, int z) { List drops = new ArrayList<>(); - List entries = table.getLoot(); - if (entries.isEmpty() || table.getMaxTries() <= 0) { + List entries = table.loot(); + if (entries.isEmpty() || table.maxTries() <= 0) { return drops; } - RNG rng = LootTables.rng(lootSeed, table, x, y, z); - int wanted = Math.max(0, LootResolver.inclusive(rng, table.getMinPicked(), table.getMaxPicked())); + String identity = LootTables.identity(tableKey); + RNG rng = LootTables.rng(lootSeed, identity, x, y, z); + int wanted = Math.max(0, LootResolver.inclusive(rng, table.minPicked(), table.maxPicked())); int tries = 0; - while (drops.size() < wanted && tries++ < table.getMaxTries()) { + while (drops.size() < wanted && tries++ < table.maxTries()) { int index = rng.nextInt(entries.size()); - IrisLoot entry = entries.get(index); - if (entry == null || entry.getSlotTypes() != InventorySlotType.STORAGE) { + LootEntry entry = entries.get(index); + if (entry == null || entry.slotTypes() != LootSlot.STORAGE) { continue; } - ItemDrop drop = drawEntry(entry, table, rng, lootSeed, index, x, y, z); + ItemDrop drop = drawEntry(entry, table, identity, rng, lootSeed, index, x, y, z); if (drop != null) { drops.add(drop); } @@ -82,66 +84,67 @@ public final class LootItems { } /** The item {@code entry} gives when nothing else decides whether it does, such as a block's drop or a mob's equipment; null for no item. */ - public ItemDrop give(IrisLoot entry, RNG rng) { + public ItemDrop give(LootEntry entry, RNG rng) { return resolve(entry, rng, null); } - private ItemDrop drawEntry(IrisLoot entry, IrisLootTable table, RNG rng, long lootSeed, int index, int x, int y, int z) { - long combinedRarity = LootResolver.combinedRarity(entry.getRarity(), table.getRarity()); - if (!LootTables.spatialOneIn(lootSeed, table, index, x, y, z, combinedRarity)) { + private ItemDrop drawEntry(LootEntry entry, LootTable table, String identity, RNG rng, long lootSeed, int index, int x, int y, int z) { + long combinedRarity = LootResolver.combinedRarity(entry.rarity(), table.rarity()); + if (!LootTables.spatialOneIn(lootSeed, identity, index, x, y, z, combinedRarity)) { return null; } return resolve(entry, rng, table); } - private ItemDrop resolve(IrisLoot entry, RNG rng, IrisLootTable table) { - String type = entry.getTypeKey(); + private ItemDrop resolve(LootEntry entry, RNG rng, LootTable table) { + String type = entry.type(); OptionalInt maxDurability = items.maxDurability(type); if (maxDurability.isEmpty() || isAir(type)) { return null; } - int amount = Math.max(MIN_AMOUNT, LootResolver.inclusive(rng, entry.getMinAmount(), entry.getMaxAmount())); + int amount = Math.max(MIN_AMOUNT, LootResolver.inclusive(rng, entry.minAmount(), entry.maxAmount())); List enchantments = drawEnchantments(entry, rng); List attributes = drawAttributes(entry, rng); - Double damage = maxDurability.getAsInt() > 0 ? 1D - rng.d(entry.getMinDurability(), entry.getMaxDurability()) : null; - return new ItemDrop(type, amount, entry.getDisplayName(), entry.getLore(), enchantments, attributes, - entry.isUnbreakable(), entry.getItemFlags(), entry.getCustomModel(), damage, entry.getLeatherColor(), - entry.getDyeColorKey(), entry.getCustomNbt(), debug ? sourceOf(entry, table) : null); + Double damage = maxDurability.getAsInt() > 0 ? 1D - rng.d(entry.minDurability(), entry.maxDurability()) : null; + return new ItemDrop(type, amount, entry.displayName(), entry.lore(), enchantments, attributes, + entry.unbreakable(), entry.itemFlags(), entry.customModel(), damage, entry.leatherColor(), + entry.dyeColor(), entry.customNbt(), debug ? sourceOf(entry, table) : null); } - private static List drawEnchantments(IrisLoot entry, RNG rng) { + private static List drawEnchantments(LootEntry entry, RNG rng) { List enchantments = new ArrayList<>(); - for (IrisEnchantment enchantment : entry.getEnchantments()) { - String key = enchantment.getEnchantment(); - if (key == null || key.isBlank() || rng.nextDouble() >= enchantment.getChance()) { + for (LootEnchantment enchantment : entry.enchantments()) { + String key = enchantment.enchantment(); + if (key == null || key.isBlank() || rng.nextDouble() >= enchantment.chance()) { continue; } - enchantments.add(new ItemEnchantment(key, Math.max(1, enchantment.getLevel(rng)))); + int level = LootResolver.inclusive(rng, enchantment.minLevel(), enchantment.maxLevel()); + enchantments.add(new ItemEnchantment(key, Math.max(1, level))); } return enchantments; } - private static List drawAttributes(IrisLoot entry, RNG rng) { + private static List drawAttributes(LootEntry entry, RNG rng) { List attributes = new ArrayList<>(); - for (IrisAttributeModifier modifier : entry.getAttributes()) { - if (rng.nextDouble() >= modifier.getChance()) { + for (ItemAttributeModifier modifier : entry.attributes()) { + if (rng.nextDouble() >= modifier.chance()) { continue; } - String attribute = modifier.getAttribute(); + String attribute = modifier.attribute(); if (attribute == null || attribute.isBlank()) { continue; } - attributes.add(new ItemAttribute(attribute, modifier.getName(), modifier.getOperation(), modifier.getAmount(rng))); + attributes.add(new ItemAttribute(attribute, modifier.name(), modifier.operation(), rng.d(modifier.minAmount(), modifier.maxAmount()))); } return attributes; } - private static ItemDrop.Source sourceOf(IrisLoot entry, IrisLootTable table) { + private static ItemDrop.Source sourceOf(LootEntry entry, LootTable table) { if (table == null) { - return new ItemDrop.Source(null, 0, entry.getRarity()); + return new ItemDrop.Source(null, 0, entry.rarity()); } - return new ItemDrop.Source(table.getName(), table.getRarity(), entry.getRarity()); + return new ItemDrop.Source(table.name(), table.rarity(), entry.rarity()); } private static boolean isAir(String type) { diff --git a/src/main/java/art/arcane/iris/engine/loot/LootModule.java b/src/main/java/art/arcane/iris/engine/loot/LootModule.java index 939bcccb7..aa2041db9 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootModule.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootModule.java @@ -18,6 +18,8 @@ package art.arcane.iris.engine.loot; +import art.arcane.iris.builtin.loot.BlockDropSettings; +import art.arcane.iris.builtin.loot.LootSettings; import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; @@ -26,9 +28,10 @@ import com.volmit.service.Loot; import com.volmit.stage.StageGraph; /** - * Module {@code iris:loot}: the loot tables of the pack ({@link LootResources}) and the items they and the block drops - * of the dimension, regions and biomes give. It checks the tables and the references to them ({@link LootValidator}). It has no generation stage; Iris asks it through {@link Loot} when a container is filled and through - * {@link BlockDrops} when a player breaks a block. + * Module {@code iris:loot}: the loot tables of the pack ({@link LootResources}), the {@link LootSettings} and + * {@link BlockDropSettings} that dimensions, regions and biomes declare, and the items they give. It checks the tables + * and the references to them ({@link LootValidator}). It has no generation stage; Iris asks it through {@link Loot} when + * a container is filled and through {@link BlockDrops} when a player breaks a block. */ public final class LootModule implements IrisModule { private static final String VERSION = "built-in"; @@ -44,6 +47,8 @@ public final class LootModule implements IrisModule { @Override public void register(FeatureRegistry registry) { + registry.registerSettings(LootSettings.class); + registry.registerSettings(BlockDropSettings.class); LootResources.kinds().forEach(registry::registerResourceKind); registry.registerValidator(new LootValidator()); registry.registerService(Loot.class, new LootGiving()); diff --git a/src/main/java/art/arcane/iris/engine/loot/LootResources.java b/src/main/java/art/arcane/iris/engine/loot/LootResources.java index 3c0a8faa1..b21985205 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootResources.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootResources.java @@ -18,10 +18,9 @@ package art.arcane.iris.engine.loot; +import art.arcane.iris.builtin.loot.LootTable; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.modules.IrisPackResources; -import art.arcane.iris.engine.object.loot.IrisLootTable; -import art.arcane.volmlib.util.collection.KList; import com.volmit.resource.ResourceId; import com.volmit.resource.ResourceKind; @@ -37,7 +36,7 @@ import java.util.List; */ public final class LootResources { /** Loot tables, in {@code loot/}. */ - public static final ResourceKind TABLES = ResourceKind.of("iris:loot/table", "loot", IrisLootTable.class); + public static final ResourceKind TABLES = ResourceKind.of("iris:loot/table", "loot", LootTable.class); private LootResources() { } @@ -47,7 +46,7 @@ public final class LootResources { return List.of(TABLES); } - public static IrisLootTable table(IrisData data, String key) { + public static LootTable table(IrisData data, String key) { if (key == null || key.isBlank()) { return null; } @@ -59,18 +58,6 @@ public final class LootResources { } } - /** The tables of the pack named by {@code keys}, in order, without the ones the pack lacks. */ - public static KList tables(IrisData data, List keys) { - KList tables = new KList<>(); - for (String key : keys) { - IrisLootTable table = table(data, key); - if (table != null) { - tables.add(table); - } - } - return tables; - } - /** The key of every loot table of the pack, in key order. */ public static List tableKeys(IrisData data) { return data.getPackResources().ids(TABLES.type()).stream().map(ResourceId::path).toList(); diff --git a/src/main/java/art/arcane/iris/engine/loot/LootTables.java b/src/main/java/art/arcane/iris/engine/loot/LootTables.java index 021c3c2b1..c1d0cb067 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootTables.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootTables.java @@ -18,14 +18,13 @@ package art.arcane.iris.engine.loot; +import art.arcane.iris.builtin.loot.LootMode; +import art.arcane.iris.builtin.loot.LootSettings; +import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.LootResolver; -import art.arcane.iris.engine.object.loot.IrisLootMode; -import art.arcane.iris.engine.object.loot.IrisLootReference; -import art.arcane.iris.engine.object.loot.IrisLootTable; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.region.IrisRegion; -import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.math.RNG; import java.util.List; @@ -34,42 +33,46 @@ import java.util.function.Function; /** * Which loot tables a place in the world draws from, and the random streams that draw from them: the part of loot - * that reads the pack's tables, loot references and layout. The streams themselves are - * {@link LootResolver}'s; here a table is named by its {@linkplain #identity identity}. + * that reads the pack's tables, loot settings and layout. The streams themselves are {@link LootResolver}'s; here a + * table is named by its {@linkplain #identity identity}, the key the pack names it by. */ public final class LootTables { + private static final String VANILLA_IDENTITY_PREFIX = "Vanilla "; + private LootTables() { } - /** What names a table in the random streams: its key, else its name. */ - public static String identity(IrisLootTable table) { - if (table == null) { - return ""; - } - String loadKey = table.getLoadKey(); - if (loadKey != null && !loadKey.isBlank()) { - return loadKey; - } - String name = table.getName(); - return name == null ? "" : name; + /** What names a table in the random streams: the key a pack table is named by. */ + public static String identity(String tableKey) { + return tableKey; } - public static RNG rng(long lootSeed, IrisLootTable table, int x, int y, int z) { - return LootResolver.tableRng(lootSeed, identity(table), x, y, z); + /** What names a table of the platform in the random streams. */ + public static String platformIdentity(String platformKey) { + return VANILLA_IDENTITY_PREFIX + platformKey; } - public static long seed(long lootSeed, IrisLootTable table, int x, int y, int z) { - return LootResolver.tableSeed(lootSeed, identity(table), x, y, z); + public static RNG rng(long lootSeed, String identity, int x, int y, int z) { + return LootResolver.tableRng(lootSeed, identity, x, y, z); } - public static boolean spatialOneIn(long lootSeed, IrisLootTable table, int entryIndex, int x, int y, int z, long rarity) { - return LootResolver.spatialOneIn(lootSeed, identity(table), entryIndex, x, y, z, rarity); + public static long seed(long lootSeed, String identity, int x, int y, int z) { + return LootResolver.tableSeed(lootSeed, identity, x, y, z); + } + + public static boolean spatialOneIn(long lootSeed, String identity, int entryIndex, int x, int y, int z, long rarity) { + return LootResolver.spatialOneIn(lootSeed, identity, entryIndex, x, y, z, rarity); + } + + /** The loot settings a dimension, region or biome declares; the defaults, which add nothing, when it declares none. */ + public static LootSettings settingsOf(IrisRegistrant owner) { + return owner.getModuleSettings().find(LootSettings.class).orElseGet(LootSettings::new); } /** * Adds the tables of the dimension, the region, the surface biome and (below the surface) the cave biome at a - * column to {@code sources}, as their loot references say, then scales their number by the areas' multipliers. - * {@code mapper} turns a table into the caller's own source; a null result skips it. + * column to {@code sources}, as their loot settings say, then scales their number by the areas' multipliers. + * {@code mapper} turns the key of a table into the caller's own source; a null result skips it. */ public static void resolveEnvironmentSources( List sources, @@ -79,7 +82,7 @@ public final class LootTables { int relativeY, int z, boolean objectLootDefined, - Function mapper + Function mapper ) { IrisRegion region = engine.getComplex().getRegionStream().get(x, z); IrisBiome surfaceBiome = engine.getComplex().getTrueBiomeStream().get(x, z); @@ -91,20 +94,21 @@ public final class LootTables { contextualBiome = surfaceBiome; } + LootSettings dimensionLoot = settingsOf(engine.getDimension()); + LootSettings regionLoot = settingsOf(region); + LootSettings surfaceLoot = settingsOf(surfaceBiome); boolean distinctContextualBiome = !sameBiome(surfaceBiome, contextualBiome); - double multiplier = engine.getDimension().getLoot().getMultiplier() - * region.getLoot().getMultiplier() - * surfaceBiome.getLoot().getMultiplier(); + double multiplier = dimensionLoot.multiplier() * regionLoot.multiplier() * surfaceLoot.multiplier(); if (distinctContextualBiome) { - multiplier *= contextualBiome.getLoot().getMultiplier(); + multiplier *= settingsOf(contextualBiome).multiplier(); } boolean fallback = !objectLootDefined; - injectReference(sources, engine.getDimension().getLoot(), engine, mapper, fallback); - injectReference(sources, region.getLoot(), engine, mapper, fallback); - injectReference(sources, surfaceBiome.getLoot(), engine, mapper, fallback); + injectReference(sources, dimensionLoot, engine, mapper, fallback); + injectReference(sources, regionLoot, engine, mapper, fallback); + injectReference(sources, surfaceLoot, engine, mapper, fallback); if (distinctContextualBiome) { - injectReference(sources, contextualBiome.getLoot(), engine, mapper, fallback); + injectReference(sources, settingsOf(contextualBiome), engine, mapper, fallback); } LootResolver.scaleSources(sources, multiplier, rng); } @@ -113,17 +117,17 @@ public final class LootTables { public static void injectSources( List sources, List additions, - IrisLootMode mode, + LootMode mode, boolean fallback ) { - if (mode == IrisLootMode.FALLBACK && !fallback) { + if (mode == LootMode.FALLBACK && !fallback) { return; } - if (mode == IrisLootMode.CLEAR) { + if (mode == LootMode.CLEAR) { sources.clear(); return; } - if (mode == IrisLootMode.REPLACE) { + if (mode == LootMode.REPLACE) { sources.clear(); } sources.addAll(additions); @@ -141,22 +145,16 @@ public final class LootTables { private static void injectReference( List sources, - IrisLootReference reference, + LootSettings loot, Engine engine, - Function mapper, + Function mapper, boolean fallback ) { - KList tables = reference.getLootTables(engine.getComplex()); - KList additions = new KList<>(); - for (IrisLootTable table : tables) { - if (table == null) { - continue; - } - T source = mapper.apply(table); - if (source != null) { - additions.add(source); - } - } - injectSources(sources, additions, reference.getMode(), fallback); + List additions = loot.tables().stream() + .filter(key -> LootResources.table(engine.getData(), key) != null) + .map(mapper) + .filter(Objects::nonNull) + .toList(); + injectSources(sources, additions, loot.mode(), fallback); } } diff --git a/src/main/java/art/arcane/iris/engine/loot/LootValidator.java b/src/main/java/art/arcane/iris/engine/loot/LootValidator.java index e5f256fcb..cb4fef3d0 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootValidator.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootValidator.java @@ -21,9 +21,9 @@ package art.arcane.iris.engine.loot; import art.arcane.iris.core.modules.IrisValidationContext; import art.arcane.iris.core.pack.PackIntegerChecks; import art.arcane.iris.core.pack.PackValidationIo; -import art.arcane.iris.engine.object.loot.IrisLoot; -import art.arcane.iris.engine.object.loot.IrisLootReference; -import art.arcane.iris.engine.object.loot.IrisLootTable; +import art.arcane.iris.builtin.loot.LootEntry; +import art.arcane.iris.builtin.loot.LootSettings; +import art.arcane.iris.builtin.loot.LootTable; import art.arcane.volmlib.util.json.JSONArray; import art.arcane.volmlib.util.json.JSONObject; import com.volmit.validation.Problem; @@ -162,9 +162,9 @@ public final class LootValidator implements Validator { PackIntegerChecks.requireMinimum(path + ".minPicked", minimumPicked, 0, blockingErrors); PackIntegerChecks.requireMinimum(path + ".maxPicked", maximumPicked, 1, blockingErrors); PackIntegerChecks.requireMinimum(path + ".maxTries", maximumTries, 1, blockingErrors); - PackIntegerChecks.requireMaximum(path + ".minPicked", minimumPicked, IrisLootTable.MAX_PICKED, blockingErrors); - PackIntegerChecks.requireMaximum(path + ".maxPicked", maximumPicked, IrisLootTable.MAX_PICKED, blockingErrors); - PackIntegerChecks.requireMaximum(path + ".maxTries", maximumTries, IrisLootTable.MAX_TRIES, blockingErrors); + PackIntegerChecks.requireMaximum(path + ".minPicked", minimumPicked, LootTable.MAX_PICKED, blockingErrors); + PackIntegerChecks.requireMaximum(path + ".maxPicked", maximumPicked, LootTable.MAX_PICKED, blockingErrors); + PackIntegerChecks.requireMaximum(path + ".maxTries", maximumTries, LootTable.MAX_TRIES, blockingErrors); PackIntegerChecks.requireOrdered(path + ".minPicked", minimumPicked, path + ".maxPicked", maximumPicked, blockingErrors); JSONArray entries = table.optJSONArray("loot"); @@ -189,8 +189,8 @@ public final class LootValidator implements Validator { PackIntegerChecks.requireMinimum(entryPath + ".rarity", entryRarity, 1, blockingErrors); PackIntegerChecks.requireMinimum(entryPath + ".minAmount", minimumAmount, 1, blockingErrors); PackIntegerChecks.requireMinimum(entryPath + ".maxAmount", maximumAmount, 1, blockingErrors); - PackIntegerChecks.requireMaximum(entryPath + ".minAmount", minimumAmount, IrisLoot.MAX_AMOUNT, blockingErrors); - PackIntegerChecks.requireMaximum(entryPath + ".maxAmount", maximumAmount, IrisLoot.MAX_AMOUNT, blockingErrors); + PackIntegerChecks.requireMaximum(entryPath + ".minAmount", minimumAmount, LootEntry.MAX_AMOUNT, blockingErrors); + PackIntegerChecks.requireMaximum(entryPath + ".maxAmount", maximumAmount, LootEntry.MAX_AMOUNT, blockingErrors); PackIntegerChecks.requireOrdered(entryPath + ".minAmount", minimumAmount, entryPath + ".maxAmount", maximumAmount, blockingErrors); validateLootEnchantments(entryPath, entry.opt("enchantments"), blockingErrors); @@ -256,9 +256,9 @@ public final class LootValidator implements Validator { if (!(rawMultiplier instanceof Number multiplier) || !Double.isFinite(multiplier.doubleValue()) || multiplier.doubleValue() < 0D - || multiplier.doubleValue() > IrisLootReference.MAX_MULTIPLIER) { + || multiplier.doubleValue() > LootSettings.MAX_MULTIPLIER) { blockingErrors.add(path + ".multiplier must be a finite number from 0 to " - + (int) IrisLootReference.MAX_MULTIPLIER + "."); + + (int) LootSettings.MAX_MULTIPLIER + "."); } } if (!reference.has("tables")) { diff --git a/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java b/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java new file mode 100644 index 000000000..18ef3d37f --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java @@ -0,0 +1,153 @@ +/* + * 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.loot; + +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.engine.framework.LootResolver; +import art.arcane.iris.engine.object.loot.IObjectLoot; +import art.arcane.iris.engine.object.placement.IrisObjectPlacement; +import art.arcane.iris.spi.IrisLogging; +import art.arcane.iris.spi.IrisPlatforms; +import art.arcane.iris.spi.PlatformBlockState; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.service.Loot; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * The loot table an object placement gives to one of its containers: the placement's tables and the platform's own, + * each with the blocks it applies to and a weight. A table that names the container's exact block wins over one that + * names the container's kind of block, which wins over one that names no blocks; among equals the weights pick. + */ +final class PlacementLoot { + private static final String VANILLA_NAMESPACE = "minecraft:"; + private static final char NAMESPACE_SEPARATOR = ':'; + private static final char PROPERTIES_START = '['; + + private final IrisData data; + private final Supplier> platformTables; + private final long lootSeed; + + /** @param platformTables the keys of the loot tables the platform has, asked for only when a placement names one */ + PlacementLoot(IrisData data, Supplier> platformTables, long lootSeed) { + this.data = data; + this.platformTables = platformTables; + this.lootSeed = lootSeed; + } + + /** The platform's loot table keys, which a placement may name, in the form a placement names them. */ + static Set platformTableKeys() { + return Set.copyOf(IrisPlatforms.get().registries().lootTableKeys()); + } + + /** + * The table the placement gives {@code container}, a storage chest, at the spot {@code x}, {@code worldY}, + * {@code z}; null when it gives it none. + */ + Loot.Source pick(IrisObjectPlacement placement, PlatformBlockState container, RNG rng, int x, int worldY, int z) { + Candidates candidates = new Candidates(container); + add(candidates, placement.getVanillaLoot(), name -> platformSource(name, x, worldY, z)); + add(candidates, placement.getLoot(), this::packSource); + List pool = candidates.pool(); + Candidate picked = LootResolver.pickWeighted(pool, Candidate::weight, rng); + return picked == null ? null : picked.source(); + } + + private void add(Candidates candidates, List entries, Function sourceOf) { + for (IObjectLoot entry : entries) { + if (entry == null || entry.getWeight() <= 0) { + continue; + } + Loot.Source source = sourceOf.apply(entry.getName()); + if (source == null) { + IrisLogging.warn("Couldn't find loot table " + entry.getName()); + continue; + } + candidates.add(entry, data, new Candidate(source, entry.getWeight())); + } + } + + private Loot.Source packSource(String key) { + return LootResources.table(data, key) == null ? null : new Loot.Table(key); + } + + private Loot.Source platformSource(String name, int x, int worldY, int z) { + String key = platformKey(name); + if (key == null || !platformTables.get().contains(key)) { + return null; + } + return new Loot.PlatformTable(key, LootTables.seed(lootSeed, LootTables.platformIdentity(key), x, worldY, z)); + } + + /** A placement's name for a platform table as the platform's key for it, or null for a name that cannot be one. */ + static String platformKey(String name) { + if (name == null || name.isBlank()) { + return null; + } + return name.indexOf(NAMESPACE_SEPARATOR) < 0 ? VANILLA_NAMESPACE + name : name; + } + + private record Candidate(Loot.Source source, int weight) { + } + + /** The candidates for one container, in the groups the placement gives them. */ + private static final class Candidates { + private final String containerKey; + private final String containerMaterial; + private final List exact = new ArrayList<>(); + private final List basic = new ArrayList<>(); + private final List global = new ArrayList<>(); + + private Candidates(PlatformBlockState container) { + this.containerKey = container.key(); + this.containerMaterial = materialOf(containerKey); + } + + void add(IObjectLoot entry, IrisData data, Candidate candidate) { + List filter = entry.getFilter(data); + if (filter.isEmpty()) { + global.add(candidate); + return; + } + for (PlatformBlockState filterState : filter) { + if (entry.isExact() && filterState.key().equals(containerKey)) { + exact.add(candidate); + } else if (!entry.isExact() && materialOf(filterState.key()).equals(containerMaterial)) { + basic.add(candidate); + } + } + } + + List pool() { + if (!exact.isEmpty()) { + return exact; + } + return basic.isEmpty() ? global : basic; + } + + private static String materialOf(String blockKey) { + int properties = blockKey.indexOf(PROPERTIES_START); + return properties < 0 ? blockKey : blockKey.substring(0, properties); + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java b/src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java new file mode 100644 index 000000000..d42367c31 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/loot/ResolvedBlockDrop.java @@ -0,0 +1,72 @@ +/* + * 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.loot; + +import art.arcane.iris.builtin.loot.BlockDrop; +import art.arcane.iris.spi.IrisPlatforms; +import art.arcane.iris.spi.PlatformBlockState; +import com.volmit.block.BlockRegistry; +import com.volmit.block.BlockSpec; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** A {@link BlockDrop} with the blocks it names resolved to the platform's: which broken blocks it drops for. */ +final class ResolvedBlockDrop { + private static final char PROPERTIES_START = '['; + + private final BlockDrop drop; + private final boolean exact; + private final Set blocks; + + private ResolvedBlockDrop(BlockDrop drop, Set blocks) { + this.drop = drop; + this.exact = drop.exactBlocks(); + this.blocks = blocks; + } + + /** @param blocks the pack's blocks, which the drop's block specs resolve against */ + static ResolvedBlockDrop of(BlockDrop drop, BlockRegistry blocks) { + Set keys = new LinkedHashSet<>(); + for (BlockSpec spec : drop.blocks()) { + PlatformBlockState state = IrisPlatforms.get().registries().block(blocks.resolve(spec).key()); + if (state != null) { + keys.add(comparable(state.key(), drop.exactBlocks())); + } + } + return new ResolvedBlockDrop(drop, keys); + } + + BlockDrop drop() { + return drop; + } + + /** Whether the drop applies to {@code brokenKey}, the platform's key for the broken block: its exact state, or just its kind of block. */ + boolean dropsFor(String brokenKey) { + return blocks.contains(comparable(brokenKey, exact)); + } + + private static String comparable(String key, boolean exact) { + if (exact) { + return key; + } + int properties = key.indexOf(PROPERTIES_START); + return properties < 0 ? key : key.substring(0, properties); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/annotations/RegistryListResource.java b/src/main/java/art/arcane/iris/engine/object/annotations/RegistryListResource.java index 7f8e40b19..24f1568b0 100644 --- a/src/main/java/art/arcane/iris/engine/object/annotations/RegistryListResource.java +++ b/src/main/java/art/arcane/iris/engine/object/annotations/RegistryListResource.java @@ -18,8 +18,6 @@ package art.arcane.iris.engine.object.annotations; -import art.arcane.iris.core.loader.IrisRegistrant; - import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -31,5 +29,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) public @interface RegistryListResource { - Class value(); + /** The class pack resources of the kind are read into: an Iris resource or the class of a module resource kind. */ + Class value(); } diff --git a/src/main/java/art/arcane/iris/engine/object/entity/IrisEffect.java b/src/main/java/art/arcane/iris/engine/object/entity/IrisEffect.java deleted file mode 100644 index b07f836ad..000000000 --- a/src/main/java/art/arcane/iris/engine/object/entity/IrisEffect.java +++ /dev/null @@ -1,288 +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.entity; - -import art.arcane.iris.engine.object.marker.IrisCommandRegistry; -import art.arcane.iris.engine.data.cache.AtomicCache; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.object.annotations.DependsOn; -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.RegistryListPotionEffect; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.spi.IrisLogging; -import art.arcane.volmlib.util.math.RNG; -import art.arcane.volmlib.util.scheduling.ChronoLatch; -import art.arcane.iris.util.common.data.registry.RegistryUtil; -import art.arcane.iris.util.common.scheduling.J; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Sound; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.Vector; - -@Snippet("effect") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("An iris effect") -@Data -public class IrisEffect { - private final transient AtomicCache pt = new AtomicCache<>(); - private final transient AtomicCache latch = new AtomicCache<>(); - private final transient AtomicCache particleEffectResolved = new AtomicCache<>(); - private final transient AtomicCache soundResolved = new AtomicCache<>(); - @RegistryListPotionEffect - @Desc("The potion effect to apply in this area") - private String potionEffect = ""; - @Desc("The particle effect to apply in the area") - private String particleEffect = null; - @DependsOn({"particleEffect"}) - @MinNumber(-32) - @MaxNumber(32) - @Desc("Randomly offset from the surface to this surface+value") - private int particleOffset = 0; - @DependsOn({"particleEffect"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") - private double particleAltX = 0; - @DependsOn({"particleEffect"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") - private double particleAltY = 0; - @DependsOn({"particleEffect"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") - private double particleAltZ = 0; - @DependsOn({"particleEffect"}) - @Desc("Randomize the altX by -altX to altX") - private boolean randomAltX = true; - @DependsOn({"particleEffect"}) - @Desc("Randomize the altY by -altY to altY") - private boolean randomAltY = false; - @DependsOn({"particleEffect"}) - @Desc("Randomize the altZ by -altZ to altZ") - private boolean randomAltZ = true; - @Desc("The sound to play") - private String sound = null; - @DependsOn({"sound"}) - @MinNumber(0) - @MaxNumber(512) - @Desc("The max distance from the player the sound will play") - private int soundDistance = 12; - @DependsOn({"sound", "maxPitch"}) - @MinNumber(0.01) - @MaxNumber(1.99) - @Desc("The minimum sound pitch") - private double minPitch = 0.5D; - @DependsOn({"sound", "minVolume"}) - @MinNumber(0.01) - @MaxNumber(1.99) - @Desc("The max sound pitch") - private double maxPitch = 1.5D; - @DependsOn({"sound"}) - @MinNumber(0.001) - @MaxNumber(512) - @Desc("The sound volume.") - private double volume = 1.5D; - @DependsOn({"particleEffect"}) - @MinNumber(0) - @MaxNumber(512) - @Desc("The particle count. Try setting to zero for using the alt xyz to a motion value instead of an offset") - private int particleCount = 0; - @DependsOn({"particleEffect"}) - @MinNumber(0) - @MaxNumber(64) - @Desc("How far away from the player particles can play") - private int particleDistance = 20; - @DependsOn({"particleEffect"}) - @MinNumber(0) - @MaxNumber(128) - @Desc("How wide the particles can play (player's view left and right) RADIUS") - private int particleDistanceWidth = 24; - @DependsOn({"particleEffect"}) - @Desc("An extra value for some particles... Which bukkit doesn't even document.") - private double extra = 0; - @DependsOn({"potionEffect"}) - @MinNumber(-1) - @MaxNumber(1024) - @Desc("The Potion Strength or -1 to disable") - private int potionStrength = -1; - @DependsOn({"potionEffect", "potionTicksMin"}) - @MinNumber(1) - @Desc("The max time the potion will last for") - private int potionTicksMax = 155; - @DependsOn({"potionEffect", "potionTicksMax"}) - @MinNumber(1) - @Desc("The min time the potion will last for") - private int potionTicksMin = 75; - @Required - @MinNumber(0) - @Desc("The effect interval in milliseconds") - private int interval = 150; - @DependsOn({"particleEffect"}) - @MinNumber(0) - @MaxNumber(16) - @Desc("The effect distance start away") - private int particleAway = 5; - @Required - @MinNumber(1) - @Desc("The chance is 1 in CHANCE per interval") - private int chance = 50; - @Desc("Run commands, with configurable location parameters") - private IrisCommandRegistry commandRegistry = null; - - - public boolean canTick() { - return latch.aquire(() -> new ChronoLatch(interval)).flip(); - } - - public boolean shouldApplyNow() { - return canTick() && RNG.r.nextInt(chance) == 0; - } - - public String getParticleEffectKey() { - return particleEffect; - } - - public String getSoundKey() { - return sound; - } - - public Particle getParticleEffect() { - if (particleEffect == null) { - return null; - } - return particleEffectResolved.aquire(() -> resolveKeyed(Particle.class, particleEffect)); - } - - public Sound getSound() { - if (sound == null) { - return null; - } - return soundResolved.aquire(() -> resolveKeyed(Sound.class, sound)); - } - - private static T resolveKeyed(Class type, String key) { - NamespacedKey namespacedKey = NamespacedKey.fromString(key); - return namespacedKey == null ? null : RegistryUtil.lookup(type).get(namespacedKey); - } - - public PotionEffectType getRealType() { - return pt.aquire(() -> - { - if (getPotionEffect() == null || getPotionEffect().isEmpty()) { - return PotionEffectType.LUCK; - } - - try { - PotionEffectType resolved = PotionEffectTypes.resolve(getPotionEffect()); - if (resolved != null) { - return resolved; - } - } catch (Throwable e) { - IrisLogging.reportError(e); - } - - if (PotionEffectTypes.shouldWarn(getPotionEffect())) { - IrisLogging.warn("Unknown Potion Effect Type: \"" + getPotionEffect() + "\". Valid types: " + PotionEffectTypes.knownTypesList()); - } - - return PotionEffectType.LUCK; - }); - } - - private static final class BukkitFx { - private static void run(Player p, Runnable r) { - J.runEntity(p, r); - } - } - - public void apply(Player p, Engine g) { - if (!shouldApplyNow()) { - return; - } - - BukkitFx.run(p, () -> { - Sound soundType = getSound(); - Particle particleType = getParticleEffect(); - if (soundType != null) { - Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance)); - p.playSound(part, soundType, (float) volume, (float) RNG.r.d(minPitch, maxPitch)); - } - - if (particleType != null) { - Location part = p.getLocation().clone().add(p.getLocation().getDirection().clone().multiply(RNG.r.i(particleDistance) + particleAway)).clone().add(p.getLocation().getDirection().clone().rotateAroundY(Math.toRadians(90)).multiply(RNG.r.d(-particleDistanceWidth, particleDistanceWidth))); - - part.setY(Math.round(g.getHeight(part.getBlockX(), part.getBlockZ())) + 1); - part.add(RNG.r.d(), 0, RNG.r.d()); - int offset = p.getWorld().getMinHeight(); - if (extra != 0) { - p.spawnParticle(particleType, part.getX(), part.getY() + offset + RNG.r.i(particleOffset), - part.getZ(), - particleCount, - randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, - randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, - randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ, - extra); - } else { - p.spawnParticle(particleType, part.getX(), part.getY() + offset + RNG.r.i(particleOffset), part.getZ(), - particleCount, - randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX, - randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY, - randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ); - } - } - - if (commandRegistry != null) { - commandRegistry.run(p); - } - - if (potionStrength > -1) { - if (p.hasPotionEffect(getRealType())) { - PotionEffect e = p.getPotionEffect(getRealType()); - if (e != null && e.getAmplifier() > getPotionStrength()) { - return; - } - - p.removePotionEffect(getRealType()); - } - - p.addPotionEffect(new PotionEffect(getRealType(), - RNG.r.i(Math.min(potionTicksMax, potionTicksMin), - Math.max(potionTicksMax, potionTicksMin)), - getPotionStrength(), - true, false, false)); - } - }); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/entity/IrisEntitySpawn.java b/src/main/java/art/arcane/iris/engine/object/entity/IrisEntitySpawn.java deleted file mode 100644 index 1332e3bf0..000000000 --- a/src/main/java/art/arcane/iris/engine/object/entity/IrisEntitySpawn.java +++ /dev/null @@ -1,66 +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.entity; - -import art.arcane.iris.engine.spawn.SpawnResources; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; -import art.arcane.iris.engine.object.marker.IrisMarker; -import art.arcane.iris.engine.object.value.IRare; -import art.arcane.iris.engine.data.cache.AtomicCache; -import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.MinNumber; -import art.arcane.iris.engine.object.annotations.RegistryListResource; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.volmlib.util.math.RNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -@Snippet("entity-spawn") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Represents an entity spawn during initial chunk generation") -@Data -public class IrisEntitySpawn implements IRare { - private final transient AtomicCache rng = new AtomicCache<>(); - private final transient AtomicCache ent = new AtomicCache<>(); - @RegistryListResource(IrisEntity.class) - @Required - @Desc("The entity") - private String entity = ""; - @MinNumber(1) - @Desc("The 1 in RARITY chance for this entity to spawn") - private int rarity = 1; - @MinNumber(1) - @Desc("The minumum of this entity to spawn") - private int minSpawns = 1; - @MinNumber(1) - @Desc("The max of this entity to spawn") - private int maxSpawns = 1; - private transient IrisSpawner referenceSpawner; - private transient IrisMarker referenceMarker; - - public IrisEntity getRealEntity(Engine g) { - return ent.aquire(() -> SpawnResources.entity(g.getData(), getEntity())); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/entity/IrisPotionEffect.java b/src/main/java/art/arcane/iris/engine/object/entity/IrisPotionEffect.java deleted file mode 100644 index f837f5cfd..000000000 --- a/src/main/java/art/arcane/iris/engine/object/entity/IrisPotionEffect.java +++ /dev/null @@ -1,102 +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.entity; - -import art.arcane.iris.engine.data.cache.AtomicCache; -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.RegistryListPotionEffect; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.spi.IrisLogging; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; -import org.bukkit.entity.LivingEntity; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor - -@Snippet("potion-effect") -@Desc("An iris potion effect") -@Data -public class IrisPotionEffect { - private final transient AtomicCache pt = new AtomicCache<>(); - @Required - @RegistryListPotionEffect - @Desc("The potion effect to apply in this area") - private String potionEffect = ""; - @Required - @MinNumber(-1) - @MaxNumber(1024) - @Desc("The Potion Strength or -1 to disable") - private int strength = -1; - @Required - @MinNumber(1) - @Desc("The time the potion will last for") - private int ticks = 200; - @Desc("Is the effect ambient") - private boolean ambient = false; - @Desc("Is the effect showing particles") - private boolean particles = true; - - public PotionEffectType getRealType() { - return pt.aquire(() -> - { - if (getPotionEffect() == null || getPotionEffect().isEmpty()) { - return PotionEffectType.LUCK; - } - - try { - PotionEffectType resolved = PotionEffectTypes.resolve(getPotionEffect()); - if (resolved != null) { - return resolved; - } - } catch (Throwable e) { - IrisLogging.reportError(e); - } - - if (PotionEffectTypes.shouldWarn(getPotionEffect())) { - IrisLogging.warn("Unknown Potion Effect Type: \"" + getPotionEffect() + "\". Valid types: " + PotionEffectTypes.knownTypesList()); - } - - return PotionEffectType.LUCK; - }); - } - - public void apply(LivingEntity p) { - if (strength > -1) { - if (p.hasPotionEffect(getRealType())) { - PotionEffect e = p.getPotionEffect(getRealType()); - if (e.getAmplifier() > strength) { - return; - } - - p.removePotionEffect(getRealType()); - } - - p.addPotionEffect(new PotionEffect(getRealType(), ticks, strength, ambient, particles, false)); - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/entity/PotionEffectTypes.java b/src/main/java/art/arcane/iris/engine/object/entity/PotionEffectTypes.java deleted file mode 100644 index 7d2a55222..000000000 --- a/src/main/java/art/arcane/iris/engine/object/entity/PotionEffectTypes.java +++ /dev/null @@ -1,98 +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.entity; - -import art.arcane.iris.util.common.reflect.KeyedType; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.potion.PotionEffectType; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.ConcurrentHashMap; - -public final class PotionEffectTypes { - private static final Map LEGACY_ALIASES; - private static final Set MISSING_WARNED = ConcurrentHashMap.newKeySet(); - - static { - Map m = new HashMap<>(); - m.put("SLOW", "SLOWNESS"); - m.put("FAST_DIGGING", "HASTE"); - m.put("SLOW_DIGGING", "MINING_FATIGUE"); - m.put("INCREASE_DAMAGE", "STRENGTH"); - m.put("HEAL", "INSTANT_HEALTH"); - m.put("HARM", "INSTANT_DAMAGE"); - m.put("JUMP", "JUMP_BOOST"); - m.put("CONFUSION", "NAUSEA"); - m.put("DAMAGE_RESISTANCE", "RESISTANCE"); - LEGACY_ALIASES = Collections.unmodifiableMap(m); - } - - private PotionEffectTypes() { - } - - public static String normalize(String input) { - if (input == null) { - return ""; - } - String upper = input.trim().toUpperCase(Locale.ROOT).replace(' ', '_'); - if (upper.contains(":")) { - upper = upper.substring(upper.indexOf(':') + 1); - } - return LEGACY_ALIASES.getOrDefault(upper, upper); - } - - public static PotionEffectType resolve(String rawName) { - if (rawName == null || rawName.trim().isEmpty()) { - return null; - } - String wanted = normalize(rawName); - for (PotionEffectType i : Registry.EFFECT) { - NamespacedKey key = KeyedType.getKey(i); - if (key == null) { - continue; - } - String candidate = key.getKey().toUpperCase(Locale.ROOT).replace(' ', '_'); - if (candidate.equals(wanted)) { - return i; - } - } - return null; - } - - public static String knownTypesList() { - TreeSet names = new TreeSet<>(); - for (PotionEffectType i : Registry.EFFECT) { - NamespacedKey key = KeyedType.getKey(i); - if (key != null) { - names.add(key.getKey().toUpperCase(Locale.ROOT).replace(' ', '_')); - } - } - return String.join(", ", names); - } - - public static boolean shouldWarn(String rawName) { - return MISSING_WARNED.add(normalize(rawName)); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisEngineSpawnerCooldown.java b/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisEngineSpawnerCooldown.java index 2f1049b29..0a1db5c1b 100644 --- a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisEngineSpawnerCooldown.java +++ b/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisEngineSpawnerCooldown.java @@ -18,8 +18,6 @@ package art.arcane.iris.engine.object.entity.spawn; -import art.arcane.iris.engine.object.value.IrisRate; -import art.arcane.iris.engine.framework.Engine; import art.arcane.volmlib.util.math.M; import lombok.Data; @@ -28,11 +26,11 @@ public class IrisEngineSpawnerCooldown { private long lastSpawn = 0; private String spawner; - public void spawn(Engine engine) { + public void spawn() { lastSpawn = M.ms(); } - public boolean canSpawn(IrisRate s) { - return M.ms() - lastSpawn > s.getInterval(); + public boolean canSpawn(long intervalMilliseconds) { + return M.ms() - lastSpawn > intervalMilliseconds; } } diff --git a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawner.java b/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawner.java deleted file mode 100644 index fdaad9401..000000000 --- a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawner.java +++ /dev/null @@ -1,142 +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.entity.spawn; - -import art.arcane.iris.engine.object.entity.IrisEntitySpawn; -import art.arcane.iris.engine.object.marker.IrisMarker; -import art.arcane.iris.engine.object.value.IrisRange; -import art.arcane.iris.engine.object.value.IrisRate; -import art.arcane.iris.engine.object.world.IrisTimeBlock; -import art.arcane.iris.engine.object.world.IrisWeather; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.core.loader.IrisRegistrant; -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.spi.PlatformWorld; -import art.arcane.volmlib.util.collection.KList; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -@EqualsAndHashCode(callSuper = true) -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Represents an entity spawn during initial chunk generation") -@Data -public class IrisSpawner extends IrisRegistrant { - - private transient IrisMarker referenceMarker; - - @ArrayType(min = 1, type = IrisEntitySpawn.class) - @Desc("The entity spawns to add") - private KList spawns = new KList<>(); - - @ArrayType(min = 1, type = IrisEntitySpawn.class) - @Desc("The entity spawns to add initially. EXECUTES PER CHUNK!") - private KList initialSpawns = new KList<>(); - - @Desc("This spawner will not spawn in a given chunk if that chunk has more than the defined amount of living entities.") - private int maxEntitiesPerChunk = 1; - - @Desc("The block of 24 hour time to contain this spawn in.") - private IrisTimeBlock timeBlock = new IrisTimeBlock(); - - @Desc("The weather condition required for this spawner to fire.") - private IrisWeather weather = IrisWeather.ANY; - - @Desc("The maximum rate this spawner can fire") - private IrisRate maximumRate = new IrisRate(); - - @Desc("The maximum rate this spawner can fire on a specific chunk") - private IrisRate maximumRatePerChunk = new IrisRate(); - - @Desc("The light levels this spawn is allowed to run in (0-15 inclusive)") - private IrisRange allowedLightLevels = new IrisRange(0, 15); - - @Desc("Where should these spawns be placed") - private IrisSpawnGroup group = IrisSpawnGroup.NORMAL; - - public boolean isValid(IrisBiome biome) { - return switch (group) { - case NORMAL -> switch (biome.getInferredType()) { - case SHORE, SEA, CAVE -> false; - case LAND -> true; - }; - case CAVE -> true; - case UNDERWATER -> switch (biome.getInferredType()) { - case SHORE, LAND, CAVE -> false; - case SEA -> true; - }; - case BEACH -> switch (biome.getInferredType()) { - case SHORE -> true; - case LAND, CAVE, SEA -> false; - }; - }; - } - - public boolean isValid(PlatformWorld world) { - return timeBlock.isWithin(world) && weather.is(world); - } - - public boolean canSpawn(Engine engine) { - PlatformWorld world = engine.getWorld().platformWorld(); - if (world == null || !isValid(world)) - return false; - - IrisRate rate = getMaximumRate(); - return rate.isInfinite() || engine.getEngineData().getCooldown(this).canSpawn(rate); - } - - public boolean canSpawn(Engine engine, int x, int z) { - if (!canSpawn(engine)) - return false; - - IrisRate rate = getMaximumRatePerChunk(); - return rate.isInfinite() || engine.getEngineData().getChunk(x, z).getCooldown(this).canSpawn(rate); - } - - public void spawn(Engine engine) { - if (getMaximumRate().isInfinite()) - return; - - engine.getEngineData().getCooldown(this).spawn(engine); - } - - public void spawn(Engine engine, int x, int z) { - spawn(engine); - if (getMaximumRatePerChunk().isInfinite()) - return; - - engine.getEngineData().getChunk(x, z).getCooldown(this).spawn(engine); - } - - @Override - public String getFolderName() { - return "spawners"; - } - - @Override - public String getTypeName() { - return "Spawner"; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java b/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java index 7fdcb744a..7b12a24b6 100644 --- a/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java +++ b/src/main/java/art/arcane/iris/engine/object/entity/spawn/IrisSpawnerCooldowns.java @@ -1,5 +1,6 @@ package art.arcane.iris.engine.object.entity.spawn; +import art.arcane.iris.builtin.spawn.Spawner; import art.arcane.iris.engine.spawn.SpawnResources; import art.arcane.iris.engine.framework.Engine; import art.arcane.volmlib.util.collection.KMap; @@ -10,10 +11,6 @@ import lombok.NonNull; public class IrisSpawnerCooldowns { private final KMap cooldowns = new KMap<>(); - public IrisEngineSpawnerCooldown getCooldown(@NonNull IrisSpawner spawner) { - return getCooldown(spawner.getLoadKey()); - } - public IrisEngineSpawnerCooldown getCooldown(@NonNull String loadKey) { return cooldowns.computeIfAbsent(loadKey, k -> { IrisEngineSpawnerCooldown cd = new IrisEngineSpawnerCooldown(); @@ -24,8 +21,8 @@ public class IrisSpawnerCooldowns { public void cleanup(Engine engine) { cooldowns.values().removeIf(cd -> { - IrisSpawner sp = SpawnResources.spawner(engine.getData(), cd.getSpawner()); - return sp == null || cd.canSpawn(sp.getMaximumRate()); + Spawner spawner = SpawnResources.spawner(engine.getData(), cd.getSpawner()); + return spawner == null || cd.canSpawn(spawner.maximumRate().interval()); }); } diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisBlockDrops.java b/src/main/java/art/arcane/iris/engine/object/loot/IrisBlockDrops.java deleted file mode 100644 index c3c26608c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisBlockDrops.java +++ /dev/null @@ -1,105 +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.loot; - -import art.arcane.iris.engine.object.material.IrisBlockData; -import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.data.cache.AtomicCache; -import art.arcane.iris.engine.framework.LootResolver; -import art.arcane.iris.engine.loot.LootItems; -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.RNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import art.arcane.iris.spi.PlatformBlockState; -import lombok.experimental.Accessors; -import com.volmit.item.ItemDrop; - -import java.util.List; - -@Snippet("block-drops") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Represents a block drop list") -@Data -public class IrisBlockDrops { - private final transient AtomicCache> data = new AtomicCache<>(); - @Required - @ArrayType(min = 1, type = IrisBlockData.class) - @Desc("The blocks that drop loot") - private KList blocks = new KList<>(); - @Desc("If exact blocks is set to true, minecraft:barrel[axis=x] will only drop for that axis. When exact is false (default) any barrel will drop the defined drops.") - private boolean exactBlocks = false; - @Desc("Add in specific items to drop") - @ArrayType(min = 1, type = IrisLoot.class) - private KList drops = new KList<>(); - @Desc("If this is in a biome, setting skipParents to true will ignore the drops in the region and dimension for this block type. The default (false) will allow all three nodes to fire and add to a list of drops.") - private boolean skipParents = false; - @Desc("Removes the default vanilla block drops and only drops the given items & any parent loot tables specified for this block type.") - private boolean replaceVanillaDrops = false; - - public boolean shouldDropFor(PlatformBlockState broken, IrisData rdata) { - KList list = this.data.aquire(() -> { - KList b = new KList<>(); - - for (IrisBlockData i : getBlocks()) { - PlatformBlockState state = i.getBlockData(rdata); - - if (state != null) { - b.add(state); - } - } - - return b.removeDuplicates(); - }); - - for (PlatformBlockState i : list) { - if (exactBlocks ? i.key().equals(broken.key()) : materialOf(i).equals(materialOf(broken))) { - return true; - } - } - - return false; - } - - /** Adds the items of the drops that pass their rarity to {@code d}. */ - public void fillDrops(LootItems items, List d) { - for (IrisLoot i : getDrops()) { - if (!LootResolver.oneIn(RNG.r, i.getRarity())) { - continue; - } - ItemDrop drop = items.give(i, RNG.r); - if (drop != null) { - d.add(drop); - } - } - } - - private static String materialOf(PlatformBlockState state) { - String key = state.key(); - int properties = key.indexOf('['); - return properties < 0 ? key : key.substring(0, properties); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisLoot.java b/src/main/java/art/arcane/iris/engine/object/loot/IrisLoot.java deleted file mode 100644 index 57f699664..000000000 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisLoot.java +++ /dev/null @@ -1,113 +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.loot; - -import art.arcane.iris.engine.object.entity.IrisAttributeModifier; -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.RegistryListItemType; -import art.arcane.iris.engine.object.annotations.Required; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.collection.KMap; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.ToString; -import lombok.experimental.Accessors; - -@Snippet("loot") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Represents a loot entry") -@Data -@EqualsAndHashCode(doNotUseGetters = true) -@ToString(doNotUseGetters = true) -public class IrisLoot { - public static final int MAX_AMOUNT = 64; - - @Desc("The target inventory slot types to fill this loot with. World generation only ever fills STORAGE; the other values are inert during worldgen.") - private InventorySlotType slotTypes = InventorySlotType.STORAGE; - @MinNumber(1) - @Desc("The sub rarity of this loot. Calculated after this loot table has been picked.") - private int rarity = 1; - @MinNumber(1) - @MaxNumber(MAX_AMOUNT) - @Desc("Minimum amount of this loot, from 1 to 64") - private int minAmount = 1; - @MinNumber(1) - @MaxNumber(MAX_AMOUNT) - @Desc("Maximum amount of this loot, from 1 to 64") - private int maxAmount = 1; - @MinNumber(1) - @Desc("The display name of this item") - private String displayName = null; - @MinNumber(0) - @MaxNumber(1) - @Desc("Minimum durability percent") - private double minDurability = 0; - @MinNumber(0) - @MaxNumber(1) - @Desc("Maximum durability percent") - private double maxDurability = 1; - @Desc("Define a custom model identifier 1.14+ only") - private Integer customModel = null; - @Desc("Set this to true to prevent it from being broken") - private boolean unbreakable = false; - @ArrayType(min = 1, type = String.class) - @Desc("The item flags to add") - private KList itemFlags = new KList<>(); - @Desc("Apply enchantments to this item") - @ArrayType(min = 1, type = IrisEnchantment.class) - private KList enchantments = new KList<>(); - @Desc("Apply attribute modifiers to this item") - @ArrayType(min = 1, type = IrisAttributeModifier.class) - private KList attributes = new KList<>(); - @ArrayType(min = 1, type = String.class) - @Desc("Add lore to this item") - private KList lore = new KList<>(); - @RegistryListItemType - @Required - @Desc("This is the item or block type. Does not accept minecraft:*, only materials such as DIAMOND_SWORD or DIRT. The exception are modded materials, as they require a namespace.") - private String type = ""; - @Desc("The dye color") - private String dyeColor = null; - @Desc("The leather armor color") - private String leatherColor = null; - @Desc("Defines a custom NBT Tag for the item.") - private KMap customNbt; - - /** - * The authored item key, exactly as written in the pack. Each platform resolves it against its own item registry. - */ - public String getTypeKey() { - return type; - } - - /** - * The authored dye colour name, or null when unset. - */ - public String getDyeColorKey() { - return dyeColor; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisLootReference.java b/src/main/java/art/arcane/iris/engine/object/loot/IrisLootReference.java deleted file mode 100644 index 598555154..000000000 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisLootReference.java +++ /dev/null @@ -1,69 +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.loot; - -import art.arcane.iris.engine.loot.LootResources; -import art.arcane.iris.engine.data.cache.AtomicCache; -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.RegistryListResource; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.iris.util.common.data.DataProvider; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -@Snippet("loot-registry") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Represents a loot entry") -@Data -public class IrisLootReference { - public static final double MAX_MULTIPLIER = 16D; - - private final transient AtomicCache> tt = new AtomicCache<>(); - @Desc("ADD = add on top of parent tables. REPLACE = clear parent tables, then add these. CLEAR = clear parent tables and add nothing, even if tables are listed. FALLBACK = only used when nothing else defined a table.") - private IrisLootMode mode = IrisLootMode.ADD; - @RegistryListResource(IrisLootTable.class) - @ArrayType(min = 1, type = String.class) - @Desc("Add loot table registries here") - private KList tables = new KList<>(); - @MinNumber(0) - @MaxNumber(MAX_MULTIPLIER) - @Desc("Scale loot sources in this area from 0 to 16 times their normal count") - private double multiplier = 1D; - - public KList getLootTables(DataProvider g) { - return tt.aquire(() -> - { - KList t = new KList<>(); - - for (String i : tables) { - t.add(LootResources.table(g.getData(), i)); - } - - return t; - }); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectLoot.java b/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectLoot.java index ec5b70e77..076519f06 100644 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectLoot.java +++ b/src/main/java/art/arcane/iris/engine/object/loot/IrisObjectLoot.java @@ -18,6 +18,7 @@ package art.arcane.iris.engine.object.loot; +import art.arcane.iris.builtin.loot.LootTable; import art.arcane.iris.engine.object.material.IrisBlockData; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.data.cache.AtomicCache; @@ -50,7 +51,7 @@ public class IrisObjectLoot implements IObjectLoot { private boolean exact = false; @Desc("The loot table name") @Required - @RegistryListResource(IrisLootTable.class) + @RegistryListResource(LootTable.class) private String name; @Desc("The weight of this loot table being chosen") @MinNumber(1) diff --git a/src/main/java/art/arcane/iris/engine/object/loot/IrisVanillaLootTable.java b/src/main/java/art/arcane/iris/engine/object/loot/IrisVanillaLootTable.java deleted file mode 100644 index d4a207804..000000000 --- a/src/main/java/art/arcane/iris/engine/object/loot/IrisVanillaLootTable.java +++ /dev/null @@ -1,73 +0,0 @@ -package art.arcane.iris.engine.object.loot; - -import art.arcane.iris.core.loader.IrisData; -import art.arcane.volmlib.util.collection.KList; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.File; - -@Data -@EqualsAndHashCode(callSuper = false) -public class IrisVanillaLootTable extends IrisLootTable { - /** - * The vanilla loot table key ("minecraft:chests/simple_dungeon"), not the LootTable itself. A - * raw org.bukkit.loot.LootTable field - and the constructor lombok would generate for it - makes - * every reflective walk over the IrisLootTable hierarchy (Gson, schema generation, the purity - * gate) resolve a Bukkit class. The host resolves the table when it pulls loot from it. The key text is - * identical to what {@code LootTable.getKey().toString()} produced before, so - * {@code LootTables.identity} (which falls back to - * {@link #getName()}) yields the same loot seed. - */ - private final String lootTableKey; - - @Override - public String getName() { - return "Vanilla " + lootTableKey; - } - - @Override - public int getRarity() { - return 0; - } - - @Override - public int getMaxPicked() { - return 0; - } - - @Override - public int getMinPicked() { - return 0; - } - - @Override - public int getMaxTries() { - return 0; - } - - @Override - public KList getLoot() { - return new KList<>(); - } - - @Override - public String getFolderName() { - throw new UnsupportedOperationException("VanillaLootTables do not have a folder name"); - } - - @Override - public String getTypeName() { - throw new UnsupportedOperationException("VanillaLootTables do not have a type name"); - } - - @Override - public File getLoadFile() { - throw new UnsupportedOperationException("VanillaLootTables do not have a load file"); - } - - @Override - public IrisData getLoader() { - throw new UnsupportedOperationException("VanillaLootTables do not have a loader"); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/marker/IrisCommandRegistry.java b/src/main/java/art/arcane/iris/engine/object/marker/IrisCommandRegistry.java deleted file mode 100644 index 1d5ed6e25..000000000 --- a/src/main/java/art/arcane/iris/engine/object/marker/IrisCommandRegistry.java +++ /dev/null @@ -1,94 +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.marker; - -import art.arcane.iris.engine.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.DependsOn; -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.platform.bukkit.BukkitWorld; -import art.arcane.iris.spi.PlatformWorld; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.RNG; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -@Snippet("command-registry") -@Accessors(chain = true) -@NoArgsConstructor -@Desc("Represents a casting location for a command") -@Data -public class IrisCommandRegistry { - @Required - @ArrayType(min = 1, type = IrisCommand.class) - @Desc("Run commands, at the exact location of the player") - private KList rawCommands = new KList<>(); - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetX = 0; - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetY = 0; - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetZ = 0; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altX from -altX to altX") - private boolean commandRandomAltX = true; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altY from -altY to altY") - private boolean commandRandomAltY = false; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altZ from -altZ to altZ") - private boolean commandRandomAltZ = true; - @DependsOn({"rawCommands"}) - @Desc("Randomize location for all separate commands (true), or run all on the same location (false)") - private boolean commandAllRandomLocations = true; - - public void run(Player p) { - if (rawCommands.isNotEmpty()) { - PlatformWorld world = new BukkitWorld(p.getWorld()); - Location part = p.getLocation().clone().add( - commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, - commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, - commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); - for (IrisCommand rawCommand : rawCommands) { - rawCommand.run(world, part.getBlockX(), part.getBlockY(), part.getBlockZ()); - if (commandAllRandomLocations) { - part = p.getLocation().clone().add( - commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, - commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, - commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); - } - } - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/marker/IrisObjectMarker.java b/src/main/java/art/arcane/iris/engine/object/marker/IrisObjectMarker.java index 580ce1212..f61e8b998 100644 --- a/src/main/java/art/arcane/iris/engine/object/marker/IrisObjectMarker.java +++ b/src/main/java/art/arcane/iris/engine/object/marker/IrisObjectMarker.java @@ -18,6 +18,7 @@ package art.arcane.iris.engine.object.marker; +import art.arcane.iris.builtin.spawn.SpawnMarker; import art.arcane.iris.engine.object.material.IrisBlockData; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.data.cache.AtomicCache; @@ -54,7 +55,7 @@ public class IrisObjectMarker { @Desc("If true, markers will only be placed if the block matches the mark list perfectly.") private boolean exact = false; @Required - @RegistryListResource(IrisMarker.class) + @RegistryListResource(SpawnMarker.class) @Desc("The marker to add") private String marker; diff --git a/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java b/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java index 169edfde5..d04debcb6 100644 --- a/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java +++ b/src/main/java/art/arcane/iris/engine/object/placement/BlocksModule.java @@ -28,7 +28,7 @@ import art.arcane.iris.builtin.blocks.ObjectMarkers; import art.arcane.iris.builtin.blocks.WrittenBlocks; import art.arcane.iris.core.modules.BlockEntities; import art.arcane.iris.core.modules.IrisPlacement; -import art.arcane.iris.engine.object.marker.IrisMarker; +import art.arcane.iris.builtin.spawn.SpawnMarker; import art.arcane.iris.engine.object.marker.IrisObjectMarker; import art.arcane.iris.engine.object.prefab.IrisObject; import art.arcane.iris.engine.object.prefab.IrisObjectShaping; @@ -205,7 +205,7 @@ public final class BlocksModule implements IrisModule { RNG markerRandom = new RNG(context.random().nextLong()); int salt = 0; for (IrisObjectMarker markerConfig : config.getMarkers()) { - IrisMarker marker = SpawnResources.marker(placement.object().getLoader(), markerConfig.getMarker()); + SpawnMarker marker = SpawnResources.marker(placement.object().getLoader(), markerConfig.getMarker()); int markerSalt = salt++; if (marker == null) { continue; @@ -216,7 +216,7 @@ public final class BlocksModule implements IrisModule { if (remaining <= 0) { break; } - if (!marker.isEmptyAbove() || hasAirAbove(world, position)) { + if (!marker.emptyAbove() || hasAirAbove(world, position)) { context.access().marker(ObjectMarkers.of(position, markerConfig.getMarker())); remaining--; } diff --git a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java index ee0075335..bfb28ac4a 100644 --- a/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java +++ b/src/main/java/art/arcane/iris/engine/object/placement/IrisObjectPlacement.java @@ -18,7 +18,6 @@ package art.arcane.iris.engine.object.placement; -import art.arcane.iris.engine.loot.LootResources; import art.arcane.iris.builtin.carve.CarvingMode; import art.arcane.iris.builtin.carve.CaveAnchorMode; import art.arcane.iris.builtin.anchor.ObjectPlaceMode; @@ -28,11 +27,8 @@ import art.arcane.iris.builtin.prepare.SlopeClip; import art.arcane.iris.builtin.vacuum.VacuumSettings; import art.arcane.iris.builtin.validate.ObjectLimit; import art.arcane.iris.core.modules.ModuleSettings; -import art.arcane.iris.engine.object.loot.IObjectLoot; -import art.arcane.iris.engine.object.loot.IrisLootTable; import art.arcane.iris.engine.object.loot.IrisObjectLoot; import art.arcane.iris.engine.object.loot.IrisObjectVanillaLoot; -import art.arcane.iris.engine.object.loot.IrisVanillaLootTable; import art.arcane.iris.engine.object.marker.IrisObjectMarker; import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; import art.arcane.iris.engine.object.noise.IrisNoiseGenerator; @@ -42,13 +38,10 @@ import art.arcane.iris.engine.object.prefab.IrisObject; import art.arcane.iris.engine.object.prefab.IrisObjectRotation; import art.arcane.iris.engine.object.prefab.IrisObjectScale; import art.arcane.iris.engine.object.prefab.IrisObjectTranslate; -import art.arcane.iris.platform.bukkit.BukkitBlockResolution; import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.engine.data.cache.AtomicCache; import art.arcane.iris.engine.data.cache.LazyBoundedCache; import art.arcane.iris.engine.framework.Engine; -import art.arcane.iris.engine.framework.LootResolver; import art.arcane.iris.engine.object.annotations.ArrayType; import art.arcane.iris.engine.object.annotations.Desc; import art.arcane.iris.engine.object.annotations.MaxNumber; @@ -56,10 +49,7 @@ import art.arcane.iris.engine.object.annotations.MinNumber; import art.arcane.iris.engine.object.annotations.RegistryListResource; import art.arcane.iris.engine.object.annotations.Required; import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.spi.IrisLogging; -import art.arcane.iris.spi.PlatformBlockState; import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.collection.KMap; import art.arcane.iris.util.common.data.DataProvider; import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.util.project.noise.CNG; @@ -73,14 +63,9 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.TreeType; -import org.bukkit.block.data.BlockData; import org.jetbrains.annotations.Nullable; -import java.util.Optional; -import java.util.function.Function; @Snippet("object-placer") @EqualsAndHashCode() @@ -204,7 +189,6 @@ public class IrisObjectPlacement { @Desc("Ignore any placement restrictions for this object") @SerializedName(value = "forcePlace", alternate = {"force"}) private boolean forcePlace = false; - private transient AtomicCache cache = new AtomicCache<>(); /** The pack modules' settings this placement declares, decoded with it. */ private transient ModuleSettings moduleSettings = ModuleSettings.NONE; @@ -313,96 +297,6 @@ public class IrisObjectPlacement { return (int) Math.round(densityStyle.get(rng, x, z, data)); } - private TableCache getCache(IrisData manager) { - return cache.aquire(() -> { - TableCache cache = new TableCache(); - - cache.merge(getCache(manager, getVanillaLoot(), IrisObjectPlacement::getVanillaTable)); - cache.merge(getCache(manager, getLoot(), key -> LootResources.table(manager, key))); - - return cache; - }); - } - - private TableCache getCache(IrisData manager, KList list, Function loader) { - TableCache tc = new TableCache(); - - for (IObjectLoot loot : list) { - if (loot == null || loot.getWeight() <= 0) - continue; - IrisLootTable table = loader.apply(loot.getName()); - if (table == null) { - IrisLogging.warn("Couldn't find loot table " + loot.getName()); - continue; - } - - if (loot.getFilter().isEmpty()) //Table applies to all containers - { - tc.global.put(table, loot.getWeight()); - } else if (!loot.isExact()) //Table is meant to be by type - { - for (PlatformBlockState filterState : loot.getFilter(manager)) { - BlockData filterData = (BlockData) filterState.nativeHandle(); - if (!tc.basic.containsKey(filterData.getMaterial())) { - tc.basic.put(filterData.getMaterial(), new WeightedTables()); - } - - tc.basic.get(filterData.getMaterial()).put(table, loot.getWeight()); - } - } else //Filter is exact - { - for (PlatformBlockState filterState : loot.getFilter(manager)) { - BlockData filterData = (BlockData) filterState.nativeHandle(); - if (!tc.exact.containsKey(filterData.getMaterial())) { - tc.exact.put(filterData.getMaterial(), new KMap<>()); - } - - if (!tc.exact.get(filterData.getMaterial()).containsKey(filterData)) { - tc.exact.get(filterData.getMaterial()).put(filterData, new WeightedTables()); - } - - tc.exact.get(filterData.getMaterial()).get(filterData).put(table, loot.getWeight()); - } - } - } - return tc; - } - - @Nullable - private static IrisVanillaLootTable getVanillaTable(String name) { - return Optional.ofNullable(NamespacedKey.fromString(name)) - .map(Bukkit::getLootTable) - // Hand over the key, not the LootTable: IrisVanillaLootTable holds no Bukkit fields. - .map(table -> new IrisVanillaLootTable(String.valueOf(table.getKey()))) - .orElse(null); - } - - /** - * Gets the loot table that should be used for the block - * - * @param state The block state of the block - * @param dataManager Iris Data Manager - * @return The loot table it should use. - */ - public IrisLootTable getTable(PlatformBlockState state, IrisData dataManager, RNG rng) { - TableCache cache = getCache(dataManager); - BlockData data = (BlockData) state.nativeHandle(); - if (BukkitBlockResolution.isStorageChest(data)) { - IrisLootTable picked = null; - if (cache.exact.containsKey(data.getMaterial()) && cache.exact.get(data.getMaterial()).containsKey(data)) { - picked = cache.exact.get(data.getMaterial()).get(data).pullRandom(rng); - } else if (cache.basic.containsKey(data.getMaterial())) { - picked = cache.basic.get(data.getMaterial()).pullRandom(rng); - } else if (!cache.global.isEmpty()) { - picked = cache.global.pullRandom(rng); - } - - return picked; - } - - return null; - } - private static final class SurfaceWarpCacheKey { private final IrisData data; private final Engine engine; @@ -432,41 +326,4 @@ public class IrisObjectPlacement { return 31 * result + Long.hashCode(seed); } } - - private static class TableCache { - final transient WeightedTables global = new WeightedTables(); - final transient KMap basic = new KMap<>(); - final transient KMap> exact = new KMap<>(); - - private void merge(TableCache other) { - global.merge(other.global); - basic.merge(other.basic, WeightedTables::merge); - exact.merge(other.exact, (a, b) -> a.merge(b, WeightedTables::merge)); - } - } - - private static final class WeightedTables { - private final KList tables = new KList<>(); - - private void put(IrisLootTable table, int weight) { - tables.add(new WeightedTable(table, weight)); - } - - private IrisLootTable pullRandom(RNG rng) { - WeightedTable picked = LootResolver.pickWeighted(tables, WeightedTable::weight, rng); - return picked == null ? null : picked.table(); - } - - private boolean isEmpty() { - return tables.isEmpty(); - } - - private WeightedTables merge(WeightedTables other) { - tables.addAll(other.tables); - return this; - } - } - - private record WeightedTable(IrisLootTable table, int weight) { - } } diff --git a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java b/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java index 5e7d3de5f..77865a878 100644 --- a/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java +++ b/src/main/java/art/arcane/iris/engine/object/structure/IrisStructure.java @@ -21,7 +21,7 @@ package art.arcane.iris.engine.object.structure; import art.arcane.iris.builtin.anchor.PlaceTrait; import art.arcane.iris.builtin.anchor.ObjectPlaceMode; import art.arcane.iris.builtin.blocks.ObjectReplace; -import art.arcane.iris.engine.object.loot.IrisLootTable; +import art.arcane.iris.builtin.loot.LootTable; import art.arcane.iris.engine.object.loot.IrisObjectLoot; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawBranchFailurePolicy; @@ -102,7 +102,7 @@ public class IrisStructure extends IrisRegistrant { private KList edit = new KList<>(); @ArrayType(type = String.class, min = 1) - @RegistryListResource(IrisLootTable.class) + @RegistryListResource(LootTable.class) @Desc("Loot tables applied to containers placed by this structure's pieces.") private KList loot = new KList<>(); diff --git a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java index 2be388ff5..fd1a30c8c 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java +++ b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java @@ -20,10 +20,6 @@ package art.arcane.iris.engine.object.world.biome; import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.builtin.carve.CaveProfile; -import art.arcane.iris.engine.object.entity.IrisEffect; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; -import art.arcane.iris.engine.object.loot.IrisBlockDrops; -import art.arcane.iris.engine.object.loot.IrisLootReference; import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; import art.arcane.iris.engine.object.noise.NoiseStyle; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; @@ -127,21 +123,9 @@ public class IrisBiome extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = IrisBiomeCustom.class) @Desc("If the biome type custom is defined, specify this") private KList customDerivitives; - @Desc("Spawn Entities in this area over time. Iris will continually replenish these mobs just like vanilla does.") - @ArrayType(min = 1, type = String.class) - @RegistryListResource(IrisSpawner.class) - private KList entitySpawners = new KList<>(); - @ArrayType(min = 1, type = IrisEffect.class) - @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play around the player even if where the effect was played is no longer in the biome the player is in.") - private KList effects = new KList<>(); @DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"}) @Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.") private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style(); - @ArrayType(min = 1, type = IrisBlockDrops.class) - @Desc("Define custom block drops for this biome") - private KList blockDrops = new KList<>(); - @Desc("Reference loot tables in this area") - private IrisLootReference loot = new IrisLootReference(); @Desc("Layers no longer descend from the surface block, they descend from the max possible height the biome can produce (constant) creating mesa like layers.") private boolean lockLayers = false; @Desc("The max layers to iterate below the surface for locked layer biomes (mesa).") diff --git a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java index 8f37e4768..4f1646a55 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java +++ b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java @@ -21,12 +21,9 @@ package art.arcane.iris.engine.object.world.dimension; import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.builtin.carve.CaveProfile; import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; import art.arcane.iris.engine.object.image.IrisImageMap; import art.arcane.iris.engine.object.image.IrisImageMapApplication; import art.arcane.iris.engine.object.image.IrisImageMapBinding; -import art.arcane.iris.engine.object.loot.IrisBlockDrops; -import art.arcane.iris.engine.object.loot.IrisLootReference; import art.arcane.iris.engine.object.material.IrisMaterialPalette; import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; import art.arcane.iris.engine.object.noise.IrisShapedGeneratorStyle; @@ -142,18 +139,9 @@ public class IrisDimension extends IrisRegistrant { private int debugCrossSectionsMod = 3; @Desc("Tree growth override settings") private IrisTreeSettings treeSettings = new IrisTreeSettings(); - @Desc("Spawn Entities in this dimension over time. Iris will continually replenish these mobs just like vanilla does.") - @ArrayType(min = 1, type = String.class) - @RegistryListResource(IrisSpawner.class) - private KList entitySpawners = new KList<>(); - @Desc("Reference loot tables in this area") - private IrisLootReference loot = new IrisLootReference(); @MinNumber(0) @Desc("The version of this dimension. Changing this will stop users from accidentally upgrading (and breaking their worlds).") private int version = 1; - @ArrayType(min = 1, type = IrisBlockDrops.class) - @Desc("Define custom block drops for this dimension") - private KList blockDrops = new KList<>(); @Desc("Should bedrock be generated or not.") private boolean bedrock = true; @MinNumber(0) diff --git a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java index 8c03c3310..104c3032f 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java +++ b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java @@ -19,10 +19,6 @@ package art.arcane.iris.engine.object.world.region; import art.arcane.iris.builtin.carve.CaveProfile; -import art.arcane.iris.engine.object.entity.IrisEffect; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; -import art.arcane.iris.engine.object.loot.IrisBlockDrops; -import art.arcane.iris.engine.object.loot.IrisLootReference; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.procedural.IrisProceduralObjects; import art.arcane.iris.engine.object.structure.IrisStructurePlacement; @@ -85,20 +81,10 @@ public class IrisRegion extends IrisRegistrant implements IRare { @Required @Desc("The name of the region") private String name = "A Region"; - @ArrayType(min = 1, type = IrisEffect.class) - @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play arround the player even if where the effect was played is no longer in the biome the player is in.") - private KList effects = new KList<>(); - @Desc("Spawn Entities in this region over time. Iris will continually replenish these mobs just like vanilla does.") - @ArrayType(min = 1, type = String.class) - @RegistryListResource(IrisSpawner.class) - private KList entitySpawners = new KList<>(); @MinNumber(1) @MaxNumber(128) @Desc("The rarity of the region") private int rarity = 1; - @ArrayType(min = 1, type = IrisBlockDrops.class) - @Desc("Define custom block drops for this region") - private KList blockDrops = new KList<>(); @ArrayType(min = 1, type = IrisObjectPlacement.class) @Desc("Objects define what schematics (iob files) iris will place in this region") private KList objects = new KList<>(); @@ -110,8 +96,6 @@ public class IrisRegion extends IrisRegistrant implements IRare { @MinNumber(0) @Desc("The min shore height") private double shoreHeightMin = 1.2; - @Desc("Reference loot tables in this area") - private IrisLootReference loot = new IrisLootReference(); @MinNumber(0) @Desc("The the max shore height") private double shoreHeightMax = 3.2; diff --git a/src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java b/src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java new file mode 100644 index 000000000..f1af6b1c4 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/spawn/AmbientEffecting.java @@ -0,0 +1,135 @@ +/* + * 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.spawn; + +import art.arcane.iris.builtin.spawn.AmbientEffect; +import art.arcane.iris.builtin.spawn.EffectCommands; +import art.arcane.iris.builtin.spawn.EffectSettings; +import art.arcane.iris.builtin.spawn.SpawnCommand; +import art.arcane.iris.core.loader.IrisRegistrant; +import art.arcane.iris.core.modules.IrisPackWorld; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.spi.PlatformWorld; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.entity.EntitySpec; +import com.volmit.service.AmbientEffects; +import com.volmit.world.BlockPosition; +import com.volmit.world.PackWorld; + +import java.util.ArrayList; +import java.util.List; + +/** + * How {@code iris:spawn} plays the ambient effects of regions and biomes: the region's effects, then the biome's, each + * when its interval and chance say, with every random choice made here so the host only carries them out. + */ +public final class AmbientEffecting implements AmbientEffects { + @Override + public List due(PackWorld world, BlockPosition at) { + Engine engine = IrisPackWorld.of(world).engine(); + EffectTimers timers = world.state(EffectTimers.class, ignored -> new EffectTimers()); + PlatformWorld platformWorld = engine.getWorld().platformWorld(); + + List due = new ArrayList<>(); + addDue(due, effectsOf(engine.getRegion(at.x(), at.z())), timers, platformWorld); + addDue(due, effectsOf(engine.getBiome(at.x(), at.y(), at.z())), timers, platformWorld); + return due; + } + + private static List effectsOf(IrisRegistrant owner) { + return owner.getModuleSettings().find(EffectSettings.class).map(EffectSettings::effects).orElse(List.of()); + } + + private static void addDue(List due, List effects, EffectTimers timers, PlatformWorld world) { + for (AmbientEffect effect : effects) { + if (timers.shouldPlayNow(effect)) { + due.add(play(effect, world)); + } + } + } + + private static Effect play(AmbientEffect effect, PlatformWorld world) { + Sound sound = effect.sound() == null ? null : soundOf(effect); + Particles particles = effect.particleEffect() == null ? null : particlesOf(effect); + return new Effect(sound, particles, commandsOf(effect.commandRegistry(), world), potionOf(effect)); + } + + private static Sound soundOf(AmbientEffect effect) { + int distance = effect.soundDistance(); + int offsetX = RNG.r.i(-distance, distance); + int offsetY = RNG.r.i(-distance, distance); + int offsetZ = RNG.r.i(-distance, distance); + float pitch = (float) RNG.r.d(effect.minPitch(), effect.maxPitch()); + return new Sound(effect.sound(), offsetX, offsetY, offsetZ, (float) effect.volume(), pitch); + } + + private static Particles particlesOf(AmbientEffect effect) { + double forward = RNG.r.i(effect.particleDistance()) + effect.particleAway(); + double sideways = RNG.r.d(-effect.particleDistanceWidth(), effect.particleDistanceWidth()); + double jitterX = RNG.r.d(); + double jitterZ = RNG.r.d(); + int lift = RNG.r.i(effect.particleOffset()); + double altX = randomized(effect.particleAltX(), effect.randomAltX()); + double altY = randomized(effect.particleAltY(), effect.randomAltY()); + double altZ = randomized(effect.particleAltZ(), effect.randomAltZ()); + return new Particles(effect.particleEffect(), forward, sideways, jitterX, jitterZ, lift, effect.particleCount(), + altX, altY, altZ, effect.extra()); + } + + private static List commandsOf(EffectCommands registry, PlatformWorld world) { + List commands = new ArrayList<>(); + if (registry == null) { + return commands; + } + + double offsetX = commandOffset(registry.commandOffsetX(), registry.commandRandomAltX()); + double offsetY = commandOffset(registry.commandOffsetY(), registry.commandRandomAltY()); + double offsetZ = commandOffset(registry.commandOffsetZ(), registry.commandRandomAltZ()); + for (SpawnCommand command : registry.rawCommands()) { + if (SpawnConditions.allow(command.timeBlock(), command.weather(), world)) { + commands.add(new Command(new EntitySpec.Command(command.commands(), command.delay(), command.repeat(), + command.repeatDelay()), offsetX, offsetY, offsetZ)); + } + if (registry.commandAllRandomLocations()) { + offsetX = commandOffset(registry.commandOffsetX(), registry.commandRandomAltX()); + offsetY = commandOffset(registry.commandOffsetY(), registry.commandRandomAltY()); + offsetZ = commandOffset(registry.commandOffsetZ(), registry.commandRandomAltZ()); + } + } + return commands; + } + + private static Potion potionOf(AmbientEffect effect) { + if (effect.potionStrength() <= -1) { + return null; + } + + int shortest = Math.min(effect.potionTicksMax(), effect.potionTicksMin()); + int longest = Math.max(effect.potionTicksMax(), effect.potionTicksMin()); + return new Potion(effect.potionEffect(), effect.potionStrength(), RNG.r.i(shortest, longest)); + } + + private static double commandOffset(double offset, boolean random) { + return randomized(offset, random); + } + + private static double randomized(double value, boolean random) { + return random ? RNG.r.d(-value, value) : value; + } +} diff --git a/src/main/java/art/arcane/iris/engine/spawn/EffectTimers.java b/src/main/java/art/arcane/iris/engine/spawn/EffectTimers.java new file mode 100644 index 000000000..e3aac1bcb --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/spawn/EffectTimers.java @@ -0,0 +1,40 @@ +/* + * 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.spawn; + +import art.arcane.iris.builtin.spawn.AmbientEffect; +import art.arcane.volmlib.util.math.RNG; +import art.arcane.volmlib.util.scheduling.ChronoLatch; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * When the effects of a world play: an effect plays at most once per interval, and then only with its chance. The timers + * are the world's, shared by every player, like the effects themselves. + */ +final class EffectTimers { + private final ConcurrentMap latches = new ConcurrentHashMap<>(); + + /** Whether {@code effect} plays now; asking starts its interval over when it has elapsed. */ + boolean shouldPlayNow(AmbientEffect effect) { + ChronoLatch latch = latches.computeIfAbsent(effect, key -> new ChronoLatch(key.interval())); + return latch.flip() && RNG.r.nextInt(effect.chance()) == 0; + } +} diff --git a/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java b/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java index a5277349e..f0b72ae42 100644 --- a/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java +++ b/src/main/java/art/arcane/iris/engine/spawn/EntityResolution.java @@ -18,13 +18,13 @@ package art.arcane.iris.engine.spawn; +import art.arcane.iris.builtin.loot.ItemAttributeModifier; +import art.arcane.iris.builtin.loot.LootEntry; +import art.arcane.iris.builtin.spawn.AmbientEffect; +import art.arcane.iris.builtin.spawn.EntityDefinition; +import art.arcane.iris.builtin.spawn.SpawnCommand; import art.arcane.iris.engine.framework.LootResolver; import art.arcane.iris.engine.loot.LootItems; -import art.arcane.iris.engine.object.entity.IrisAttributeModifier; -import art.arcane.iris.engine.object.entity.IrisEffect; -import art.arcane.iris.engine.object.entity.IrisEntity; -import art.arcane.iris.engine.object.loot.IrisLoot; -import art.arcane.iris.engine.object.marker.IrisCommand; import art.arcane.iris.spi.PlatformWorld; import art.arcane.volmlib.util.math.RNG; import com.volmit.entity.EntitySpec; @@ -44,83 +44,85 @@ final class EntityResolution { private final LootItems items; private final PlatformWorld world; + private final EffectTimers timers; /** @param world the world the entity appears in, whose time and weather decide which of its commands run */ - EntityResolution(LootItems items, PlatformWorld world) { + EntityResolution(LootItems items, PlatformWorld world, EffectTimers timers) { this.items = items; this.world = world; + this.timers = timers; } - EntitySpec resolve(IrisEntity entity, RNG rng) { + EntitySpec resolve(EntityDefinition entity, RNG rng) { List passengers = new ArrayList<>(); long passengerIndex = 0; - for (IrisEntity passenger : entity.getPassengers()) { + for (EntityDefinition passenger : entity.passengers()) { passengers.add(resolve(passenger, rng.nextParallelRNG(PASSENGER_STREAM_BASE + passengerIndex++))); } List attributes = drawAttributes(entity, rng); - List lootTables = List.copyOf(entity.getLoot().getTables()); + List lootTables = List.copyOf(entity.loot().tables()); long lootShuffleSeed = lootTables.isEmpty() ? 0L : rng.nextLong(); - EntitySpec leashHolder = entity.getLeashHolder() == null ? null : resolve(entity.getLeashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM)); + EntitySpec leashHolder = entity.leashHolder() == null ? null : resolve(entity.leashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM)); EntitySpec.Equipment equipment = new EntitySpec.Equipment( - equip(entity.getHelmet(), rng), equip(entity.getChestplate(), rng), equip(entity.getLeggings(), rng), - equip(entity.getBoots(), rng), equip(entity.getMainHand(), rng), equip(entity.getOffHand(), rng)); + equip(entity.helmet(), rng), equip(entity.chestplate(), rng), equip(entity.leggings(), rng), + equip(entity.boots(), rng), equip(entity.mainHand(), rng), equip(entity.offHand(), rng)); return new EntitySpec( - entity.getType() == null ? "" : entity.getType(), - entity.getSpecialType() == null ? "" : entity.getSpecialType(), - entity.getReason(), - entity.getCustomName() == null ? "" : entity.getCustomName(), + entity.type() == null ? "" : entity.type(), + entity.specialType() == null ? "" : entity.specialType(), + entity.reason(), + entity.customName() == null ? "" : entity.customName(), flagsOf(entity), equipment, passengers, attributes, lootTables, lootShuffleSeed, leashHolder, - spawnEffectOf(entity), entity.isSpawnEffectRiseOutOfGround(), entity.getPandaMainGene(), - entity.getPandaHiddenGene(), entity.isApplySettingsToCustomMobAnyways(), commandsOf(entity)); + spawnEffectOf(entity), entity.spawnEffectRiseOutOfGround(), entity.pandaMainGene(), + entity.pandaHiddenGene(), entity.applySettingsToCustomMobAnyways(), commandsOf(entity)); } - private static EntitySpec.Flags flagsOf(IrisEntity entity) { - return new EntitySpec.Flags(entity.isCustomNameVisible(), entity.isAware(), entity.isAi(), entity.isGlowing(), - entity.isGravity(), entity.isInvulnerable(), entity.isSilent(), entity.isPickupItems(), entity.isRemovable(), - entity.isKeepEntity(), entity.isBaby()); + private static EntitySpec.Flags flagsOf(EntityDefinition entity) { + return new EntitySpec.Flags(entity.customNameVisible(), entity.aware(), entity.ai(), entity.glowing(), + entity.gravity(), entity.invulnerable(), entity.silent(), entity.pickupItems(), entity.removable(), + entity.keepEntity(), entity.baby()); } - private static List drawAttributes(IrisEntity entity, RNG rng) { + private static List drawAttributes(EntityDefinition entity, RNG rng) { List attributes = new ArrayList<>(); - for (IrisAttributeModifier modifier : entity.getAttributes()) { - if (rng.nextDouble() >= modifier.getChance()) { + for (ItemAttributeModifier modifier : entity.attributes()) { + if (rng.nextDouble() >= modifier.chance()) { continue; } - String attribute = modifier.getAttribute(); + String attribute = modifier.attribute(); if (attribute == null || attribute.isBlank()) { continue; } - attributes.add(new ItemAttribute(attribute, modifier.getName(), modifier.getOperation(), modifier.getAmount(rng))); + attributes.add(new ItemAttribute(attribute, modifier.name(), modifier.operation(), rng.d(modifier.minAmount(), modifier.maxAmount()))); } return attributes; } - private ItemDrop equip(IrisLoot piece, RNG rng) { - if (piece == null || !LootResolver.oneIn(rng, piece.getRarity())) { + private ItemDrop equip(LootEntry piece, RNG rng) { + if (piece == null || !LootResolver.oneIn(rng, piece.rarity())) { return null; } return items.give(piece, rng); } /** The entity's spawn effect when it shows this time: an effect only shows now and then, as its interval and chance say. */ - private static EntitySpec.SpawnEffect spawnEffectOf(IrisEntity entity) { - IrisEffect effect = entity.getSpawnEffect(); - if (effect == null || !effect.shouldApplyNow()) { + private EntitySpec.SpawnEffect spawnEffectOf(EntityDefinition entity) { + AmbientEffect effect = entity.spawnEffect(); + if (effect == null || !timers.shouldPlayNow(effect)) { return null; } - return new EntitySpec.SpawnEffect(effect.getSoundKey(), effect.getSoundDistance(), effect.getMinPitch(), - effect.getMaxPitch(), effect.getVolume(), effect.getParticleEffectKey(), effect.getParticleOffset(), - effect.getParticleCount(), effect.getParticleAltX(), effect.getParticleAltY(), effect.getParticleAltZ(), - effect.isRandomAltX(), effect.isRandomAltY(), effect.isRandomAltZ(), effect.getExtra()); + return new EntitySpec.SpawnEffect(effect.sound(), effect.soundDistance(), effect.minPitch(), + effect.maxPitch(), effect.volume(), effect.particleEffect(), effect.particleOffset(), + effect.particleCount(), effect.particleAltX(), effect.particleAltY(), effect.particleAltZ(), + effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra()); } - private List commandsOf(IrisEntity entity) { + private List commandsOf(EntityDefinition entity) { List commands = new ArrayList<>(); - for (IrisCommand command : entity.getRawCommands()) { - if (command.isValid(world)) { - commands.add(new EntitySpec.Command(command.getCommands(), command.getDelay(), command.isRepeat(), command.getRepeatDelay())); + for (SpawnCommand command : entity.rawCommands()) { + if (SpawnConditions.allow(command.timeBlock(), command.weather(), world)) { + commands.add(new EntitySpec.Command(command.commands(), command.delay(), command.repeat(), command.repeatDelay())); } } return commands; diff --git a/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java b/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java index e4aea6f93..afe14ae5e 100644 --- a/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java +++ b/src/main/java/art/arcane/iris/engine/spawn/EntitySpawning.java @@ -18,26 +18,29 @@ package art.arcane.iris.engine.spawn; +import art.arcane.iris.builtin.spawn.EntityDefinition; +import art.arcane.iris.builtin.spawn.EntitySpawn; +import art.arcane.iris.builtin.spawn.SpawnMarker; +import art.arcane.iris.builtin.spawn.SpawnSurface; +import art.arcane.iris.builtin.spawn.Spawner; +import art.arcane.iris.builtin.spawn.SpawnerSettings; +import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.core.modules.IrisPackWorld; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.LootResolver; import art.arcane.iris.engine.loot.LootItems; -import art.arcane.iris.engine.object.entity.IrisEntity; -import art.arcane.iris.engine.object.entity.IrisEntitySpawn; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; -import art.arcane.iris.engine.object.entity.spawn.IrisSurface; -import art.arcane.iris.engine.object.marker.IrisMarker; import art.arcane.iris.engine.object.value.IRare; import art.arcane.iris.engine.object.value.IrisPosition; -import art.arcane.iris.engine.object.value.IrisRange; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.region.IrisRegion; +import art.arcane.iris.engine.spawn.SpawnResources.KeyedSpawner; import art.arcane.iris.spi.IrisLogging; import art.arcane.iris.util.common.scheduling.J; import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.math.PowerOfTwoCoordinates; import art.arcane.volmlib.util.math.RNG; import art.arcane.volmlib.util.matter.slices.MarkerMatter; +import com.volmit.config.Range; import com.volmit.entity.EntitySpec; import com.volmit.service.EntitySpawns; import com.volmit.world.BlockPosition; @@ -76,15 +79,15 @@ public final class EntitySpawning implements EntitySpawns { if (count <= 0) { return; } - IrisSpawner spawner = SpawnResources.spawner(engine(world).getData(), plan.spawner()); + Spawner spawner = SpawnResources.spawner(engine(world).getData(), plan.spawner()); if (spawner != null) { - spawner.spawn(engine(world), plan.chunkX(), plan.chunkZ()); + SpawnerGate.spawned(plan.spawner(), spawner, engine(world), plan.chunkX(), plan.chunkZ()); } } @Override public Optional entity(PackWorld world, String key) { - IrisEntity entity = SpawnResources.entity(engine(world).getData(), key); + EntityDefinition entity = SpawnResources.entity(engine(world).getData(), key); if (entity == null) { return Optional.empty(); } @@ -97,40 +100,40 @@ public final class EntitySpawning implements EntitySpawns { return Optional.empty(); } Engine engine = engine(world); - IrisMarker marker = SpawnResources.marker(engine.getData(), tag); + SpawnMarker marker = SpawnResources.marker(engine.getData(), tag); if (marker == null) { return Optional.empty(); } List spawners = new ArrayList<>(); - for (String key : marker.getSpawners()) { + for (String key : marker.spawners()) { if (SpawnResources.spawner(engine.getData(), key) == null) { IrisLogging.error("Cannot load spawner: " + key + " for marker " + tag); continue; } spawners.add(key); } - return Optional.of(new MarkerRule(spawners, marker.isEmptyAbove(), marker.isRemoveOnChange())); + return Optional.of(new MarkerRule(spawners, marker.emptyAbove(), marker.removeOnChange())); } private Optional planChunk(PackWorld world, Engine engine, Chunk chunk) { - Predicate canSpawn = spawner -> spawner.canSpawn(engine, chunk.chunkX(), chunk.chunkZ()); + Predicate canSpawn = keyed -> SpawnerGate.canSpawn(keyed.key(), keyed.spawner(), engine, chunk.chunkX(), chunk.chunkZ()); int blockX = PowerOfTwoCoordinates.chunkToBlock(chunk.chunkX()); int blockZ = PowerOfTwoCoordinates.chunkToBlock(chunk.chunkZ()); IrisBiome centreBiome = engine.getSurfaceBiome(blockX + BLOCKS_TO_CHUNK_CENTRE, blockZ + BLOCKS_TO_CHUNK_CENTRE); IrisRegion region = engine.getRegion(blockX, blockZ); IrisBiome biome = engine.getSurfaceBiome(blockX, blockZ); - List candidates = Stream.concat( - shuffled(engine, engine.getDimension().getEntitySpawners()).stream() - .filter(canSpawn).filter(spawner -> spawner.isValid(centreBiome)), + List candidates = Stream.concat( + shuffled(engine, engine.getDimension()).stream() + .filter(canSpawn).filter(keyed -> SpawnerGate.suits(keyed.spawner(), centreBiome)), Stream.concat( - shuffled(engine, region.getEntitySpawners()).stream().filter(canSpawn), - shuffled(engine, biome.getEntitySpawners()).stream().filter(canSpawn))) - .filter(spawner -> chunk.livingEntities() < spawner.getMaxEntitiesPerChunk()) + shuffled(engine, region).stream().filter(canSpawn), + shuffled(engine, biome).stream().filter(canSpawn))) + .filter(keyed -> chunk.livingEntities() < keyed.spawner().maxEntitiesPerChunk()) .toList(); - List spawns = candidates.stream().flatMap(spawner -> spawnsOf(spawner, chunk.initial())).collect(Collectors.toList()); + List spawns = candidates.stream().flatMap(keyed -> spawnsOf(keyed, chunk.initial())).collect(Collectors.toList()); Candidate chosen = IRare.expandWeighted(spawns).getRandom(); if (chosen == null) { return Optional.empty(); @@ -139,26 +142,25 @@ public final class EntitySpawning implements EntitySpawns { } private Optional planChunkSpawn(PackWorld world, Engine engine, Chunk chunk, Candidate chosen) { - IrisSpawner spawner = chosen.spawner(); - IrisEntitySpawn spawn = chosen.spawn(); - int count = LootResolver.inclusive(RNG.r, spawn.getMinSpawns(), spawn.getMaxSpawns()); + EntitySpawn spawn = chosen.spawn(); + int count = LootResolver.inclusive(RNG.r, spawn.minSpawns(), spawn.maxSpawns()); List attempts = new ArrayList<>(); for (int i = 0; i < count; i++) { int x = (chunk.chunkX() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE); int z = (chunk.chunkZ() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE); - BlockPosition at = spawnPosition(engine, spawner, chunk.chunkX(), chunk.chunkZ(), x, z); + BlockPosition at = spawnPosition(engine, chosen.spawner(), chunk.chunkX(), chunk.chunkZ(), x, z); if (at != null) { addAttempt(attempts, world, engine, chosen, at, true); } } - return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(spawner.getLoadKey(), chunk.chunkX(), chunk.chunkZ(), false, attempts)); + return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(chosen.key(), chunk.chunkX(), chunk.chunkZ(), false, attempts)); } /** Where a spawner of its group puts an entity at the column; null when it has no place for one. */ - private static BlockPosition spawnPosition(Engine engine, IrisSpawner spawner, int chunkX, int chunkZ, int x, int z) { + private static BlockPosition spawnPosition(Engine engine, Spawner spawner, int chunkX, int chunkZ, int x, int z) { int height = engine.getHeight(x, z, true); int heightWithFluid = engine.getHeight(x, z, false); - return switch (spawner.getGroup()) { + return switch (spawner.group()) { case NORMAL -> new BlockPosition(x, heightWithFluid + 1, z); case CAVE -> caveSpawnPosition(engine, chunkX, chunkZ); case UNDERWATER, BEACH -> new BlockPosition(x, RNG.r.i(height + 1, heightWithFluid), z); @@ -175,78 +177,92 @@ public final class EntitySpawning implements EntitySpawns { } private Optional planMarker(PackWorld world, Engine engine, Marker marker) { - IrisSpawner spawner = SpawnResources.spawner(engine.getData(), marker.spawner()); - IrisMarker irisMarker = SpawnResources.marker(engine.getData(), marker.marker()); + Spawner spawner = SpawnResources.spawner(engine.getData(), marker.spawner()); + SpawnMarker spawnMarker = SpawnResources.marker(engine.getData(), marker.marker()); if (spawner == null) { return Optional.empty(); } - KList candidates = marker.initial() ? spawner.getInitialSpawns() : spawner.getSpawns(); + List candidates = marker.initial() ? spawner.initialSpawns() : spawner.spawns(); if (candidates.isEmpty()) { return Optional.empty(); } - IrisEntitySpawn spawn = IRare.expandWeighted(candidates).getRandom(); + EntitySpawn spawn = IRare.expandWeighted(candidates.stream().map(RareSpawn::new).toList()).getRandom().spawn(); BlockPosition position = marker.position(); int chunkX = PowerOfTwoCoordinates.blockToChunkFloor(position.x()); int chunkZ = PowerOfTwoCoordinates.blockToChunkFloor(position.z()); - if (!spawner.canSpawn(engine, chunkX, chunkZ)) { + if (!SpawnerGate.canSpawn(marker.spawner(), spawner, engine, chunkX, chunkZ)) { return Optional.empty(); } - int count = LootResolver.inclusive(RNG.r, spawn.getMinSpawns(), spawn.getMaxSpawns()); + int count = LootResolver.inclusive(RNG.r, spawn.minSpawns(), spawn.maxSpawns()); if (count <= 0) { return Optional.empty(); } - boolean exhaustsMarker = irisMarker != null && irisMarker.shouldExhaust(); + boolean exhaustsMarker = spawnMarker != null && shouldExhaust(spawnMarker); List attempts = new ArrayList<>(); BlockPosition above = new BlockPosition(position.x(), position.y() + AIR_ABOVE_MARKER, position.z()); for (int i = 0; i < count; i++) { - addAttempt(attempts, world, engine, new Candidate(spawner, spawn), above, false); + addAttempt(attempts, world, engine, new Candidate(marker.spawner(), spawner, spawn), above, false); } - return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(spawner.getLoadKey(), chunkX, chunkZ, exhaustsMarker, attempts)); + return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(marker.spawner(), chunkX, chunkZ, exhaustsMarker, attempts)); + } + + private static boolean shouldExhaust(SpawnMarker marker) { + return marker.exhaustionChance() > RNG.r.nextDouble(); } private void addAttempt(List attempts, PackWorld world, Engine engine, Candidate candidate, BlockPosition at, boolean checkSurface) { - IrisEntity entity = candidate.spawn().getRealEntity(engine); + EntityDefinition entity = SpawnResources.entity(engine.getData(), candidate.spawn().entity()); if (entity == null) { IrisLogging.debug(" You are trying to spawn an entity that does not exist!"); return; } - IrisRange light = candidate.spawner().getAllowedLightLevels(); + Range light = candidate.spawner().allowedLightLevels(); EntitySpec spec = resolution(world, engine).resolve(entity, entityRandom(world).rng()); - attempts.add(new Attempt(at, spec, surfaceOf(entity.getSurface()), - (int) Math.ceil(light.getMin()), (int) Math.floor(light.getMax()), checkSurface)); + attempts.add(new Attempt(at, spec, surfaceOf(entity.surface()), + (int) Math.ceil(light.min()), (int) Math.floor(light.max()), checkSurface)); } private static EntityResolution resolution(PackWorld world, Engine engine) { LootItems items = new LootItems(world.resources().items(), engine.isStudio()); - return new EntityResolution(items, engine.getWorld().platformWorld()); + return new EntityResolution(items, engine.getWorld().platformWorld(), world.state(EffectTimers.class, ignored -> new EffectTimers())); } private static EntityRandom entityRandom(PackWorld world) { return world.state(EntityRandom.class, EntityRandom::new); } - private static Surface surfaceOf(IrisSurface surface) { + private static Surface surfaceOf(SpawnSurface surface) { return Surface.valueOf(surface.name()); } - private static KList shuffled(Engine engine, KList keys) { - return SpawnResources.spawners(engine.getData(), keys).shuffleCopy(RNG.r); + /** The spawners an area lists, in a random order. */ + private static List shuffled(Engine engine, IrisRegistrant owner) { + List keys = owner.getModuleSettings().find(SpawnerSettings.class).map(SpawnerSettings::spawners).orElse(List.of()); + return new KList<>(SpawnResources.spawners(engine.getData(), keys)).shuffleCopy(RNG.r); } - private static Stream spawnsOf(IrisSpawner spawner, boolean initial) { - KList spawns = initial ? spawner.getInitialSpawns() : spawner.getSpawns(); - return spawns.stream().map(spawn -> new Candidate(spawner, spawn)); + private static Stream spawnsOf(KeyedSpawner keyed, boolean initial) { + List spawns = initial ? keyed.spawner().initialSpawns() : keyed.spawner().spawns(); + return spawns.stream().map(spawn -> new Candidate(keyed.key(), keyed.spawner(), spawn)); } /** A spawn of a spawner, which picks as often as the spawn's rarity says. */ - private record Candidate(IrisSpawner spawner, IrisEntitySpawn spawn) implements IRare { + private record Candidate(String key, Spawner spawner, EntitySpawn spawn) implements IRare { @Override public int getRarity() { - return spawn.getRarity(); + return spawn.rarity(); + } + } + + /** A spawn that picks as often as its rarity says. */ + private record RareSpawn(EntitySpawn spawn) implements IRare { + @Override + public int getRarity() { + return spawn.rarity(); } } diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java new file mode 100644 index 000000000..f7616adef --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnConditions.java @@ -0,0 +1,42 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.engine.spawn; + +import art.arcane.iris.builtin.spawn.SpawnTimeBlock; +import art.arcane.iris.builtin.spawn.SpawnWeather; +import art.arcane.iris.spi.PlatformWorld; + +/** The time of day and the weather a command or spawner of the pack asks for, checked against a world. */ +final class SpawnConditions { + private static final double TICKS_PER_HOUR = 1000D; + private static final double HOURS_AT_TIME_ZERO = 6; + private static final double HOURS_PER_DAY = 24; + + private SpawnConditions() { + } + + static boolean allow(SpawnTimeBlock time, SpawnWeather weather, PlatformWorld world) { + return time.contains(hourOf(world)) && weather.matches(world.isStorming(), world.isThundering()); + } + + /** The world's time of day as a clock hour: tick 0 is 6 in the morning. */ + static double hourOf(PlatformWorld world) { + return ((world.getTime() / TICKS_PER_HOUR) + HOURS_AT_TIME_ZERO) % HOURS_PER_DAY; + } +} diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java index c941d7702..e219c7b2f 100644 --- a/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java +++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnModule.java @@ -18,16 +18,21 @@ package art.arcane.iris.engine.spawn; +import art.arcane.iris.builtin.spawn.EffectSettings; +import art.arcane.iris.builtin.spawn.SpawnerSettings; import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; +import com.volmit.service.AmbientEffects; import com.volmit.service.EntitySpawns; import com.volmit.stage.StageGraph; /** - * Module {@code iris:spawn}: the spawners, entities and markers of the pack ({@link SpawnResources}), and the entities that appear in the world - * over time because of them. It has no generation stage; Iris asks it through {@link EntitySpawns} when it looks for - * something to spawn in a chunk or at a marker. + * Module {@code iris:spawn}: the spawners, entities and markers of the pack ({@link SpawnResources}), the + * {@link SpawnerSettings} that dimensions, regions and biomes list, the entities that appear in the world over time + * because of them, and the ambient effects ({@link EffectSettings}) that play around players. It has no generation + * stage; Iris asks it through {@link EntitySpawns} when it looks for something to spawn in a chunk or at a marker, and + * through {@link AmbientEffects} for the effects due around a player. */ public final class SpawnModule implements IrisModule { private static final String VERSION = "built-in"; @@ -43,7 +48,10 @@ public final class SpawnModule implements IrisModule { @Override public void register(FeatureRegistry registry) { + registry.registerSettings(SpawnerSettings.class); + registry.registerSettings(EffectSettings.class); SpawnResources.kinds().forEach(registry::registerResourceKind); registry.registerService(EntitySpawns.class, new EntitySpawning()); + registry.registerService(AmbientEffects.class, new AmbientEffecting()); } } diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java index b5c25a6b2..fa12eefd2 100644 --- a/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java +++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnResources.java @@ -18,15 +18,15 @@ package art.arcane.iris.engine.spawn; +import art.arcane.iris.builtin.spawn.EntityDefinition; +import art.arcane.iris.builtin.spawn.SpawnMarker; +import art.arcane.iris.builtin.spawn.Spawner; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.modules.IrisPackResources; -import art.arcane.iris.engine.object.entity.IrisEntity; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; -import art.arcane.iris.engine.object.marker.IrisMarker; -import art.arcane.volmlib.util.collection.KList; import com.volmit.resource.ResourceId; import com.volmit.resource.ResourceKind; +import java.util.ArrayList; import java.util.List; /** @@ -39,39 +39,43 @@ import java.util.List; */ public final class SpawnResources { /** Spawners, in {@code spawners/}. */ - public static final ResourceKind SPAWNERS = ResourceKind.of("iris:spawn/spawner", "spawners", IrisSpawner.class); + public static final ResourceKind SPAWNERS = ResourceKind.of("iris:spawn/spawner", "spawners", Spawner.class); /** Entities, in {@code entities/}. */ - public static final ResourceKind ENTITIES = ResourceKind.of("iris:spawn/entity", "entities", IrisEntity.class); + public static final ResourceKind ENTITIES = ResourceKind.of("iris:spawn/entity", "entities", EntityDefinition.class); /** Markers, in {@code markers/}. */ - public static final ResourceKind MARKERS = ResourceKind.of("iris:spawn/marker", "markers", IrisMarker.class); + public static final ResourceKind MARKERS = ResourceKind.of("iris:spawn/marker", "markers", SpawnMarker.class); private SpawnResources() { } + /** A spawner and the key the pack names it by. */ + public record KeyedSpawner(String key, Spawner spawner) { + } + /** Every resource kind of the spawn module. */ public static List> kinds() { return List.of(SPAWNERS, ENTITIES, MARKERS); } - public static IrisSpawner spawner(IrisData data, String key) { + public static Spawner spawner(IrisData data, String key) { return find(data, SPAWNERS, key); } - public static IrisEntity entity(IrisData data, String key) { + public static EntityDefinition entity(IrisData data, String key) { return find(data, ENTITIES, key); } - public static IrisMarker marker(IrisData data, String key) { + public static SpawnMarker marker(IrisData data, String key) { return find(data, MARKERS, key); } /** The spawners of the pack named by {@code keys}, in order, without the ones the pack lacks. */ - public static KList spawners(IrisData data, List keys) { - KList spawners = new KList<>(); + public static List spawners(IrisData data, List keys) { + List spawners = new ArrayList<>(); for (String key : keys) { - IrisSpawner spawner = spawner(data, key); + Spawner spawner = spawner(data, key); if (spawner != null) { - spawners.add(spawner); + spawners.add(new KeyedSpawner(key, spawner)); } } return spawners; diff --git a/src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java b/src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java new file mode 100644 index 000000000..74bbfb95b --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/spawn/SpawnerGate.java @@ -0,0 +1,97 @@ +/* + * 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.spawn; + +import art.arcane.iris.builtin.spawn.SpawnRate; +import art.arcane.iris.builtin.spawn.Spawner; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import art.arcane.iris.spi.PlatformWorld; + +/** + * Whether a spawner may fire: in a biome of the kind its group wants, in the time and weather it asks for, and not + * more often than its rates allow. The rates count in the engine's persisted data, by the key the pack names the + * spawner by. + */ +final class SpawnerGate { + private SpawnerGate() { + } + + /** Whether a spawner of this group fires in {@code biome}. */ + static boolean suits(Spawner spawner, IrisBiome biome) { + return switch (spawner.group()) { + case NORMAL -> switch (biome.getInferredType()) { + case SHORE, SEA, CAVE -> false; + case LAND -> true; + }; + case CAVE -> true; + case UNDERWATER -> switch (biome.getInferredType()) { + case SHORE, LAND, CAVE -> false; + case SEA -> true; + }; + case BEACH -> switch (biome.getInferredType()) { + case SHORE -> true; + case LAND, CAVE, SEA -> false; + }; + }; + } + + /** Whether the world is in the time and weather the spawner asks for. */ + static boolean suits(Spawner spawner, PlatformWorld world) { + return SpawnConditions.allow(spawner.timeBlock(), spawner.weather(), world); + } + + /** Whether the spawner may fire in the chunk now. */ + static boolean canSpawn(String key, Spawner spawner, Engine engine, int chunkX, int chunkZ) { + if (!canSpawn(key, spawner, engine)) { + return false; + } + + SpawnRate rate = spawner.maximumRatePerChunk(); + return rate.isInfinite() || engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(key).canSpawn(rate.interval()); + } + + /** Counts a spawn of the spawner in the chunk against its rates. */ + static void spawned(String key, Spawner spawner, Engine engine, int chunkX, int chunkZ) { + spawned(key, spawner, engine); + if (spawner.maximumRatePerChunk().isInfinite()) { + return; + } + + engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(key).spawn(); + } + + private static boolean canSpawn(String key, Spawner spawner, Engine engine) { + PlatformWorld world = engine.getWorld().platformWorld(); + if (world == null || !suits(spawner, world)) { + return false; + } + + SpawnRate rate = spawner.maximumRate(); + return rate.isInfinite() || engine.getEngineData().getCooldown(key).canSpawn(rate.interval()); + } + + private static void spawned(String key, Spawner spawner, Engine engine) { + if (spawner.maximumRate().isInfinite()) { + return; + } + + engine.getEngineData().getCooldown(key).spawn(); + } +} From cff492ada8ff440fb5ff3d42fe89c733a50e8cfd Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:51:28 +0200 Subject: [PATCH 4/7] Caves and floating islands are settings of iris:carve and iris:floating caveProfile (CaveProfile is the feature, held by dimension, region and biome), carving (CarvingSettings of CarvingEntry), carvingEnabled, carvingBiome and caveMinDepthBelowSurface are iris:carve settings; floatingChildBiomes and mergeFloatingChildBiomes are iris:floating settings, all under the keys and shapes packs always wrote. CarvingEntry is IrisApi-typed; ResolvedCarvingEntry, CarvingBands (the world's bands) and CarvingResolver (was IrisDimensionCarvingResolver) hold the behaviour, CaveProfiles and FloatingChildren read the settings. iris:carve provides CaveBiomes (CaveBiomeBands). CarvingBiomeSettings, CarvingSettings and FloatingChildSettings implement LinkedBiomes, so the biome tree and the biomes a dimension reaches learn of the biomes they name without reading the classes. IrisBiome, IrisRegion and IrisDimension lose the fields, the carving entry index and getRealCarvingBiome; IrisDimensionCarvingEntry is deleted. CaveApplying and DepositPlacer no longer thread a resolver state through the cave biome lookup. --- README.md | 16 ++- .../builtin/carve/CarvingBiomeSettings.java | 54 ++++++++ .../builtin/carve/CarvingEnabledSettings.java | 43 ++++++ .../iris/builtin/carve/CarvingEntry.java | 103 ++++++++++++++ .../iris/builtin/carve/CarvingSettings.java | 80 +++++++++++ .../iris/builtin/carve/CaveDepthSettings.java | 47 +++++++ .../iris/builtin/carve/CaveProfile.java | 9 +- .../floating/FloatingChildSettings.java | 70 ++++++++++ .../MergeFloatingChildrenSettings.java | 43 ++++++ .../iris/engine/actuator/ResolvedOre.java | 12 +- .../iris/engine/actuator/TerrainOres.java | 9 +- .../engine/mantle/components/CaveCarving.java | 62 +++++---- .../FloatingIslandSampleResolver.java | 3 +- .../components/FloatingObjectPlacing.java | 4 +- .../mantle/components/ObjectPlacing.java | 13 +- .../iris/engine/modifier/CarveModule.java | 16 ++- .../iris/engine/modifier/CaveApplying.java | 53 ++++---- .../iris/engine/modifier/CaveBiomeBands.java | 61 +++++++++ .../iris/engine/modifier/DepositPlacer.java | 11 +- .../iris/engine/modifier/FloatingIslands.java | 5 +- .../iris/engine/modifier/FloatingModule.java | 6 +- .../object/terrain/carving/CarvingBands.java | 71 ++++++++++ ...vingResolver.java => CarvingResolver.java} | 126 ++++++++---------- .../object/terrain/carving/CaveProfiles.java | 33 +++++ .../carving/IrisDimensionCarvingEntry.java | 84 ------------ .../terrain/carving/ResolvedCarvingEntry.java | 101 ++++++++++++++ .../terrain/floating/FloatingChildren.java | 13 ++ .../floating/FloatingIslandSample.java | 6 +- .../floating/ResolvedFloatingChild.java | 22 +-- .../engine/object/world/biome/IrisBiome.java | 30 ----- .../object/world/dimension/IrisDimension.java | 69 +--------- .../object/world/region/IrisRegion.java | 8 +- 32 files changed, 927 insertions(+), 356 deletions(-) create mode 100644 src/main/java/art/arcane/iris/builtin/carve/CarvingBiomeSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/carve/CarvingEnabledSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/carve/CarvingEntry.java create mode 100644 src/main/java/art/arcane/iris/builtin/carve/CarvingSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/carve/CaveDepthSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/floating/FloatingChildSettings.java create mode 100644 src/main/java/art/arcane/iris/builtin/floating/MergeFloatingChildrenSettings.java create mode 100644 src/main/java/art/arcane/iris/engine/modifier/CaveBiomeBands.java create mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/carving/CarvingBands.java rename src/main/java/art/arcane/iris/engine/object/terrain/carving/{IrisDimensionCarvingResolver.java => CarvingResolver.java} (69%) create mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/carving/CaveProfiles.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/carving/IrisDimensionCarvingEntry.java create mode 100644 src/main/java/art/arcane/iris/engine/object/terrain/carving/ResolvedCarvingEntry.java diff --git a/README.md b/README.md index 4bf62dc47..84c19c521 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ only: `DepositSettings` holds `DepositGenerator`s (blocks as `BlockSpec`, its en `art.arcane.iris.builtin.deposit`), and packs write `"deposits": [...]`, as they always have (`@Feature(key = "deposits", root = "generators")`: the key holds the one option's list). What needs Iris (resolving the palette, ore checks, clump shapes per world seed) lives in the module's own code, `ResolvedDeposit`. -Settings that live inside a class of Iris's own, such as an object placement's clamp, stilt, vacuum and edit settings, its slope condition, -a cave profile, a floating child biome or a procedural coral, are module-owned classes too (`art.arcane.iris.builtin.validate`, +Settings that live inside a class of Iris's own, such as an object placement's clamp, stilt, vacuum and edit settings, its slope condition +or a procedural coral, are module-owned classes too (`art.arcane.iris.builtin.validate`, `.stilt`, `.vacuum`, `.blocks`, `.prepare`, `.carve`, `.floating`, `.objects.*`). The module registers each with `registry.registerHeldType(...)` so studio describes it from the module's own annotations; packs write the same JSON as before. Behaviour that needs Iris (noise built from the styles, blocks resolved through the pack, baked object variants) lives in `Resolved*` classes beside the @@ -64,6 +64,18 @@ seed is the world's decorator seed, its biome's key and its place in the biome's them ahead of generation; `iris:terrain` and `iris:objects` warm their ore generators, placements and procedural objects the same way. +Caves, floating islands and ores are settings of their modules too, written under the keys they always had. `iris:carve` owns +`caveProfile` (dimension, region, biome; an object, or a `snippet/cave-profile/...` reference), `carving` (dimension; a list of bands) and +`carvingEnabled` (dimension; a boolean), `carvingBiome` (biome; a biome key) and `caveMinDepthBelowSurface` (biome; a number). `iris:floating` +owns `floatingChildBiomes` (biome; a list) and `mergeFloatingChildBiomes` (biome; a boolean). `iris:terrain` owns `ores` (dimension, region, +biome; a list of generators) and `hideOresForHiddenOre` (dimension; a boolean); `iris:deposit` owns `depositVariants` (dimension, region, biome; a list) +and `oreDepositFrequencyMultiplier` and `oreDepositSizeMultiplier` (biome; numbers). Behaviour that needs Iris lives in the `Resolved*` classes beside the +workers: `ResolvedOre`/`ResolvedOres` (blocks and chance noise per world, `TerrainOres` the world's state), `ResolvedDepositVariant`, +`ResolvedCarvingEntry`/`CarvingBands`/`CarvingResolver` (the band for a position) and `ResolvedFloatingChild`. The settings that name biomes +(`carvingBiome`, a band's biome, a floating child's target and carving) implement `LinkedBiomes`, which is how Iris's biome tree and the biomes a +dimension reaches learn of them without reading the settings classes; and `iris:carve` provides the `CaveBiomes` service +(`CaveBiomeBands`), which Iris asks for the dimension's carving band at a position and for a biome's minimum cave depth. + Packs write each settings feature under the short key it declares: `deposits` (dimension, region, biome; a list), `decorators` (biome; a list) and `importedStructures` (dimension; an object of `disabled`, `adjustments` and the rest). The feature ids (`iris:deposit`, `iris:decorant`, `iris:structure`) stay the modules' identity in the stage graph and logs. A key is unique diff --git a/src/main/java/art/arcane/iris/builtin/carve/CarvingBiomeSettings.java b/src/main/java/art/arcane/iris/builtin/carve/CarvingBiomeSettings.java new file mode 100644 index 000000000..e2942aecb --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/carve/CarvingBiomeSettings.java @@ -0,0 +1,54 @@ +/* + * 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.carve; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.LinkedBiomes; +import com.volmit.config.Ref; +import com.volmit.config.Reference; + +import java.util.Set; + +/** A biome's {@code carvingBiome}, written as the biome key: it registers that biome with the pack's layout and is not applied as a substitute under carvings. */ +@Desc("Registers the referenced biome with this pack's reachable biome set. It is NOT applied as a substitute under carvings; cave biomes come from the region's caveBiomes list.") +@Feature(id = "iris:carve/biome", name = "Carving biome", key = "carvingBiome", root = "biome", targets = Target.BIOME) +public final class CarvingBiomeSettings implements IrisFeature, LinkedBiomes { + @Ref(Reference.PACK_BIOME) + @Desc("Registers the referenced biome with this pack's reachable biome set. It is NOT applied as a substitute under carvings; cave biomes come from the region's caveBiomes list.") + private String biome = ""; + + public CarvingBiomeSettings() { + } + + public CarvingBiomeSettings(String biome) { + this.biome = biome; + } + + public String biome() { + return biome == null ? "" : biome; + } + + @Override + public Set treeBiomes() { + return Set.of(biome()); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/carve/CarvingEnabledSettings.java b/src/main/java/art/arcane/iris/builtin/carve/CarvingEnabledSettings.java new file mode 100644 index 000000000..d09f7e7ac --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/carve/CarvingEnabledSettings.java @@ -0,0 +1,43 @@ +/* + * 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.carve; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** A dimension's {@code carvingEnabled}, written as the bare boolean. */ +@Desc("Enable or disable all carving for this dimension") +@Feature(id = "iris:carve/enabled", name = "Carving enabled", key = "carvingEnabled", root = "enabled", targets = Target.DIMENSION) +public final class CarvingEnabledSettings implements IrisFeature { + @Desc("Enable or disable all carving for this dimension") + private boolean enabled = true; + + public CarvingEnabledSettings() { + } + + public CarvingEnabledSettings(boolean enabled) { + this.enabled = enabled; + } + + public boolean enabled() { + return enabled; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/carve/CarvingEntry.java b/src/main/java/art/arcane/iris/builtin/carve/CarvingEntry.java new file mode 100644 index 000000000..7508832a7 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/carve/CarvingEntry.java @@ -0,0 +1,103 @@ +/* + * 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.carve; + +import com.volmit.config.Desc; +import com.volmit.config.Range; +import com.volmit.config.Ref; +import com.volmit.config.Reference; +import com.volmit.config.Snippet; +import com.volmit.noise.NoiseStyle; + +import java.util.Collections; +import java.util.List; + +/** + * One dimension-level cave biome override, an entry of {@code carving}: a pack biome that replaces the cave biome within a band + * of world Y, optionally split into child entries by a noise pattern. IrisApi types only; {@code CarvingResolver} picks + * the entry for a position. + */ +@Snippet("dimension-carving-entry") +@Desc("Dimension-level cave biome override with absolute world Y bounds.") +public final class CarvingEntry { + private static final double DEFAULT_WORLD_Y_MIN = -64; + private static final double DEFAULT_WORLD_Y_MAX = 320; + private static final double DEFAULT_CHILD_SHRINK_FACTOR = 1.5; + private static final int DEFAULT_CHILD_RECURSION_DEPTH = 3; + + @Desc("Stable id for this carving entry") + private String id = ""; + + @Desc("Enable or disable this carving entry") + private boolean enabled = true; + + @Ref(Reference.PACK_BIOME) + @Desc("Cave biome to apply when world Y falls within worldYRange") + private String biome = ""; + + @Desc("Absolute world Y bounds where this carving entry applies") + private Range worldYRange = Range.of(DEFAULT_WORLD_Y_MIN, DEFAULT_WORLD_Y_MAX); + + @Desc("If this carving entry has child carving entries, this controls how small those child carving patches are.") + private double childShrinkFactor = DEFAULT_CHILD_SHRINK_FACTOR; + + @Desc("If this carving entry has child carving entries, this controls the shape pattern used to pick them.") + private NoiseStyle childStyle = NoiseStyle.of("CELLULAR_IRIS_DOUBLE"); + + @Desc("Child carving entry ids. Child ids can point back to parent ids to create cycles; recursion is bounded by childRecursionDepth.") + private List children = List.of(); + + @Desc("Maximum recursion depth when resolving child carving entries from this entry.") + private int childRecursionDepth = DEFAULT_CHILD_RECURSION_DEPTH; + + public CarvingEntry() { + } + + public String id() { + return id == null ? "" : id; + } + + public boolean enabled() { + return enabled; + } + + public String biome() { + return biome == null ? "" : biome; + } + + public Range worldYRange() { + return worldYRange; + } + + public double childShrinkFactor() { + return childShrinkFactor; + } + + public NoiseStyle childStyle() { + return childStyle; + } + + public List children() { + return children == null ? List.of() : Collections.unmodifiableList(children); + } + + public int childRecursionDepth() { + return childRecursionDepth; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/carve/CarvingSettings.java b/src/main/java/art/arcane/iris/builtin/carve/CarvingSettings.java new file mode 100644 index 000000000..afd544963 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/carve/CarvingSettings.java @@ -0,0 +1,80 @@ +/* + * 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.carve; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.LinkedBiomes; +import com.volmit.config.MinItems; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * The cave biome overrides a dimension declares, written as {@code "carving": [...]}, the list of {@link CarvingEntry}s. + * The biome of every enabled entry takes part in the pack's layout like any biome the dimension reaches. + */ +@Desc("Dimension-level cave biome carving overrides with absolute world Y ranges") +@Feature(id = "iris:carve/bands", name = "Cave biome bands", key = "carving", root = "entries", targets = Target.DIMENSION) +public final class CarvingSettings implements IrisFeature, LinkedBiomes { + @MinItems(1) + @Desc("Dimension-level cave biome carving overrides with absolute world Y ranges") + private List entries = List.of(); + + public CarvingSettings() { + } + + public CarvingSettings(List entries) { + this.entries = List.copyOf(entries); + } + + public List entries() { + return entries == null ? List.of() : Collections.unmodifiableList(entries); + } + + /** + * The biome key {@code reference} stands for: the biome of the entry with that id, ignoring surrounding blanks, or + * {@code reference} itself when no entry has the id. When several entries share an id the last one counts. + */ + public String biomeOf(String reference) { + CarvingEntry entry = null; + for (CarvingEntry candidate : entries()) { + if (candidate != null && !candidate.id().isBlank() && candidate.id().trim().equals(reference)) { + entry = candidate; + } + } + return entry == null ? reference : entry.biome(); + } + + @Override + public Set usedBiomes(Collection dimension) { + Set biomes = new LinkedHashSet<>(); + for (CarvingEntry entry : entries()) { + if (entry != null && entry.enabled()) { + biomes.add(entry.biome()); + } + } + return biomes; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/carve/CaveDepthSettings.java b/src/main/java/art/arcane/iris/builtin/carve/CaveDepthSettings.java new file mode 100644 index 000000000..08f005403 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/carve/CaveDepthSettings.java @@ -0,0 +1,47 @@ +/* + * 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.carve; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.MaxNumber; +import com.volmit.config.MinNumber; + +/** A biome's {@code caveMinDepthBelowSurface}, written as the bare number of blocks. */ +@Desc("Minimum depth below terrain surface required before this cave biome can be selected.") +@Feature(id = "iris:carve/min-depth", name = "Cave minimum depth", key = "caveMinDepthBelowSurface", root = "depth", targets = Target.BIOME) +public final class CaveDepthSettings implements IrisFeature { + @MinNumber(0) + @MaxNumber(256) + @Desc("Minimum depth below terrain surface required before this cave biome can be selected.") + private int depth = 0; + + public CaveDepthSettings() { + } + + public CaveDepthSettings(int depth) { + this.depth = depth; + } + + public int depth() { + return depth; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/carve/CaveProfile.java b/src/main/java/art/arcane/iris/builtin/carve/CaveProfile.java index 0884897b3..a64df4d67 100644 --- a/src/main/java/art/arcane/iris/builtin/carve/CaveProfile.java +++ b/src/main/java/art/arcane/iris/builtin/carve/CaveProfile.java @@ -19,7 +19,10 @@ package art.arcane.iris.builtin.carve; import art.arcane.iris.builtin.anchor.ObjectPlaceMode; +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; import com.volmit.config.Desc; +import com.volmit.config.Feature; import com.volmit.config.MaxNumber; import com.volmit.config.MinItems; import com.volmit.config.MinNumber; @@ -35,11 +38,13 @@ import java.util.Optional; /** * A 3D cave profile as packs write it for a dimension, region or biome ({@code caveProfile}) or under * {@code snippet/cave-profile/}: the noise fields that decide where caves are, how they meet the surface, where - * cave fluid may sit and how objects find anchors in them. IrisApi types only; the carving module builds the noise. + * cave fluid may sit and how objects find anchors in them. A level that writes none has no profile, which is the + * same as one that is not {@code enabled}. IrisApi types only; the carving module builds the noise. */ @Snippet("cave-profile") @Desc("Represents a configurable 3D cave profile.") -public final class CaveProfile { +@Feature(id = "iris:carve/profile", name = "Cave profile", key = "caveProfile", targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) +public final class CaveProfile implements IrisFeature { @Desc("Enable profile-driven cave carving.") private boolean enabled = false; diff --git a/src/main/java/art/arcane/iris/builtin/floating/FloatingChildSettings.java b/src/main/java/art/arcane/iris/builtin/floating/FloatingChildSettings.java new file mode 100644 index 000000000..796b062f8 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/floating/FloatingChildSettings.java @@ -0,0 +1,70 @@ +/* + * 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.floating; + +import art.arcane.iris.builtin.carve.CarvingSettings; +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; +import com.volmit.config.LinkedBiomes; +import com.volmit.config.MinItems; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * The floating child biomes one biome declares, written as {@code "floatingChildBiomes": [...]}, the list of + * {@link FloatingChildBiome}s. The target biome of every child, and the biome its {@code carving} names, take part in the + * pack's layout like any biome a dimension reaches. + */ +@Desc("Floating child biomes that procedurally generate above this biome's terrain. Each entry references a target biome whose layers, decorators, and objects drive the floating island's visual design, while the config here drives size, shape, altitude, rarity, and water level. Multiple entries are supported and selected by rarity per column unless mergeFloatingChildBiomes is enabled.") +@Feature(id = "iris:floating/children", name = "Floating child biomes", key = "floatingChildBiomes", root = "children", targets = Target.BIOME) +public final class FloatingChildSettings implements IrisFeature, LinkedBiomes { + @MinItems(1) + @Desc("Floating child biomes that procedurally generate above this biome's terrain. Each entry references a target biome whose layers, decorators, and objects drive the floating island's visual design, while the config here drives size, shape, altitude, rarity, and water level. Multiple entries are supported and selected by rarity per column unless mergeFloatingChildBiomes is enabled.") + private List children = List.of(); + + public FloatingChildSettings() { + } + + public FloatingChildSettings(List children) { + this.children = List.copyOf(children); + } + + public List children() { + return children == null ? List.of() : Collections.unmodifiableList(children); + } + + @Override + public Set usedBiomes(Collection dimension) { + CarvingSettings carving = dimension.stream().filter(CarvingSettings.class::isInstance).map(CarvingSettings.class::cast).findFirst().orElse(null); + Set biomes = new LinkedHashSet<>(); + for (FloatingChildBiome child : children()) { + if (child != null) { + biomes.add(child.biome()); + biomes.add(carving == null ? child.carving() : carving.biomeOf(child.carving())); + } + } + return biomes; + } +} diff --git a/src/main/java/art/arcane/iris/builtin/floating/MergeFloatingChildrenSettings.java b/src/main/java/art/arcane/iris/builtin/floating/MergeFloatingChildrenSettings.java new file mode 100644 index 000000000..24224b836 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/floating/MergeFloatingChildrenSettings.java @@ -0,0 +1,43 @@ +/* + * 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.floating; + +import com.volmit.FeatureAttachment.Target; +import com.volmit.IrisFeature; +import com.volmit.config.Desc; +import com.volmit.config.Feature; + +/** A biome's {@code mergeFloatingChildBiomes}, written as the bare boolean. */ +@Desc("When true, every floating child entry is sampled independently and their solid masks are unioned, so multiple floating islands can stack, overlap, and collide instead of the picker choosing only one child per column.") +@Feature(id = "iris:floating/merge", name = "Merge floating child biomes", key = "mergeFloatingChildBiomes", root = "merge", targets = Target.BIOME) +public final class MergeFloatingChildrenSettings implements IrisFeature { + @Desc("When true, every floating child entry is sampled independently and their solid masks are unioned, so multiple floating islands can stack, overlap, and collide instead of the picker choosing only one child per column.") + private boolean merge = false; + + public MergeFloatingChildrenSettings() { + } + + public MergeFloatingChildrenSettings(boolean merge) { + this.merge = merge; + } + + public boolean merge() { + return merge; + } +} diff --git a/src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java b/src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java index ee0b330a4..721dbbb0c 100644 --- a/src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java +++ b/src/main/java/art/arcane/iris/engine/actuator/ResolvedOre.java @@ -105,13 +105,21 @@ final class ResolvedOre { if (settings.palette().palette().isEmpty()) { return null; } - NoiseSampler sampler = chance.aquire(() -> noise.sampler(settings.chanceStyle(), terrainSeed)); - if (sampler.sample(x, y, z) > settings.threshold()) { + if (chanceNoise().sample(x, y, z) > settings.threshold()) { return null; } return pick(x, y, z); } + /** The chance noise, which this runs per block of the terrain, so a built one is read without creating a supplier. */ + private NoiseSampler chanceNoise() { + NoiseSampler built = chance.getIfPresent(); + if (built != null) { + return built; + } + return chance.aquire(() -> noise.sampler(settings.chanceStyle(), terrainSeed)); + } + private PlatformBlockState pick(int x, int y, int z) { if (blocks.isEmpty()) { return null; diff --git a/src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java b/src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java index 8dc6a9b0e..1eb73d719 100644 --- a/src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java +++ b/src/main/java/art/arcane/iris/engine/actuator/TerrainOres.java @@ -42,12 +42,19 @@ final class TerrainOres { return engine.getGeneration().state(TerrainOres.class, TerrainOres::new); } - /** The ore generators {@code owner}, a dimension, region or biome, declares; {@link ResolvedOres#NONE} when it declares none. */ + /** + * The ore generators {@code owner}, a dimension, region or biome, declares; {@link ResolvedOres#NONE} when it declares none. The + * terrain asks this for two owners per column, so a resolved set is read without taking the map's lock. + */ ResolvedOres of(IrisRegistrant owner) { OreSettings settings = owner.getModuleSettings().find(OreSettings.class).orElse(null); if (settings == null) { return ResolvedOres.NONE; } + ResolvedOres existing = resolved.get(settings); + if (existing != null) { + return existing; + } return resolved.computeIfAbsent(settings, declared -> ResolvedOres.of(declared, engine)); } } diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java b/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java index 2660dc3f2..da5c48f1e 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/CaveCarving.java @@ -19,13 +19,17 @@ package art.arcane.iris.engine.mantle.components; import art.arcane.iris.builtin.carve.CaveProfile; +import art.arcane.iris.core.modules.IrisValues; import art.arcane.iris.engine.IrisComplex; import art.arcane.iris.engine.UpperDimensionContext; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.mantle.MantleWriter; +import art.arcane.iris.engine.object.terrain.carving.CaveProfiles; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingEntry; -import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver; +import art.arcane.iris.engine.object.terrain.carving.ResolvedCarvingEntry; +import art.arcane.iris.engine.modifier.CaveBiomeBands; +import art.arcane.iris.engine.object.terrain.carving.CarvingBands; +import art.arcane.iris.engine.object.terrain.carving.CarvingResolver; import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.engine.object.value.IrisRange; import art.arcane.iris.spi.PlatformBlockState; @@ -89,7 +93,7 @@ public class CaveCarving { /** Carves the caves of the chunk at chunk coordinates {@code x}, {@code z} into {@code writer}. */ public void carve(MantleWriter writer, int x, int z, ChunkContext context) { IrisComplex complex = context.getComplex(); - IrisDimensionCarvingResolver.State resolverState = new IrisDimensionCarvingResolver.State(); + CarvingResolver.State resolverState = new CarvingResolver.State(); BlendScratch blendScratch = BLEND_SCRATCH.get(); int[] chunkSurfaceHeights = prepareChunkSurfaceHeights(x, z, context, blendScratch.chunkSurfaceHeights); PrecisionStopwatch resolveStopwatch = PrecisionStopwatch.start(); @@ -200,7 +204,7 @@ public class CaveCarving { } } - private List resolveWeightedProfiles(int chunkX, int chunkZ, IrisComplex complex, IrisDimensionCarvingResolver.State resolverState) { + private List resolveWeightedProfiles(int chunkX, int chunkZ, IrisComplex complex, CarvingResolver.State resolverState) { BlendScratch blendScratch = BLEND_SCRATCH.get(); CaveProfile[] profileField = blendScratch.profileField; Map columnProfileWeights = blendScratch.columnProfileWeights; @@ -296,40 +300,40 @@ public class CaveCarving { return resolvedProfiles; } - private List resolveDimensionCarvingProfiles(int chunkX, int chunkZ, IrisDimensionCarvingResolver.State resolverState, BlendScratch blendScratch) { + private List resolveDimensionCarvingProfiles(int chunkX, int chunkZ, CarvingResolver.State resolverState, BlendScratch blendScratch) { List weightedProfiles = new ArrayList<>(); - List entries = engine.getDimension().getCarving(); - if (entries == null || entries.isEmpty()) { + List entries = CarvingBands.of(engine).entries(); + if (entries.isEmpty()) { return weightedProfiles; } - Map dimensionColumnPlans = blendScratch.dimensionColumnPlans; + Map dimensionColumnPlans = blendScratch.dimensionColumnPlans; dimensionColumnPlans.clear(); - for (IrisDimensionCarvingEntry entry : entries) { - if (entry == null || !entry.isEnabled()) { + for (ResolvedCarvingEntry entry : entries) { + if (!entry.enabled()) { continue; } - IrisBiome rootBiome = IrisDimensionCarvingResolver.resolveEntryBiome(engine, entry, resolverState); + IrisBiome rootBiome = CarvingResolver.resolveEntryBiome(engine, entry, resolverState); if (rootBiome == null) { continue; } - IrisDimensionCarvingEntry[] columnPlan = dimensionColumnPlans.computeIfAbsent(entry, key -> new IrisDimensionCarvingEntry[CHUNK_AREA]); + ResolvedCarvingEntry[] columnPlan = dimensionColumnPlans.computeIfAbsent(entry, key -> new ResolvedCarvingEntry[CHUNK_AREA]); buildDimensionColumnPlan(columnPlan, chunkX, chunkZ, entry, resolverState); Map rootProfileColumnWeights = new IdentityHashMap<>(); List rootProfileOrder = new ArrayList<>(); - IrisRange worldYRange = entry.getWorldYRange(); + IrisRange worldYRange = entry.worldYRange() == null ? null : IrisValues.range(entry.worldYRange()); for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) { - IrisDimensionCarvingEntry resolvedEntry = columnPlan[columnIndex]; - IrisBiome resolvedBiome = IrisDimensionCarvingResolver.resolveEntryBiome(engine, resolvedEntry, resolverState); + ResolvedCarvingEntry resolvedEntry = columnPlan[columnIndex]; + IrisBiome resolvedBiome = CarvingResolver.resolveEntryBiome(engine, resolvedEntry, resolverState); if (resolvedBiome == null) { continue; } - CaveProfile profile = resolvedBiome.getCaveProfile(); + CaveProfile profile = CaveProfiles.declaredBy(resolvedBiome); if (!isProfileEnabled(profile)) { continue; } @@ -351,7 +355,7 @@ public class CaveCarving { return weightedProfiles; } - private void buildDimensionColumnPlan(IrisDimensionCarvingEntry[] columnPlan, int chunkX, int chunkZ, IrisDimensionCarvingEntry entry, IrisDimensionCarvingResolver.State resolverState) { + private void buildDimensionColumnPlan(ResolvedCarvingEntry[] columnPlan, int chunkX, int chunkZ, ResolvedCarvingEntry entry, CarvingResolver.State resolverState) { int baseX = PowerOfTwoCoordinates.chunkToBlock(chunkX); int baseZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ); for (int localX = 0; localX < CHUNK_SIZE; localX++) { @@ -359,12 +363,12 @@ public class CaveCarving { for (int localZ = 0; localZ < CHUNK_SIZE; localZ++) { int worldZ = baseZ + localZ; int columnIndex = PowerOfTwoCoordinates.packLocal16(localX, localZ); - columnPlan[columnIndex] = IrisDimensionCarvingResolver.resolveFromRoot(engine, entry, worldX, worldZ, resolverState); + columnPlan[columnIndex] = CarvingResolver.resolveFromRoot(engine, entry, worldX, worldZ, resolverState); } } } - private void fillProfileField(CaveProfile[] profileField, int chunkX, int chunkZ, IrisComplex complex, IrisDimensionCarvingResolver.State resolverState, BlendScratch blendScratch) { + private void fillProfileField(CaveProfile[] profileField, int chunkX, int chunkZ, IrisComplex complex, CarvingResolver.State resolverState, BlendScratch blendScratch) { int startX = PowerOfTwoCoordinates.chunkToBlock(chunkX) - BLEND_RADIUS; int startZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ) - BLEND_RADIUS; prefillProfileFieldSamples(startX, startZ, complex, blendScratch); @@ -404,23 +408,23 @@ public class CaveCarving { IrisRegion region, IrisBiome surfaceBiome, IrisBiome caveBiome, - IrisDimensionCarvingResolver.State resolverState + CarvingResolver.State resolverState ) { CaveProfile resolved = null; - CaveProfile dimensionProfile = engine.getDimension().getCaveProfile(); + CaveProfile dimensionProfile = CaveProfiles.declaredBy(engine.getDimension()); if (isProfileEnabled(dimensionProfile)) { resolved = dimensionProfile; } if (region != null) { - CaveProfile regionProfile = region.getCaveProfile(); + CaveProfile regionProfile = CaveProfiles.declaredBy(region); if (isProfileEnabled(regionProfile)) { resolved = regionProfile; } } if (surfaceBiome != null) { - CaveProfile surfaceProfile = surfaceBiome.getCaveProfile(); + CaveProfile surfaceProfile = CaveProfiles.declaredBy(surfaceBiome); if (isProfileEnabled(surfaceProfile)) { resolved = surfaceProfile; } @@ -429,11 +433,11 @@ public class CaveCarving { int roundedSurfaceY = (int) Math.round(surfaceHeight); int sampleY = Math.max(1, roundedSurfaceY - 56); int worldY = sampleY + engine.getWorld().minHeight(); - IrisDimensionCarvingEntry rootCarvingEntry = IrisDimensionCarvingResolver.resolveRootEntry(engine, worldY, resolverState); + ResolvedCarvingEntry rootCarvingEntry = CarvingResolver.resolveRootEntry(engine, worldY, resolverState); IrisBiome resolvedCarvingBiome = null; if (rootCarvingEntry != null) { - IrisDimensionCarvingEntry resolvedCarvingEntry = IrisDimensionCarvingResolver.resolveFromRoot(engine, rootCarvingEntry, worldX, worldZ, resolverState); - resolvedCarvingBiome = IrisDimensionCarvingResolver.resolveEntryBiome(engine, resolvedCarvingEntry, resolverState); + ResolvedCarvingEntry resolvedCarvingEntry = CarvingResolver.resolveFromRoot(engine, rootCarvingEntry, worldX, worldZ, resolverState); + resolvedCarvingBiome = CarvingResolver.resolveEntryBiome(engine, resolvedCarvingEntry, resolverState); if (resolvedCarvingBiome != null) { caveBiome = resolvedCarvingBiome; } @@ -447,7 +451,7 @@ public class CaveCarving { if (depthBelowSurface <= 0) { effectiveCaveBiome = surfaceBiome; } else { - int minDepth = Math.max(0, caveBiome.getCaveMinDepthBelowSurface()); + int minDepth = Math.max(0, CaveBiomeBands.minDepthBelowSurface(caveBiome)); if (depthBelowSurface < minDepth) { effectiveCaveBiome = surfaceBiome; } @@ -455,7 +459,7 @@ public class CaveCarving { } } - CaveProfile caveProfile = effectiveCaveBiome.getCaveProfile(); + CaveProfile caveProfile = CaveProfiles.declaredBy(effectiveCaveBiome); if (isProfileEnabled(caveProfile)) { resolved = caveProfile; } @@ -680,7 +684,7 @@ public class CaveCarving { private final CaveProfile[] kernelProfiles = new CaveProfile[KERNEL_SIZE]; private final double[] kernelProfileWeights = new double[KERNEL_SIZE]; private final IdentityHashMap columnProfileWeights = new IdentityHashMap<>(); - private final IdentityHashMap dimensionColumnPlans = new IdentityHashMap<>(); + private final IdentityHashMap dimensionColumnPlans = new IdentityHashMap<>(); private final IdentityHashMap activeProfiles = new IdentityHashMap<>(); private final List profileOrder = new ArrayList<>(); private final double[] fieldSurfaceHeights = new double[FIELD_SIZE * FIELD_SIZE]; diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/FloatingIslandSampleResolver.java b/src/main/java/art/arcane/iris/engine/mantle/components/FloatingIslandSampleResolver.java index b80204f93..b45fbe693 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/FloatingIslandSampleResolver.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/FloatingIslandSampleResolver.java @@ -23,6 +23,7 @@ import art.arcane.iris.engine.data.cache.Cache; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.mantle.EngineMantle; import art.arcane.iris.engine.modifier.FloatingIslands; +import art.arcane.iris.engine.object.terrain.floating.FloatingChildren; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample; import art.arcane.iris.engine.object.world.biome.IrisBiome; @@ -56,7 +57,7 @@ final class FloatingIslandSampleResolver implements IslandObjectPlacer.SamplePro return sampleCache.get(key); } IrisBiome parent = parent(x, z); - if (parent == null || parent.getFloatingChildBiomes() == null || parent.getFloatingChildBiomes().isEmpty()) { + if (parent == null || FloatingChildren.declaredBy(parent).isEmpty()) { resolvedSamples.add(key); return null; } diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java b/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java index 2a74bfb86..6537c02ce 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java @@ -543,8 +543,8 @@ public class FloatingObjectPlacing { try { IrisData data = engine.getData(); for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) { - List settings = biome.getFloatingChildBiomes(); - if (settings == null || settings.isEmpty()) { + List settings = FloatingChildren.declaredBy(biome); + if (settings.isEmpty()) { continue; } for (ResolvedFloatingChild entry : FloatingChildren.of(engine).of(settings)) { diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java index 88d18f4b8..288e9c139 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java @@ -25,6 +25,7 @@ import art.arcane.iris.builtin.carve.CaveAnchorMode; import art.arcane.iris.builtin.carve.CaveProfile; import art.arcane.iris.builtin.anchor.ObjectPlaceMode; import art.arcane.iris.builtin.prepare.AxisRotationClamp; +import art.arcane.iris.engine.object.terrain.carving.CaveProfiles; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.placement.IrisObjectVacuum; import art.arcane.iris.core.IrisSettings; @@ -235,8 +236,8 @@ public class ObjectPlacing { int rejected = 0; int nullObjects = 0; int errors = 0; - CaveProfile biomeCaveProfile = resolveCaveProfile(caveBiome.getCaveProfile(), region.getCaveProfile()); - CaveProfile regionCaveProfile = resolveCaveProfile(region.getCaveProfile(), caveBiome.getCaveProfile()); + CaveProfile biomeCaveProfile = resolveCaveProfile(CaveProfiles.declaredBy(caveBiome), CaveProfiles.declaredBy(region)); + CaveProfile regionCaveProfile = resolveCaveProfile(CaveProfiles.declaredBy(region), CaveProfiles.declaredBy(caveBiome)); CaveAnchorCache caveAnchorCache = new CaveAnchorCache(); for (IrisObjectPlacement i : surfaceBiome.getSurfaceObjects()) { @@ -384,12 +385,12 @@ public class ObjectPlacing { @ChunkCoordinates private void placeProceduralObjects(MantleWriter writer, RNG rng, int x, int z, IrisBiome surfaceBiome, IrisBiome caveBiome, IrisRegion region) { - CaveProfile surfaceCaveProfile = resolveCaveProfile(surfaceBiome.getCaveProfile(), region.getCaveProfile()); - CaveProfile regionCaveProfile = resolveCaveProfile(region.getCaveProfile(), caveBiome == null ? null : caveBiome.getCaveProfile()); + CaveProfile surfaceCaveProfile = resolveCaveProfile(CaveProfiles.declaredBy(surfaceBiome), CaveProfiles.declaredBy(region)); + CaveProfile regionCaveProfile = resolveCaveProfile(CaveProfiles.declaredBy(region), caveBiome == null ? null : CaveProfiles.declaredBy(caveBiome)); placeProceduralFrom(writer, rng, x, z, surfaceBiome.getProceduralObjects(), surfaceBiome.getName(), surfaceCaveProfile, surfaceBiome.getLoadKey()); placeProceduralFrom(writer, rng, x, z, region.getProceduralObjects(), region.getName(), regionCaveProfile, null); if (caveBiome != null && caveBiome != surfaceBiome) { - CaveProfile caveProfile = resolveCaveProfile(caveBiome.getCaveProfile(), region.getCaveProfile()); + CaveProfile caveProfile = resolveCaveProfile(CaveProfiles.declaredBy(caveBiome), CaveProfiles.declaredBy(region)); placeProceduralFrom(writer, rng, x, z, caveBiome.getProceduralObjects(), caveBiome.getName(), caveProfile, caveBiome.getLoadKey()); } } @@ -1319,7 +1320,7 @@ public class ObjectPlacing { } private CaveProfile resolveCaveProfile(CaveProfile preferred, CaveProfile secondary) { - CaveProfile dimensionProfile = engine.getDimension().getCaveProfile(); + CaveProfile dimensionProfile = CaveProfiles.declaredBy(engine.getDimension()); if (preferred != null && preferred.enabled()) { return preferred; } diff --git a/src/main/java/art/arcane/iris/engine/modifier/CarveModule.java b/src/main/java/art/arcane/iris/engine/modifier/CarveModule.java index d69592f3d..4d6a91412 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/CarveModule.java +++ b/src/main/java/art/arcane/iris/engine/modifier/CarveModule.java @@ -18,7 +18,10 @@ package art.arcane.iris.engine.modifier; -import art.arcane.iris.builtin.carve.CaveFieldModule; +import art.arcane.iris.builtin.carve.CarvingBiomeSettings; +import art.arcane.iris.builtin.carve.CarvingEnabledSettings; +import art.arcane.iris.builtin.carve.CarvingSettings; +import art.arcane.iris.builtin.carve.CaveDepthSettings; import art.arcane.iris.builtin.carve.CaveProfile; import com.volmit.FeatureRegistry; import art.arcane.iris.builtin.IrisStages; @@ -28,6 +31,7 @@ import art.arcane.iris.engine.mantle.components.CaveCarving; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import com.volmit.IrisModule; import com.volmit.ModuleInfo; +import com.volmit.service.CaveBiomes; import com.volmit.stage.ChunkStageContext; import com.volmit.stage.MantleStageContext; import com.volmit.stage.StageGraph; @@ -51,8 +55,12 @@ public final class CarveModule implements IrisModule { @Override public void register(FeatureRegistry registry) { - registry.registerHeldType(CaveProfile.class); - registry.registerHeldType(CaveFieldModule.class); + registry.registerSettings(CaveProfile.class); + registry.registerSettings(CarvingSettings.class); + registry.registerSettings(CarvingEnabledSettings.class); + registry.registerSettings(CarvingBiomeSettings.class); + registry.registerSettings(CaveDepthSettings.class); + registry.registerService(CaveBiomes.class, new CaveBiomeBands()); } @Override @@ -83,6 +91,6 @@ public final class CarveModule implements IrisModule { * also does: Iris then skips this stage's mantle pass like any disabled component. */ private static boolean carves(IrisDimension dimension) { - return dimension.isCarvingEnabled(); + return dimension.getModuleSettings().find(CarvingEnabledSettings.class).map(CarvingEnabledSettings::enabled).orElse(true); } } diff --git a/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java b/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java index 15242fee5..cc2b666a3 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java +++ b/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java @@ -26,7 +26,6 @@ import art.arcane.iris.engine.decorator.IrisSurfaceDecorator; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.world.biome.InferredType; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver; import art.arcane.iris.util.project.context.ChunkContext; import art.arcane.iris.util.common.data.B; import art.arcane.volmlib.util.documentation.ChunkCoordinates; @@ -82,7 +81,6 @@ public class CaveApplying { public void apply(int x, int z, Hunk output, boolean multicore, ChunkContext context) { PrecisionStopwatch caveStopwatch = PrecisionStopwatch.start(); Mantle mantle = engine.getMantle().getMantle(); - IrisDimensionCarvingResolver.State resolverState = new IrisDimensionCarvingResolver.State(); Long2ObjectOpenHashMap caveBiomeCache = new Long2ObjectOpenHashMap<>(2048); IrisCarveScratch scratch = SCRATCH.get(); scratch.reset(); @@ -174,7 +172,7 @@ public class CaveApplying { int worldZ = rz + chunkBlockZ; String customBiome = cavern.getCustomBiome(); IrisBiome biome = customBiome.isEmpty() - ? resolveCaveBiome(caveBiomeCache, worldX, yy, worldZ, resolverState) + ? resolveCaveBiome(caveBiomeCache, worldX, yy, worldZ) : resolveCustomBiome(customBiomeCache, customBiome); if (biome != null) { @@ -188,14 +186,14 @@ public class CaveApplying { }); for (int columnIndex = 0; columnIndex < 256; columnIndex++) { - processColumnFromMask(output, mantleChunk, mantle, columnMasks[columnIndex], columnIndex, x, z, resolverState, caveBiomeCache, customBiomeCache); + processColumnFromMask(output, mantleChunk, mantle, columnMasks[columnIndex], columnIndex, x, z, caveBiomeCache, customBiomeCache); } for (int columnIndex = 0; columnIndex < 256; columnIndex++) { if (boundaryMasks[columnIndex].isEmpty() || !columnMasks[columnIndex].isEmpty()) { continue; } - processBoundaryColumnFromMask(output, boundaryMasks[columnIndex], walls, columnIndex, x, z, resolverState, caveBiomeCache, customBiomeCache); + processBoundaryColumnFromMask(output, boundaryMasks[columnIndex], walls, columnIndex, x, z, caveBiomeCache, customBiomeCache); } // Surface-break carving must not leave an ore cap suspended across the opening. @@ -409,7 +407,6 @@ public class CaveApplying { int columnIndex, int chunkX, int chunkZ, - IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache ) { @@ -438,7 +435,7 @@ public class CaveApplying { zone.ceiling = buf; } else { if (zone.isValid(engine)) { - processZone(output, mc, mantle, zone, rx, rz, worldX, worldZ, resolverState, caveBiomeCache, customBiomeCache); + processZone(output, mc, mantle, zone, rx, rz, worldX, worldZ, caveBiomeCache, customBiomeCache); } zone = new CaveZone(); zone.setFloor(y); @@ -450,7 +447,7 @@ public class CaveApplying { } if (zone.isValid(engine)) { - processZone(output, mc, mantle, zone, rx, rz, worldX, worldZ, resolverState, caveBiomeCache, customBiomeCache); + processZone(output, mc, mantle, zone, rx, rz, worldX, worldZ, caveBiomeCache, customBiomeCache); } } @@ -461,7 +458,6 @@ public class CaveApplying { int columnIndex, int chunkX, int chunkZ, - IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache ) { @@ -482,14 +478,14 @@ public class CaveApplying { if (y == zoneCeiling + 1) { zoneCeiling = y; } else { - paintBoundaryZone(output, walls, rx, rz, worldX, worldZ, zoneFloor, zoneCeiling, resolverState, caveBiomeCache, customBiomeCache); + paintBoundaryZone(output, walls, rx, rz, worldX, worldZ, zoneFloor, zoneCeiling, caveBiomeCache, customBiomeCache); zoneFloor = y; zoneCeiling = y; } y = boundaryMask.nextSetBit(y + 1); } - paintBoundaryZone(output, walls, rx, rz, worldX, worldZ, zoneFloor, zoneCeiling, resolverState, caveBiomeCache, customBiomeCache); + paintBoundaryZone(output, walls, rx, rz, worldX, worldZ, zoneFloor, zoneCeiling, caveBiomeCache, customBiomeCache); } private void paintBoundaryZone( @@ -501,16 +497,15 @@ public class CaveApplying { int worldZ, int zoneFloor, int zoneCeiling, - IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache ) { IrisBiome floorBiome = resolveCaveBoundaryBiome( walls.get(rx, zoneFloor, rz), worldX, zoneFloor, worldZ, - resolverState, caveBiomeCache, customBiomeCache); + caveBiomeCache, customBiomeCache); IrisBiome ceilingBiome = resolveCaveBoundaryBiome( walls.get(rx, zoneCeiling, rz), worldX, zoneCeiling, worldZ, - resolverState, caveBiomeCache, customBiomeCache); + caveBiomeCache, customBiomeCache); if (floorBiome == null && ceilingBiome == null) { return; } @@ -574,7 +569,7 @@ public class CaveApplying { return (h & 15L) == 0L; } - private void processZone(Hunk output, MantleChunk mc, Mantle mantle, CaveZone zone, int rx, int rz, int xx, int zz, IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache) { + private void processZone(Hunk output, MantleChunk mc, Mantle mantle, CaveZone zone, int rx, int rz, int xx, int zz, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache) { int maxY = output.getHeight(); if (zone.ceiling + 1 < maxY && B.isDecorant(output.getRaw(rx, zone.ceiling + 1, rz))) { @@ -596,8 +591,8 @@ public class CaveApplying { mantle.set(xx, zone.floor, zz, MarkerMatter.CAVE_FLOOR); } - IrisBiome floorBiome = resolveCaveBoundaryBiome(mc, rx, zone.floor, rz, xx, zz, resolverState, caveBiomeCache, customBiomeCache); - IrisBiome ceilingBiome = resolveCaveBoundaryBiome(mc, rx, zone.ceiling, rz, xx, zz, resolverState, caveBiomeCache, customBiomeCache); + IrisBiome floorBiome = resolveCaveBoundaryBiome(mc, rx, zone.floor, rz, xx, zz, caveBiomeCache, customBiomeCache); + IrisBiome ceilingBiome = resolveCaveBoundaryBiome(mc, rx, zone.ceiling, rz, xx, zz, caveBiomeCache, customBiomeCache); if (floorBiome == null && ceilingBiome == null) { return; } @@ -651,10 +646,10 @@ public class CaveApplying { } } - IrisBiome resolveCaveBoundaryBiome(MantleChunk mantleChunk, int x, int y, int z, int worldX, int worldZ, IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache) { + IrisBiome resolveCaveBoundaryBiome(MantleChunk mantleChunk, int x, int y, int z, int worldX, int worldZ, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache) { MatterCavern cavern = dataIfPresent(mantleChunk, x, y, z, MatterCavern.class); return resolveCaveBoundaryBiome( - cavern, worldX, y, worldZ, resolverState, caveBiomeCache, customBiomeCache); + cavern, worldX, y, worldZ, caveBiomeCache, customBiomeCache); } private static T dataIfPresent(MantleChunk mantleChunk, int x, int y, int z, Class type) { @@ -669,11 +664,11 @@ public class CaveApplying { return matter.getSlice(type).get(x & 15, y & 15, z & 15); } - IrisBiome resolveCaveBoundaryBiome(MatterCavern cavern, int worldX, int y, int worldZ, IrisDimensionCarvingResolver.State resolverState, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache) { + IrisBiome resolveCaveBoundaryBiome(MatterCavern cavern, int worldX, int y, int worldZ, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache) { if (cavern != null && !cavern.getCustomBiome().isEmpty()) { return resolveCustomBiome(customBiomeCache, cavern.getCustomBiome()); } - return resolveCaveBiome(caveBiomeCache, worldX, y, worldZ, resolverState); + return resolveCaveBiome(caveBiomeCache, worldX, y, worldZ); } static boolean canReplaceCaveFloorLayer(Hunk output, int x, int y, int z, PlatformBlockState layer) { @@ -695,16 +690,16 @@ public class CaveApplying { return state != null && state.hasGravity(); } - private IrisBiome resolveCaveBiome(Long2ObjectOpenHashMap caveBiomeCache, int x, int y, int z, IrisDimensionCarvingResolver.State resolverState) { - IrisBiome center = sampleCaveBiome(caveBiomeCache, x, y, z, resolverState); + private IrisBiome resolveCaveBiome(Long2ObjectOpenHashMap caveBiomeCache, int x, int y, int z) { + IrisBiome center = sampleCaveBiome(caveBiomeCache, x, y, z); if (center == null) { return null; } - IrisBiome xPos = sampleCaveBiome(caveBiomeCache, x + CAVE_BIOME_BLEND_RADIUS, y, z, resolverState); - IrisBiome xNeg = sampleCaveBiome(caveBiomeCache, x - CAVE_BIOME_BLEND_RADIUS, y, z, resolverState); - IrisBiome zPos = sampleCaveBiome(caveBiomeCache, x, y, z + CAVE_BIOME_BLEND_RADIUS, resolverState); - IrisBiome zNeg = sampleCaveBiome(caveBiomeCache, x, y, z - CAVE_BIOME_BLEND_RADIUS, resolverState); + IrisBiome xPos = sampleCaveBiome(caveBiomeCache, x + CAVE_BIOME_BLEND_RADIUS, y, z); + IrisBiome xNeg = sampleCaveBiome(caveBiomeCache, x - CAVE_BIOME_BLEND_RADIUS, y, z); + IrisBiome zPos = sampleCaveBiome(caveBiomeCache, x, y, z + CAVE_BIOME_BLEND_RADIUS); + IrisBiome zNeg = sampleCaveBiome(caveBiomeCache, x, y, z - CAVE_BIOME_BLEND_RADIUS); if (xPos == center && xNeg == center && zPos == center && zNeg == center) { return center; @@ -727,14 +722,14 @@ public class CaveApplying { return zNeg != null ? zNeg : center; } - private IrisBiome sampleCaveBiome(Long2ObjectOpenHashMap caveBiomeCache, int x, int y, int z, IrisDimensionCarvingResolver.State resolverState) { + private IrisBiome sampleCaveBiome(Long2ObjectOpenHashMap caveBiomeCache, int x, int y, int z) { long key = BlockPosition.toLong(x, y, z); IrisBiome cachedBiome = caveBiomeCache.get(key); if (cachedBiome != null) { return cachedBiome; } - IrisBiome resolvedBiome = engine.getCaveBiome(x, y, z, resolverState); + IrisBiome resolvedBiome = engine.getCaveBiome(x, y, z); if (resolvedBiome != null) { caveBiomeCache.put(key, resolvedBiome); } diff --git a/src/main/java/art/arcane/iris/engine/modifier/CaveBiomeBands.java b/src/main/java/art/arcane/iris/engine/modifier/CaveBiomeBands.java new file mode 100644 index 000000000..4a67e77c3 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/modifier/CaveBiomeBands.java @@ -0,0 +1,61 @@ +/* + * 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.carve.CaveDepthSettings; +import art.arcane.iris.core.modules.IrisPackWorld; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.terrain.carving.CarvingResolver; +import art.arcane.iris.engine.object.terrain.carving.ResolvedCarvingEntry; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import com.volmit.service.CaveBiomes; +import com.volmit.world.PackWorld; + +import java.util.Optional; + +/** + * What the carve module tells the host about cave biomes ({@link CaveBiomes}): the biome of the dimension's carving band at a + * position, and how far below the surface a biome's caves begin. + */ +public final class CaveBiomeBands implements CaveBiomes { + @Override + public Optional overriddenBiome(PackWorld world, int x, int y, int z) { + Engine engine = IrisPackWorld.of(world).engine(); + ResolvedCarvingEntry rootEntry = CarvingResolver.resolveRootEntry(engine, y + engine.getWorld().minHeight(), null); + if (rootEntry == null) { + return Optional.empty(); + } + ResolvedCarvingEntry entry = CarvingResolver.resolveFromRoot(engine, rootEntry, x, z, null); + if (CarvingResolver.resolveEntryBiome(engine, entry, null) == null) { + return Optional.empty(); + } + return Optional.of(entry.biomeKey().trim()); + } + + @Override + public int minDepthBelowSurface(PackWorld world, String biomeKey) { + IrisBiome biome = IrisPackWorld.of(world).engine().getData().getBiomeLoader().load(biomeKey); + return biome == null ? 0 : minDepthBelowSurface(biome); + } + + /** How many blocks below the surface {@code biome}'s caves begin, as its {@code caveMinDepthBelowSurface} says; 0 where it says none. */ + public static int minDepthBelowSurface(IrisBiome biome) { + return biome.getModuleSettings().find(CaveDepthSettings.class).map(CaveDepthSettings::depth).orElse(0); + } +} 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 2a8906b69..a6fa011ca 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java +++ b/src/main/java/art/arcane/iris/engine/modifier/DepositPlacer.java @@ -30,7 +30,6 @@ 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.world.dimension.IrisDimension; -import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver; import art.arcane.iris.engine.object.prefab.IrisObject; import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; import art.arcane.iris.engine.object.world.region.IrisRegion; @@ -102,7 +101,6 @@ public class DepositPlacer extends EngineAssignedComponent { } 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(); ResolvedDeposit deposit = resolved(k); if (k.spawnChance() < rng.d()) return; @@ -148,8 +146,7 @@ public class DepositPlacer extends EngineAssignedComponent { 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) + ? getEngine().getCaveBiome((cx << 4) + x, biomeY, (cz << 4) + z) : null; if (!deposit.matchesBiome(surfaceBiome, depositBiome)) { continue; @@ -211,7 +208,7 @@ public class DepositPlacer extends EngineAssignedComponent { if (chunk.get(nx, ny, nz, MatterCavern.class) == null) { PlatformBlockState ore = clump.getBlocks().get(j); PlatformBlockState remapped = resolveDepositVariant( - cx, cz, nx, ny, nz, ore, dimension, context, carvingState); + cx, cz, nx, ny, nz, ore, dimension, context); PlatformBlockState finalBlock = remapped != null ? remapped : B.toDeepSlateOre(current, ore); @@ -317,12 +314,12 @@ public class DepositPlacer extends EngineAssignedComponent { return Math.max(minimum, Math.min(center, maximum)); } - private PlatformBlockState resolveDepositVariant(int cx, int cz, int nx, int localY, int nz, PlatformBlockState ore, IrisDimension dimension, ChunkContext context, IrisDimensionCarvingResolver.State carvingState) { + private PlatformBlockState resolveDepositVariant(int cx, int cz, int nx, int localY, int nz, PlatformBlockState ore, IrisDimension dimension, ChunkContext context) { int worldX = (cx << 4) + nx; int worldZ = (cz << 4) + nz; int worldY = absoluteWorldY(getEngine().getMinHeight(), localY); - IrisBiome biome = getEngine().getCaveBiome(worldX, localY, worldZ, carvingState); + IrisBiome biome = getEngine().getCaveBiome(worldX, localY, worldZ); if (biome != null) { PlatformBlockState match = matchDepositVariant(biome, ore, worldY); if (match != null) { diff --git a/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java b/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java index 70ee4b567..2cc02067c 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java +++ b/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java @@ -19,6 +19,7 @@ package art.arcane.iris.engine.modifier; +import art.arcane.iris.engine.object.terrain.floating.FloatingChildren; import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild; import art.arcane.iris.builtin.floating.FloatingBottomPaletteMode; import art.arcane.iris.builtin.prepare.SlopeClip; @@ -225,7 +226,7 @@ public class FloatingIslands { int wx = x + xf; int wz = z + zf; IrisBiome parent = boundarySampler.parent(wx, wz); - if (parent == null || parent.getFloatingChildBiomes() == null || parent.getFloatingChildBiomes().isEmpty()) { + if (parent == null || FloatingChildren.declaredBy(parent).isEmpty()) { continue; } FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler); @@ -310,7 +311,7 @@ public class FloatingIslands { int wx = x + xf; int wz = z + zf; IrisBiome parent = boundarySampler.parent(wx, wz); - if (parent == null || parent.getFloatingChildBiomes() == null || parent.getFloatingChildBiomes().isEmpty()) { + if (parent == null || FloatingChildren.declaredBy(parent).isEmpty()) { continue; } FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler); diff --git a/src/main/java/art/arcane/iris/engine/modifier/FloatingModule.java b/src/main/java/art/arcane/iris/engine/modifier/FloatingModule.java index 691d6ba22..f116a6cdc 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/FloatingModule.java +++ b/src/main/java/art/arcane/iris/engine/modifier/FloatingModule.java @@ -18,7 +18,8 @@ package art.arcane.iris.engine.modifier; -import art.arcane.iris.builtin.floating.FloatingChildBiome; +import art.arcane.iris.builtin.floating.FloatingChildSettings; +import art.arcane.iris.builtin.floating.MergeFloatingChildrenSettings; import com.volmit.FeatureRegistry; import art.arcane.iris.builtin.IrisStages; import art.arcane.iris.core.modules.IrisChunk; @@ -50,7 +51,8 @@ public final class FloatingModule implements IrisModule { @Override public void register(FeatureRegistry registry) { - registry.registerHeldType(FloatingChildBiome.class); + registry.registerSettings(FloatingChildSettings.class); + registry.registerSettings(MergeFloatingChildrenSettings.class); } @Override diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/carving/CarvingBands.java b/src/main/java/art/arcane/iris/engine/object/terrain/carving/CarvingBands.java new file mode 100644 index 000000000..916e35316 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/terrain/carving/CarvingBands.java @@ -0,0 +1,71 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.engine.object.terrain.carving; + +import art.arcane.iris.builtin.carve.CarvingEntry; +import art.arcane.iris.builtin.carve.CarvingSettings; +import art.arcane.iris.engine.framework.Engine; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * What the carve module keeps for one world: the cave biome bands its dimension declares ({@link CarvingSettings}) made ready + * ({@link ResolvedCarvingEntry}), in the order the dimension lists them, and by id. + */ +public final class CarvingBands { + private final List entries; + private final Map index; + + CarvingBands(List declared) { + this.entries = declared.stream().filter(Objects::nonNull).map(ResolvedCarvingEntry::new).toList(); + this.index = indexById(entries); + } + + CarvingBands(Engine engine) { + this(engine.getDimension().getModuleSettings().find(CarvingSettings.class).map(CarvingSettings::entries).orElse(List.of())); + } + + /** The bands of the world {@code engine} generates now. */ + public static CarvingBands of(Engine engine) { + return engine.getGeneration().state(CarvingBands.class, CarvingBands::new); + } + + /** Every declared entry, enabled or not. */ + public List entries() { + return entries; + } + + /** The entries by their trimmed ids; entries without an id are not in it, and the last of several with one id is. */ + public Map index() { + return index; + } + + private static Map indexById(List entries) { + Map index = new HashMap<>(); + for (ResolvedCarvingEntry entry : entries) { + if (!entry.id().isBlank()) { + index.put(entry.id().trim(), entry); + } + } + return Map.copyOf(index); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/carving/IrisDimensionCarvingResolver.java b/src/main/java/art/arcane/iris/engine/object/terrain/carving/CarvingResolver.java similarity index 69% rename from src/main/java/art/arcane/iris/engine/object/terrain/carving/IrisDimensionCarvingResolver.java rename to src/main/java/art/arcane/iris/engine/object/terrain/carving/CarvingResolver.java index 951b70fe9..a4eb736ed 100644 --- a/src/main/java/art/arcane/iris/engine/object/terrain/carving/IrisDimensionCarvingResolver.java +++ b/src/main/java/art/arcane/iris/engine/object/terrain/carving/CarvingResolver.java @@ -1,14 +1,13 @@ package art.arcane.iris.engine.object.terrain.carving; import art.arcane.iris.engine.object.value.IRare; -import art.arcane.iris.engine.object.value.IrisRange; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.util.project.interpolation.IrisInterpolation; -import art.arcane.volmlib.util.collection.KList; import art.arcane.iris.util.project.noise.CNG; +import com.volmit.config.Range; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -17,36 +16,40 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; -public final class IrisDimensionCarvingResolver { +/** + * Picks the dimension's carving entry for a position: the last enabled root entry whose world Y band holds the height, + * then, through the entries' children, the one a noise pattern selects at the column. The state a caller passes (or, when + * it passes none, the thread's) keeps the picks and the entries' biomes, so a caller resolving many positions reuses them. + */ +public final class CarvingResolver { private static final int MAX_CHILD_DEPTH = 32; private static final long CHILD_SEED_SALT = 0x9E3779B97F4A7C15L; private static final ThreadLocal> THREAD_STATE = ThreadLocal.withInitial(() -> new WeakReference<>(null)); - private IrisDimensionCarvingResolver() { + private CarvingResolver() { } - public static IrisDimensionCarvingEntry resolveRootEntry(Engine engine, int worldY) { + public static ResolvedCarvingEntry resolveRootEntry(Engine engine, int worldY) { return resolveRootEntry(engine, worldY, threadState()); } - public static IrisDimensionCarvingEntry resolveRootEntry(Engine engine, int worldY, State state) { + public static ResolvedCarvingEntry resolveRootEntry(Engine engine, int worldY, State state) { State resolvedState = state == null ? threadState() : state; resolvedState.bind(engine); if (resolvedState.rootEntriesByWorldY.containsKey(worldY)) { return resolvedState.rootEntriesByWorldY.get(worldY); } - IrisDimension dimension = engine.getDimension(); - List entries = dimension.getCarving(); - if (entries == null || entries.isEmpty()) { + List entries = resolvedState.bands.entries(); + if (entries.isEmpty()) { resolvedState.rootEntriesByWorldY.put(worldY, null); return null; } - IrisDimensionCarvingEntry resolved = null; - for (IrisDimensionCarvingEntry entry : entries) { + ResolvedCarvingEntry resolved = null; + for (ResolvedCarvingEntry entry : entries) { if (!isRootCandidate(engine, entry, worldY, resolvedState)) { continue; } @@ -58,11 +61,11 @@ public final class IrisDimensionCarvingResolver { return resolved; } - public static IrisDimensionCarvingEntry resolveFromRoot(Engine engine, IrisDimensionCarvingEntry rootEntry, int worldX, int worldZ) { + public static ResolvedCarvingEntry resolveFromRoot(Engine engine, ResolvedCarvingEntry rootEntry, int worldX, int worldZ) { return resolveFromRoot(engine, rootEntry, worldX, worldZ, threadState()); } - public static IrisDimensionCarvingEntry resolveFromRoot(Engine engine, IrisDimensionCarvingEntry rootEntry, int worldX, int worldZ, State state) { + public static ResolvedCarvingEntry resolveFromRoot(Engine engine, ResolvedCarvingEntry rootEntry, int worldX, int worldZ, State state) { State resolvedState = state == null ? threadState() : state; resolvedState.bind(engine); if (rootEntry == null) { @@ -74,22 +77,22 @@ public final class IrisDimensionCarvingResolver { return null; } - int remainingDepth = clampDepth(rootEntry.getChildRecursionDepth()); + int remainingDepth = clampDepth(rootEntry.childRecursionDepth()); if (remainingDepth <= 0) { return rootEntry; } - Map entryIndex = resolveEntryIndex(engine, resolvedState); - IrisDimensionCarvingEntry current = rootEntry; + Map entryIndex = resolvedState.bands.index(); + ResolvedCarvingEntry current = rootEntry; int depth = remainingDepth; while (depth > 0) { - IrisDimensionCarvingEntry selected = selectChild(engine, current, worldX, worldZ, entryIndex, resolvedState); + ResolvedCarvingEntry selected = selectChild(engine, current, worldX, worldZ, entryIndex, resolvedState); if (selected == null || selected == current) { break; } depth--; - int childDepthLimit = clampDepth(selected.getChildRecursionDepth()); + int childDepthLimit = clampDepth(selected.childRecursionDepth()); if (childDepthLimit < depth) { depth = childDepthLimit; } @@ -99,17 +102,17 @@ public final class IrisDimensionCarvingResolver { return current; } - public static IrisBiome resolveEntryBiome(Engine engine, IrisDimensionCarvingEntry entry) { + public static IrisBiome resolveEntryBiome(Engine engine, ResolvedCarvingEntry entry) { return resolveEntryBiome(engine, entry, null); } - public static IrisBiome resolveEntryBiome(Engine engine, IrisDimensionCarvingEntry entry, State state) { + public static IrisBiome resolveEntryBiome(Engine engine, ResolvedCarvingEntry entry, State state) { if (entry == null) { return null; } if (state == null) { - return entry.getRealBiome(engine.getData()); + return entry.realBiome(engine.getData()); } state.bind(engine); @@ -117,17 +120,17 @@ public final class IrisDimensionCarvingResolver { return state.biomeCache.get(entry); } - IrisBiome biome = entry.getRealBiome(engine.getData()); + IrisBiome biome = entry.realBiome(engine.getData()); state.biomeCache.put(entry, biome); return biome; } - private static boolean isRootCandidate(Engine engine, IrisDimensionCarvingEntry entry, int worldY, State state) { - if (entry == null || !entry.isEnabled()) { + private static boolean isRootCandidate(Engine engine, ResolvedCarvingEntry entry, int worldY, State state) { + if (entry == null || !entry.enabled()) { return false; } - IrisRange worldYRange = entry.getWorldYRange(); + Range worldYRange = entry.worldYRange(); if (worldYRange != null && !worldYRange.contains(worldY)) { return false; } @@ -135,16 +138,16 @@ public final class IrisDimensionCarvingResolver { return resolveEntryBiome(engine, entry, state) != null; } - private static IrisDimensionCarvingEntry selectChild( + private static ResolvedCarvingEntry selectChild( Engine engine, - IrisDimensionCarvingEntry parent, + ResolvedCarvingEntry parent, int worldX, int worldZ, - Map entryIndex, + Map entryIndex, State state ) { - KList children = parent.getChildren(); - if (children == null || children.isEmpty()) { + List children = parent.children(); + if (children.isEmpty()) { return parent; } @@ -164,7 +167,7 @@ public final class IrisDimensionCarvingResolver { } long seed = resolveChildSeed(engine, state); - CNG childGenerator = parent.getChildrenGenerator(seed, engine.getData()); + CNG childGenerator = parent.childrenGenerator(seed, engine.getData()); double sample = childGenerator.noiseFast2D(worldX, worldZ); int selectedIndex = (int) Math.round(IrisInterpolation.lerp(0, selectionPlan.maxIndex, sample)); CarvingChoice selected = selectionPlan.get(selectedIndex); @@ -177,31 +180,28 @@ public final class IrisDimensionCarvingResolver { private static ParentSelectionPlan buildSelectionPlan( Engine engine, - IrisDimensionCarvingEntry parent, + ResolvedCarvingEntry parent, IrisBiome parentBiome, - Map entryIndex, + Map entryIndex, State state ) { List options = new ArrayList<>(); - KList children = parent.getChildren(); - if (children != null) { - for (String childId : children) { - if (childId == null || childId.isBlank()) { - continue; - } - - IrisDimensionCarvingEntry child = entryIndex.get(childId.trim()); - if (child == null || !child.isEnabled()) { - continue; - } - - IrisBiome childBiome = resolveEntryBiome(engine, child, state); - if (childBiome == null) { - continue; - } - - options.add(new CarvingChoice(child, rarity(childBiome))); + for (String childId : parent.children()) { + if (childId == null || childId.isBlank()) { + continue; } + + ResolvedCarvingEntry child = entryIndex.get(childId.trim()); + if (child == null || !child.enabled()) { + continue; + } + + IrisBiome childBiome = resolveEntryBiome(engine, child, state); + if (childBiome == null) { + continue; + } + + options.add(new CarvingChoice(child, rarity(childBiome))); } options.add(new CarvingChoice(parent, rarity(parentBiome))); @@ -260,14 +260,6 @@ public final class IrisDimensionCarvingResolver { return Math.min(depth, MAX_CHILD_DEPTH); } - private static Map resolveEntryIndex(Engine engine, State state) { - if (state.entryIndex == null) { - state.entryIndex = engine.getDimension().getCarvingEntryIndex(); - } - - return state.entryIndex; - } - private static long resolveChildSeed(Engine engine, State state) { if (state.childSeed == null) { state.childSeed = engine.getSeedManager().getCarve() ^ CHILD_SEED_SALT; @@ -288,13 +280,13 @@ public final class IrisDimensionCarvingResolver { } public static final class State { - private final Map rootEntriesByWorldY = new HashMap<>(); - private final Map selectionPlans = new IdentityHashMap<>(); - private final Map biomeCache = new IdentityHashMap<>(); + private final Map rootEntriesByWorldY = new HashMap<>(); + private final Map selectionPlans = new IdentityHashMap<>(); + private final Map biomeCache = new IdentityHashMap<>(); private WeakReference engineIdentity; private WeakReference dimensionIdentity; private WeakReference dataIdentity; - private Map entryIndex; + private CarvingBands bands; private Long childSeed; private void bind(Engine engine) { @@ -308,10 +300,10 @@ public final class IrisDimensionCarvingResolver { engineIdentity = new WeakReference<>(engine); dimensionIdentity = new WeakReference<>(dimension); dataIdentity = new WeakReference<>(data); + bands = CarvingBands.of(engine); rootEntriesByWorldY.clear(); selectionPlans.clear(); biomeCache.clear(); - entryIndex = null; childSeed = null; } @@ -359,10 +351,10 @@ public final class IrisDimensionCarvingResolver { } private static final class CarvingChoice implements IRare { - private final IrisDimensionCarvingEntry entry; + private final ResolvedCarvingEntry entry; private final int rarity; - private CarvingChoice(IrisDimensionCarvingEntry entry, int rarity) { + private CarvingChoice(ResolvedCarvingEntry entry, int rarity) { this.entry = entry; this.rarity = rarity; } diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/carving/CaveProfiles.java b/src/main/java/art/arcane/iris/engine/object/terrain/carving/CaveProfiles.java new file mode 100644 index 000000000..55628bb16 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/terrain/carving/CaveProfiles.java @@ -0,0 +1,33 @@ +/* + * 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.object.terrain.carving; + +import art.arcane.iris.builtin.carve.CaveProfile; +import art.arcane.iris.core.loader.IrisRegistrant; + +/** The cave profiles dimensions, regions and biomes declare ({@code caveProfile}). */ +public final class CaveProfiles { + private CaveProfiles() { + } + + /** The profile {@code owner}, a dimension, region or biome, declares; null when it declares none, which is as good as one that is not enabled. */ + public static CaveProfile declaredBy(IrisRegistrant owner) { + return owner.getModuleSettings().find(CaveProfile.class).orElse(null); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/carving/IrisDimensionCarvingEntry.java b/src/main/java/art/arcane/iris/engine/object/terrain/carving/IrisDimensionCarvingEntry.java deleted file mode 100644 index 6256fc281..000000000 --- a/src/main/java/art/arcane/iris/engine/object/terrain/carving/IrisDimensionCarvingEntry.java +++ /dev/null @@ -1,84 +0,0 @@ -package art.arcane.iris.engine.object.terrain.carving; - -import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; -import art.arcane.iris.engine.object.noise.NoiseStyle; -import art.arcane.iris.engine.object.value.IrisRange; -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.object.annotations.ArrayType; -import art.arcane.iris.engine.object.annotations.Desc; -import art.arcane.iris.engine.object.annotations.DependsOn; -import art.arcane.iris.engine.object.annotations.RegistryListResource; -import art.arcane.iris.engine.object.annotations.Snippet; -import art.arcane.iris.util.project.noise.CNG; -import art.arcane.volmlib.util.collection.KList; -import art.arcane.volmlib.util.math.RNG; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@Snippet("dimension-carving-entry") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("Dimension-level cave biome override with absolute world Y bounds.") -@Data -public class IrisDimensionCarvingEntry { - private final transient AtomicCache realBiome = new AtomicCache<>(true); - private final transient Map childGenerators = new ConcurrentHashMap<>(); - - @Desc("Stable id for this carving entry") - private String id = ""; - - @Desc("Enable or disable this carving entry") - private boolean enabled = true; - - @RegistryListResource(IrisBiome.class) - @Desc("Cave biome to apply when world Y falls within worldYRange") - private String biome = ""; - - @Desc("Absolute world Y bounds where this carving entry applies") - private IrisRange worldYRange = new IrisRange(-64, 320); - - @DependsOn({"children"}) - @Desc("If this carving entry has child carving entries, this controls how small those child carving patches are.") - private double childShrinkFactor = 1.5; - - @DependsOn({"children"}) - @Desc("If this carving entry has child carving entries, this controls the shape pattern used to pick them.") - private IrisGeneratorStyle childStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @ArrayType(min = 1, type = String.class) - @Desc("Child carving entry ids. Child ids can point back to parent ids to create cycles; recursion is bounded by childRecursionDepth.") - private KList children = new KList<>(); - - @Desc("Maximum recursion depth when resolving child carving entries from this entry.") - private int childRecursionDepth = 3; - - public IrisBiome getRealBiome(IrisData data) { - return realBiome.aquire(() -> { - String biomeKey = getBiome(); - if (biomeKey == null || biomeKey.isBlank()) { - return null; - } - - return data.getBiomeLoader().load(biomeKey.trim()); - }); - } - - public CNG getChildrenGenerator(long seed, IrisData data) { - String entryId = getId(); - long idHash = entryId == null ? 0L : entryId.trim().hashCode(); - long generatorSeed = seed ^ (idHash << 32) ^ 2137L; - return childGenerators.computeIfAbsent(generatorSeed, key -> { - double scale = Math.max(0.0001D, getChildShrinkFactor()); - RNG random = new RNG(key); - return getChildStyle().create(random.nextParallelRNG(2137), data).bake().scale(scale).bake(); - }); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/carving/ResolvedCarvingEntry.java b/src/main/java/art/arcane/iris/engine/object/terrain/carving/ResolvedCarvingEntry.java new file mode 100644 index 000000000..fc880344d --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/object/terrain/carving/ResolvedCarvingEntry.java @@ -0,0 +1,101 @@ +/* + * 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.object.terrain.carving; + +import art.arcane.iris.builtin.carve.CarvingEntry; +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.core.modules.IrisValues; +import art.arcane.iris.engine.data.cache.AtomicCache; +import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import art.arcane.iris.util.project.noise.CNG; +import art.arcane.volmlib.util.math.RNG; +import com.volmit.config.Range; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * One {@link CarvingEntry} made ready for one world: the biome it names, loaded from the pack when first asked for, and the + * noise that splits it into child entries, built once per seed. What the entry describes stays in the settings. + */ +public final class ResolvedCarvingEntry { + private static final long CHILD_GENERATOR_SALT = 2137L; + private static final int CHILD_GENERATOR_SIGNATURE = 2137; + private static final double MIN_CHILD_SCALE = 0.0001D; + + private final CarvingEntry settings; + private final IrisGeneratorStyle childStyle; + private final AtomicCache realBiome = new AtomicCache<>(true); + private final Map childGenerators = new ConcurrentHashMap<>(); + + ResolvedCarvingEntry(CarvingEntry settings) { + this.settings = settings; + this.childStyle = IrisValues.generatorStyle(settings.childStyle()); + } + + public String id() { + return settings.id(); + } + + public boolean enabled() { + return settings.enabled(); + } + + /** The biome key the entry names, as the pack wrote it. */ + public String biomeKey() { + return settings.biome(); + } + + public Range worldYRange() { + return settings.worldYRange(); + } + + public List children() { + return settings.children(); + } + + public int childRecursionDepth() { + return settings.childRecursionDepth(); + } + + /** The pack biome the entry names; null when it names none or the pack has no such biome. */ + public IrisBiome realBiome(IrisData data) { + return realBiome.aquire(() -> { + String biomeKey = settings.biome(); + if (biomeKey.isBlank()) { + return null; + } + + return data.getBiomeLoader().load(biomeKey.trim()); + }); + } + + /** The noise that picks between the entry and its children, seeded by {@code seed} and the entry's id. */ + public CNG childrenGenerator(long seed, IrisData data) { + long idHash = settings.id().trim().hashCode(); + long generatorSeed = seed ^ (idHash << 32) ^ CHILD_GENERATOR_SALT; + return childGenerators.computeIfAbsent(generatorSeed, key -> { + double scale = Math.max(MIN_CHILD_SCALE, settings.childShrinkFactor()); + RNG random = new RNG(key); + return childStyle.create(random.nextParallelRNG(CHILD_GENERATOR_SIGNATURE), data).bake().scale(scale).bake(); + }); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingChildren.java b/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingChildren.java index 2a7492f4c..dd2ad533e 100644 --- a/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingChildren.java +++ b/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingChildren.java @@ -19,8 +19,11 @@ package art.arcane.iris.engine.object.terrain.floating; import art.arcane.iris.builtin.floating.FloatingChildBiome; +import art.arcane.iris.builtin.floating.FloatingChildSettings; +import art.arcane.iris.builtin.floating.MergeFloatingChildrenSettings; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.world.biome.IrisBiome; import java.util.List; import java.util.Map; @@ -46,6 +49,16 @@ public final class FloatingChildren { return engine.getGeneration().state(FloatingChildren.class, FloatingChildren::new); } + /** The floating children {@code biome} declares, in the order it lists them; none when it declares none. */ + public static List declaredBy(IrisBiome biome) { + return biome.getModuleSettings().find(FloatingChildSettings.class).map(FloatingChildSettings::children).orElse(List.of()); + } + + /** Whether {@code biome} samples every floating child on its own and unions their islands instead of picking one per column. */ + public static boolean merges(IrisBiome biome) { + return biome.getModuleSettings().find(MergeFloatingChildrenSettings.class).map(MergeFloatingChildrenSettings::merge).orElse(false); + } + public ResolvedFloatingChild of(FloatingChildBiome settings) { return resolved.computeIfAbsent(settings, ResolvedFloatingChild::new); } diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingIslandSample.java b/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingIslandSample.java index 7fc7b6f1c..ae339e57f 100644 --- a/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingIslandSample.java +++ b/src/main/java/art/arcane/iris/engine/object/terrain/floating/FloatingIslandSample.java @@ -196,8 +196,8 @@ public final class FloatingIslandSample { } public static FloatingIslandSample sample(IrisBiome parent, int wx, int wz, int chunkHeight, long baseSeed, IrisData data, Engine engine, FloatingIslandBoundarySampler boundarySampler) { - List settings = parent.getFloatingChildBiomes(); - if (settings == null || settings.isEmpty()) { + List settings = FloatingChildren.declaredBy(parent); + if (settings.isEmpty()) { return reject(REJECT_NO_ENTRIES); } KList entries = new KList<>(FloatingChildren.of(data).of(settings)); @@ -208,7 +208,7 @@ public final class FloatingIslandSample { int boundaryFieldWidth = maximumEdgeFieldWidth(entries, baseSeed, data, parent); int parentBoundaryDistance = boundarySampler.edgeDistance(parent, wx, wz, boundaryFieldWidth); - if (parent.isMergeFloatingChildBiomes()) { + if (FloatingChildren.merges(parent)) { return sampleMerged(parent, entries, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler, parentBoundaryDistance, boundaryFieldWidth); } diff --git a/src/main/java/art/arcane/iris/engine/object/terrain/floating/ResolvedFloatingChild.java b/src/main/java/art/arcane/iris/engine/object/terrain/floating/ResolvedFloatingChild.java index e50ec5226..518bb6fbc 100644 --- a/src/main/java/art/arcane/iris/engine/object/terrain/floating/ResolvedFloatingChild.java +++ b/src/main/java/art/arcane/iris/engine/object/terrain/floating/ResolvedFloatingChild.java @@ -18,20 +18,22 @@ package art.arcane.iris.engine.object.terrain.floating; +import art.arcane.iris.builtin.carve.CaveProfile; import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.modules.IrisValues; import art.arcane.iris.engine.data.cache.AtomicCache; import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.terrain.carving.CaveProfiles; import art.arcane.iris.engine.object.noise.IrisGeneratorStyle; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.prefab.IrisObjectScale; -import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingEntry; -import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingResolver; +import art.arcane.iris.engine.object.terrain.carving.ResolvedCarvingEntry; +import art.arcane.iris.engine.object.terrain.carving.CarvingBands; +import art.arcane.iris.engine.object.terrain.carving.CarvingResolver; import art.arcane.iris.engine.object.terrain.carving.IrisCaveProfileSampler; import art.arcane.iris.engine.object.value.IRare; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.util.project.noise.CNG; import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.math.RNG; @@ -137,11 +139,12 @@ public final class ResolvedFloatingChild implements IRare { return carvingProfileSamplerCache.aquire(() -> { IrisBiome resolved = resolveCarvingBiome(settings.carving(), engine, data); - if (resolved == null || resolved.getCaveProfile() == null || !resolved.getCaveProfile().enabled()) { + CaveProfile profile = resolved == null ? null : CaveProfiles.declaredBy(resolved); + if (profile == null || !profile.enabled()) { return null; } - return new IrisCaveProfileSampler(engine, resolved.getCaveProfile()); + return new IrisCaveProfileSampler(engine, profile); }); } @@ -155,12 +158,9 @@ public final class ResolvedFloatingChild implements IRare { return null; } - IrisDimension dimension = engine.getDimension(); - if (dimension != null && dimension.getCarvingEntryIndex() != null) { - IrisDimensionCarvingEntry entry = dimension.getCarvingEntryIndex().get(carving); - if (entry != null) { - return IrisDimensionCarvingResolver.resolveEntryBiome(engine, entry); - } + ResolvedCarvingEntry entry = CarvingBands.of(engine).index().get(carving); + if (entry != null) { + return CarvingResolver.resolveEntryBiome(engine, entry); } if (data.getBiomeLoader() == null) { diff --git a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java index d6da53ad2..63f928f93 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java +++ b/src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java @@ -18,8 +18,6 @@ package art.arcane.iris.engine.object.world.biome; -import art.arcane.iris.builtin.floating.FloatingChildBiome; -import art.arcane.iris.builtin.carve.CaveProfile; import art.arcane.iris.engine.object.entity.IrisEffect; import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; import art.arcane.iris.engine.object.loot.IrisBlockDrops; @@ -104,7 +102,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { private transient volatile SeededBiomeGenerator recentBiomeGenerator; private final transient AtomicCache maxHeight = new AtomicCache<>(); private final transient AtomicCache maxWithObjectHeight = new AtomicCache<>(); - private final transient AtomicCache realCarveBiome = new AtomicCache<>(); private final transient AtomicCache> realChildren = new AtomicCache<>(); private final transient AtomicCache> layerHeightGenerators = new AtomicCache<>(); private final transient AtomicCache> layerSeaHeightGenerators = new AtomicCache<>(); @@ -138,8 +135,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { private boolean lockLayers = false; @Desc("The max layers to iterate below the surface for locked layer biomes (mesa).") private int lockLayersMax = 7; - @Desc("Profile-driven 3D cave configuration") - private CaveProfile caveProfile = new CaveProfile(); @MinNumber(1) @MaxNumber(512) @Desc("The rarity of this biome (integer)") @@ -172,13 +167,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = String.class) @Desc("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 4 biomes down the tree.") private KList children = new KList<>(); - @RegistryListResource(IrisBiome.class) - @Desc("Registers the referenced biome with this pack's reachable biome set. It is NOT applied as a substitute under carvings; cave biomes come from the region's caveBiomes list.") - private String carvingBiome = ""; - @MinNumber(0) - @MaxNumber(256) - @Desc("Minimum depth below terrain surface required before this cave biome can be selected.") - private int caveMinDepthBelowSurface = 0; @Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.") private IrisBiomePaletteLayer slab = new IrisBiomePaletteLayer().zero(); @Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)") @@ -201,11 +189,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = IrisStructurePlacement.class) @Desc("Structures define jigsaw or vanilla/datapack structures iris will place in this biome") private KList structures = new KList<>(); - @ArrayType(min = 1, type = FloatingChildBiome.class) - @Desc("Floating child biomes that procedurally generate above this biome's terrain. Each entry references a target biome whose layers, decorators, and objects drive the floating island's visual design, while the config here drives size, shape, altitude, rarity, and water level. Multiple entries are supported and selected by rarity per column unless mergeFloatingChildBiomes is enabled.") - private KList floatingChildBiomes = new KList<>(); - @Desc("When true, every floating child entry is sampled independently and their solid masks are unioned, so multiple floating islands can stack, overlap, and collide instead of the picker choosing only one child per column.") - private boolean mergeFloatingChildBiomes = false; @ArrayType(min = 1, type = IrisBiomeGeneratorLink.class) @Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.") private KList generators = new KList().qadd(new IrisBiomeGeneratorLink()); @@ -321,19 +304,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { return IrisBiomeGenLinks.getGenLink(this, loadKey); } - public IrisBiome getRealCarvingBiome(IrisData data) { - return realCarveBiome.aquire(() -> - { - IrisBiome biome = data.getBiomeLoader().load(getCarvingBiome()); - - if (biome == null) { - biome = this; - } - - return biome; - }); - } - public KList getSurfaceObjects() { return getSurfaceObjectsCache().aquire(() -> { diff --git a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java index b59850df2..3f007b2e2 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java +++ b/src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java @@ -18,8 +18,6 @@ package art.arcane.iris.engine.object.world.dimension; -import art.arcane.iris.builtin.floating.FloatingChildBiome; -import art.arcane.iris.builtin.carve.CaveProfile; import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl; import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; import art.arcane.iris.engine.object.image.IrisImageMap; @@ -34,7 +32,6 @@ import art.arcane.iris.engine.object.noise.NoiseStyle; import art.arcane.iris.engine.object.procedural.tree.IrisTreeSettings; import art.arcane.iris.engine.object.runtime.StudioMode; import art.arcane.iris.engine.object.structure.IrisStructurePlacement; -import art.arcane.iris.engine.object.terrain.carving.IrisDimensionCarvingEntry; import art.arcane.iris.engine.object.value.IrisRange; import art.arcane.iris.engine.object.world.IrisEnvironment; import art.arcane.iris.engine.object.world.IrisWorldBoundary; @@ -45,7 +42,6 @@ import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.core.IrisDatapackCompiler.DimensionHeight; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.spi.IrisLogging; -import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.core.nms.datapack.DataVersion; import art.arcane.iris.core.nms.datapack.IDataFixer; @@ -84,7 +80,6 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayDeque; import java.util.Deque; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Locale; @@ -110,7 +105,6 @@ public class IrisDimension extends IrisRegistrant { private final transient AtomicCache cosr = new AtomicCache<>(); private final transient AtomicCache rad = new AtomicCache<>(); private final transient AtomicCache featuresUsed = new AtomicCache<>(); - private final transient AtomicCache> carvingEntryIndex = new AtomicCache<>(); @MinNumber(2) @Required @Desc("The human readable name of this dimension") @@ -175,13 +169,6 @@ public class IrisDimension extends IrisRegistrant { private boolean postProcessingSlabs = true; @Desc("Add painted walls in post processing") private boolean postProcessingWalls = true; - @Desc("Enable or disable all carving for this dimension") - private boolean carvingEnabled = true; - @ArrayType(type = IrisDimensionCarvingEntry.class, min = 1) - @Desc("Dimension-level cave biome carving overrides with absolute world Y ranges") - private KList carving = new KList<>(); - @Desc("Profile-driven 3D cave configuration") - private CaveProfile caveProfile = new CaveProfile(); @Desc("Refuse to place surface objects and trees over carved surface openings.") private boolean requireObjectSurfaceSupport = true; @MinNumber(0) @@ -298,36 +285,6 @@ public class IrisDimension extends IrisRegistrant { return (int) getDimensionHeight().getMin(); } - public Map getCarvingEntryIndex() { - return carvingEntryIndex.aquire(() -> { - Map index = new HashMap<>(); - KList entries = getCarving(); - if (entries == null || entries.isEmpty()) { - return index; - } - - for (IrisDimensionCarvingEntry entry : entries) { - if (entry == null) { - continue; - } - - String entryId = entry.getId(); - if (entryId == null || entryId.isBlank()) { - continue; - } - - index.put(entryId.trim(), entry); - } - - return index; - }); - } - - public void setCarving(KList carving) { - this.carving = carving == null ? new KList<>() : carving; - carvingEntryIndex.reset(); - } - public int getFluidHeight() { return fluidHeight - (int) dimensionHeight.getMin(); } @@ -449,17 +406,9 @@ public class IrisDimension extends IrisRegistrant { } } - KList carvingEntries = getCarving(); - if (carvingEntries != null) { - for (IrisDimensionCarvingEntry entry : carvingEntries) { - if (entry != null && entry.isEnabled()) { - addReachableBiomeKey(pending, entry.getBiome()); - } - } - } + addReachableBiomeKeys(pending, getModuleSettings().usedBiomes(getModuleSettings())); Set visited = new HashSet<>(); - Map carvingEntryIndex = getCarvingEntryIndex(); while (!pending.isEmpty()) { String biomeKey = pending.removeFirst(); if (!visited.add(biomeKey)) { @@ -479,20 +428,8 @@ public class IrisDimension extends IrisRegistrant { visited.add(loadKey); biomes.put(loadKey, biome); addReachableBiomeKeys(pending, biome.getChildren()); - addReachableBiomeKey(pending, biome.getCarvingBiome()); - KList floatingChildren = biome.getFloatingChildBiomes(); - if (floatingChildren == null) { - continue; - } - for (FloatingChildBiome floatingChild : floatingChildren) { - if (floatingChild != null) { - addReachableBiomeKey(pending, floatingChild.biome()); - String carvingReference = floatingChild.carving(); - IrisDimensionCarvingEntry carvingEntry = carvingEntryIndex.get(carvingReference); - addReachableBiomeKey(pending, - carvingEntry == null ? carvingReference : carvingEntry.getBiome()); - } - } + addReachableBiomeKeys(pending, biome.getModuleSettings().treeBiomes()); + addReachableBiomeKeys(pending, biome.getModuleSettings().usedBiomes(getModuleSettings())); } return biomes.v(); diff --git a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java index 60b0583ce..3bc2a7fd0 100644 --- a/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java +++ b/src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java @@ -18,7 +18,6 @@ package art.arcane.iris.engine.object.world.region; -import art.arcane.iris.builtin.carve.CaveProfile; import art.arcane.iris.engine.object.entity.IrisEffect; import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; import art.arcane.iris.engine.object.loot.IrisBlockDrops; @@ -32,7 +31,6 @@ import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.framework.render.RenderType; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.spi.IrisLogging; -import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.engine.data.cache.AtomicCache; import art.arcane.iris.engine.object.annotations.ArrayType; @@ -123,8 +121,6 @@ public class IrisRegion extends IrisRegistrant implements IRare { @MinNumber(0.0001) @Desc("How large cave biomes are in this region") private double caveBiomeZoom = 1; - @Desc("Profile-driven 3D cave configuration") - private CaveProfile caveProfile = new CaveProfile(); @RegistryListResource(IrisBiome.class) @Required @ArrayType(min = 1, type = String.class) @@ -216,7 +212,7 @@ public class IrisRegion extends IrisRegistrant implements IRare { continue; } - names.add(biome.getCarvingBiome()); + names.addAll(biome.getModuleSettings().treeBiomes()); b.put(biome.getLoadKey(), biome); names.addAll(biome.getChildren()); } @@ -313,7 +309,7 @@ public class IrisRegion extends IrisRegistrant implements IRare { continue; } - names.add(biome.getCarvingBiome()); + names.addAll(biome.getModuleSettings().treeBiomes()); b.put(biome.getLoadKey(), biome); names.addAll(biome.getChildren()); } From c9efe0d73d5d39aee96409cbe27f1f2faa32e528 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 08:53:57 +0200 Subject: [PATCH 5/7] ObjectPlacing: a dimension without a cave profile falls back to one shared default profile --- .../arcane/iris/engine/mantle/components/ObjectPlacing.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java index 288e9c139..80e64d2e1 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java @@ -79,6 +79,7 @@ import java.util.concurrent.atomic.AtomicLong; * placement reach of any object the dimension can place. */ public class ObjectPlacing { + private static final CaveProfile DEFAULT_CAVE_PROFILE = new CaveProfile(); private static final long CAVE_REJECT_LOG_THROTTLE_MS = 5000L; private static final int BEDROCK_CLEARANCE = 6; private static final byte LIQUID_FORCED_AIR = 3; @@ -1333,7 +1334,7 @@ public class ObjectPlacing { return dimensionProfile; } - return new CaveProfile(); + return DEFAULT_CAVE_PROFILE; } private CaveAnchorMode resolveAnchorMode(IrisObjectPlacement objectPlacement, CaveProfile caveProfile) { From 697d21f8a445d541873653940c155ace320dc881 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 13:00:03 +0200 Subject: [PATCH 6/7] PlacementLoot takes the placement's lists, so its picks can be tested --- .../art/arcane/iris/engine/loot/LootGiving.java | 2 +- .../art/arcane/iris/engine/loot/PlacementLoot.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java index 94af45f91..94db333c0 100644 --- a/src/main/java/art/arcane/iris/engine/loot/LootGiving.java +++ b/src/main/java/art/arcane/iris/engine/loot/LootGiving.java @@ -55,7 +55,7 @@ public final class LootGiving implements Loot { IrisObjectPlacement placement = site.container() == null ? null : placementAt(engine, x, relativeY, z); if (placement != null) { objectLootDefined = objectLootDefined || placement.getLoot().isNotEmpty() || placement.getVanillaLoot().isNotEmpty(); - Source picked = placementLoot(world, engine).pick(placement, platformState(site), rng, x, worldY, z); + Source picked = placementLoot(world, engine).pick(placement.getVanillaLoot(), placement.getLoot(), platformState(site), rng, x, worldY, z); if (picked != null) { sources.add(picked); if (placement.isOverrideGlobalLoot()) { diff --git a/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java b/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java index 18ef3d37f..e059d4a06 100644 --- a/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java +++ b/src/main/java/art/arcane/iris/engine/loot/PlacementLoot.java @@ -21,7 +21,6 @@ package art.arcane.iris.engine.loot; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.framework.LootResolver; import art.arcane.iris.engine.object.loot.IObjectLoot; -import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.spi.IrisLogging; import art.arcane.iris.spi.IrisPlatforms; import art.arcane.iris.spi.PlatformBlockState; @@ -61,13 +60,15 @@ final class PlacementLoot { } /** - * The table the placement gives {@code container}, a storage chest, at the spot {@code x}, {@code worldY}, - * {@code z}; null when it gives it none. + * The table a placement, whose platform tables are {@code platformLoot} and whose pack tables are {@code packLoot}, + * gives {@code container}, a storage chest, at the spot {@code x}, {@code worldY}, {@code z}; null when it gives + * it none. */ - Loot.Source pick(IrisObjectPlacement placement, PlatformBlockState container, RNG rng, int x, int worldY, int z) { + Loot.Source pick(List platformLoot, List packLoot, PlatformBlockState container, + RNG rng, int x, int worldY, int z) { Candidates candidates = new Candidates(container); - add(candidates, placement.getVanillaLoot(), name -> platformSource(name, x, worldY, z)); - add(candidates, placement.getLoot(), this::packSource); + add(candidates, platformLoot, name -> platformSource(name, x, worldY, z)); + add(candidates, packLoot, this::packSource); List pool = candidates.pool(); Candidate picked = LootResolver.pickWeighted(pool, Candidate::weight, rng); return picked == null ? null : picked.source(); From 651ff77c8514da658fa011da5ae787d176b112fb Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 13:01:15 +0200 Subject: [PATCH 7/7] README: iris:loot and iris:spawn settings, AmbientEffects, PlacementLoot --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4bf62dc47..7c52a866b 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,15 @@ objects are trees) and says which biomes and regions place an object (`ObjectLoc them (`LootValidator`), and provides `Loot` (`LootGiving`: which tables a container draws from and the `ItemDrop`s a table gives) and `BlockDrops` (`BlockDropping`). `iris:spawn` owns spawners, entities and markers (`SpawnResources`, folders `spawners`, `entities`, `markers`) and provides `EntitySpawns` (`EntitySpawning`: what to spawn in a chunk or at -a marker, as `EntitySpec`s; `EntityResolution` makes the entity's random choices). Iris's Bukkit code creates the items -and entities from those values (`BukkitItemStacks`, `BukkitEntitySpawner`). +a marker, as `EntitySpec`s; `EntityResolution` makes the entity's random choices) and `AmbientEffects` (`AmbientEffecting`: +the effects due around a player, with their random values). Iris's Bukkit code creates the items and entities from those +values (`BukkitItemStacks`, `BukkitEntitySpawner`, `BukkitAmbientEffects`); the modded adapters, which cannot name IrisApi +types, ask through the host-typed `ContentServices`. +The settings of both modules are `builtin.loot` and `builtin.spawn` types of IrisApi annotations only: `iris:loot` declares +`loot` (object, also the shape of an entity's `loot`) and `blockDrops` (list) for dimensions, regions and biomes; +`iris:spawn` declares `entitySpawners` (list of spawner keys) for the same and `effects` (list, `iris:spawn/effects`) for +regions and biomes. The loot tables, spawners, entities and markers are plain module types too (`LootTable`, `Spawner`, +`EntityDefinition`, `SpawnMarker`). `PlacementLoot` picks the table an object placement gives one of its chests. `iris:decorant` keeps its per-world `Decorating` in the world's state store (`context.world().state(...)`); the other built-ins still reach the same store through `IrisChunk.state(...)` / `engine.getGeneration().state(...)`.