From 587c24deb508b82f8339bedf6e55ace3af4a2d40 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 9 Oct 2026 21:59:43 +0200 Subject: [PATCH 1/2] Decorators become iris:decorant settings of IrisApi types; the decorant module keeps the resolved decorators per world Decorator, DecorationPart, DecoratorSlope and DecorantSettings (iris:decorant, biome level) replace IrisDecorator and IrisDecorationPart. ResolvedDecorator holds the blocks and noise, BiomeDecorators the per-world buckets, warm-up and load figures. Ore and object warm-up move into the terrain and objects modules' warmUp. --- .../builtin/decorant/DecorantSettings.java | 51 +++ .../decorant/DecorationPart.java} | 10 +- .../iris/builtin/decorant/Decorator.java | 202 ++++++++++ .../iris/builtin/decorant/DecoratorSlope.java | 64 ++++ .../iris/engine/actuator/DecorantModule.java | 27 +- .../iris/engine/actuator/OreWarmUp.java | 73 ++++ .../iris/engine/actuator/TerrainModule.java | 19 +- .../engine/decorator/BiomeDecorators.java | 173 +++++++++ .../iris/engine/decorator/DecoratorCore.java | 118 +++--- .../engine/decorator/FloatingDecorator.java | 12 +- .../decorator/IrisCeilingDecorator.java | 14 +- .../engine/decorator/IrisEngineDecorator.java | 8 +- .../decorator/IrisSeaFloorDecorator.java | 25 +- .../decorator/IrisSeaSurfaceDecorator.java | 22 +- .../decorator/IrisShoreLineDecorator.java | 25 +- .../decorator/IrisSurfaceDecorator.java | 24 +- .../engine/decorator/ResolvedDecorator.java | 269 +++++++++++++ .../mantle/components/ObjectModule.java | 12 +- .../mantle/components/ObjectWarmUp.java | 91 +++++ .../iris/engine/modifier/CaveApplying.java | 16 +- .../iris/engine/modifier/FloatingIslands.java | 4 +- .../object/decoration/IrisDecorator.java | 356 ------------------ .../engine/object/world/biome/IrisBiome.java | 24 -- .../world/biome/IrisBiomeColorRenderer.java | 11 +- 24 files changed, 1086 insertions(+), 564 deletions(-) create mode 100644 src/main/java/art/arcane/iris/builtin/decorant/DecorantSettings.java rename src/main/java/art/arcane/iris/{engine/object/decoration/IrisDecorationPart.java => builtin/decorant/DecorationPart.java} (81%) create mode 100644 src/main/java/art/arcane/iris/builtin/decorant/Decorator.java create mode 100644 src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java create mode 100644 src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.java create mode 100644 src/main/java/art/arcane/iris/engine/decorator/BiomeDecorators.java create mode 100644 src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java create mode 100644 src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorator.java diff --git a/src/main/java/art/arcane/iris/builtin/decorant/DecorantSettings.java b/src/main/java/art/arcane/iris/builtin/decorant/DecorantSettings.java new file mode 100644 index 000000000..775ac54c3 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/decorant/DecorantSettings.java @@ -0,0 +1,51 @@ +/* + * 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.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 decorators one biome declares, written as {@code "iris:decorant": {"decorators": [...]}}. IrisApi types only, like + * {@link Decorator}. + */ +@Desc("Decorators are used for things like tall grass, bisected flowers, and even kelp or cactus (random heights)") +@Feature(id = "iris:decorant", name = "Decorators", targets = Target.BIOME) +public final class DecorantSettings implements IrisFeature { + @MinItems(1) + @Desc("Decorators are used for things like tall grass, bisected flowers, and even kelp or cactus (random heights)") + private List decorators = List.of(); + + public DecorantSettings() { + } + + public DecorantSettings(List decorators) { + this.decorators = List.copyOf(decorators); + } + + public List decorators() { + return decorators == null ? List.of() : Collections.unmodifiableList(decorators); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorationPart.java b/src/main/java/art/arcane/iris/builtin/decorant/DecorationPart.java similarity index 81% rename from src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorationPart.java rename to src/main/java/art/arcane/iris/builtin/decorant/DecorationPart.java index 38ec3f688..433ac4f25 100644 --- a/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorationPart.java +++ b/src/main/java/art/arcane/iris/builtin/decorant/DecorationPart.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.decoration; +package art.arcane.iris.builtin.decorant; -import art.arcane.iris.engine.object.annotations.Desc; +import com.volmit.config.Desc; @Desc("Represents a location where decorations should go") -public enum IrisDecorationPart { +public enum DecorationPart { @Desc("The default, decorate anywhere") NONE, diff --git a/src/main/java/art/arcane/iris/builtin/decorant/Decorator.java b/src/main/java/art/arcane/iris/builtin/decorant/Decorator.java new file mode 100644 index 000000000..9ef5e0eff --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/decorant/Decorator.java @@ -0,0 +1,202 @@ +/* + * 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.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.Collections; +import java.util.List; +import java.util.Optional; + +/** + * One decorator of a biome, as packs write it in the {@code decorators} of {@code "iris:decorant"} or under + * {@code snippet/decorator/}: which blocks it places, where, how often and how tall. A value of IrisApi types only; the + * decorant module resolves the blocks and builds the noise. + */ +@Snippet("decorator") +@Desc("A biome decorator is used for placing flowers, grass, cacti and so on") +public final class Decorator { + private static final String STATIC_NOISE = "STATIC"; + private static final String DEFAULT_BLOCK = "grass"; + + @Desc("The varience dispersion is used when multiple blocks are put in the palette. Scatter scrambles them, Wispy shows streak-looking varience") + private NoiseStyle variance = NoiseStyle.of(STATIC_NOISE); + + @Desc("Forcefully place this decorant anywhere it is supposed to go even if it should not go on a specific surface block. For example, you could force tallgrass to place on top of stone by using this.") + private boolean forcePlace = false; + + @Desc("Forced the surface block of this decorant to be the specified block. Assumes forcePlace.") + private BlockSpec forceBlock; + + @MinItems(1) + @Desc("When set, the decorator can only place onto any of these blocks.") + private List whitelist; + + @MinItems(1) + @Desc("When set, the decorator will never place onto any of these blocks.") + 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(); + + @Desc("If stackMax is set to true, use this to limit its max height for large caverns") + private int absoluteMaxStack = 30; + + @Desc("Dispersion is used to pick places to spawn. Scatter randomly places them (vanilla) or Wispy for a streak like patch system.") + private NoiseStyle style = NoiseStyle.of(STATIC_NOISE); + + @Desc("If this decorator has a height more than 1 this changes how it picks the height between your maxes. Scatter = random, Wispy = wavy heights") + private NoiseStyle heightVariance = NoiseStyle.of(STATIC_NOISE); + + @Desc("Tells iris where this decoration is a part of. I.e. SHORE_LINE or SEA_SURFACE") + private DecorationPart partOf = DecorationPart.NONE; + + @MinNumber(1) + @MaxNumber(2032) + @Desc("The minimum repeat stack height (setting to 3 would stack 3 of on top of each other") + private int stackMin = 1; + + @MinNumber(1) + @MaxNumber(2032) + @Desc("The maximum repeat stack height") + private int stackMax = 1; + + @Desc(""" + Changes stackMin and stackMin from being absolute block heights and instead uses them as a percentage to scale the stack based on the cave height + + Within a cave, setting them stackMin/max to 50 would make the stack 50% of the cave height""") + private boolean scaleStack = false; + + @Required + @MinNumber(0) + @MaxNumber(1) + @Desc("The chance for this decorator to decorate at a given X,Y coordinate. This is hit 256 times per chunk (per surface block)") + private double chance = 0.1; + + @Required + @MinItems(1) + @Desc("The palette of blocks to pick from when this decorator needs to place.") + private List palette = List.of(BlockSpec.of(DEFAULT_BLOCK)); + + @MinItems(1) + @Desc("The palette of blocks used at the very top of a 'stackMax' of higher than 1. For example, bamboo tops.") + private List topPalette = List.of(); + + @MinNumber(0.01) + @MaxNumber(1.0) + @Desc("When the stack passes the top threshold, the top palette will start being used instead of the normal palette.") + private double topThreshold = 1.0; + + /** A decorator with every option at its default, as packs get it from {@code {}}. */ + public Decorator() { + } + + public NoiseStyle variance() { + return variance == null ? NoiseStyle.of(STATIC_NOISE) : variance; + } + + public boolean forcePlace() { + return forcePlace; + } + + public Optional forceBlock() { + return Optional.ofNullable(forceBlock); + } + + /** The blocks it may only be placed onto; empty when unset, which {@link #hasWhitelist()} tells apart from an explicitly empty list that blocks all placement. */ + public List whitelist() { + return listOrEmpty(whitelist); + } + + public boolean hasWhitelist() { + return whitelist != null; + } + + public List blacklist() { + return listOrEmpty(blacklist); + } + + public boolean hasBlacklist() { + return blacklist != null; + } + + public DecoratorSlope slopeCondition() { + return slopeCondition == null ? new DecoratorSlope() : slopeCondition; + } + + public int absoluteMaxStack() { + return absoluteMaxStack; + } + + public NoiseStyle style() { + return style == null ? NoiseStyle.of(STATIC_NOISE) : style; + } + + public NoiseStyle heightVariance() { + return heightVariance == null ? NoiseStyle.of(STATIC_NOISE) : heightVariance; + } + + public DecorationPart partOf() { + return partOf == null ? DecorationPart.NONE : partOf; + } + + public int stackMin() { + return stackMin; + } + + public int stackMax() { + return stackMax; + } + + public boolean scaleStack() { + return scaleStack; + } + + public double chance() { + return chance; + } + + public List palette() { + return listOrEmpty(palette); + } + + public List topPalette() { + return listOrEmpty(topPalette); + } + + public double topThreshold() { + return topThreshold; + } + + /** Whether it places more than one block per column. */ + public boolean isStacking() { + return stackMax > 1; + } + + private static List listOrEmpty(List list) { + return list == null ? List.of() : Collections.unmodifiableList(list); + } +} diff --git a/src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java b/src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java new file mode 100644 index 000000000..f7ea80716 --- /dev/null +++ b/src/main/java/art/arcane/iris/builtin/decorant/DecoratorSlope.java @@ -0,0 +1,64 @@ +/* + * 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/engine/actuator/DecorantModule.java b/src/main/java/art/arcane/iris/engine/actuator/DecorantModule.java index 1bd6b4195..bf486e46c 100644 --- a/src/main/java/art/arcane/iris/engine/actuator/DecorantModule.java +++ b/src/main/java/art/arcane/iris/engine/actuator/DecorantModule.java @@ -21,12 +21,14 @@ package art.arcane.iris.engine.actuator; import art.arcane.iris.builtin.IrisStages; import art.arcane.iris.core.modules.IrisChunk; import art.arcane.iris.core.modules.IrisPackWorld; +import art.arcane.iris.engine.decorator.BiomeDecorators; import art.arcane.iris.engine.decorator.IrisSeaFloorDecorator; import art.arcane.iris.engine.decorator.IrisSeaSurfaceDecorator; import art.arcane.iris.engine.decorator.IrisShoreLineDecorator; import art.arcane.iris.engine.decorator.IrisSurfaceDecorator; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.EngineDecorator; +import art.arcane.iris.builtin.decorant.DecorantSettings; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.util.common.data.B; @@ -34,8 +36,10 @@ import art.arcane.iris.util.project.context.ChunkContext; import art.arcane.iris.util.project.hunk.Hunk; import art.arcane.volmlib.util.documentation.BlockCoordinates; import art.arcane.volmlib.util.scheduling.PrecisionStopwatch; +import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; +import com.volmit.ModuleLifecycle; import com.volmit.stage.ChunkStageContext; import com.volmit.stage.StageGraph; import com.volmit.world.PackWorld; @@ -43,11 +47,11 @@ import com.volmit.world.PackWorld; import java.util.function.Predicate; /** - * Module {@code iris:decorant}: the biomes' decorators, placed on the surface the mantle's blocks left: the - * surface itself, the sea surface and floor, and the shore line. A dimension turns decorating off with - * {@code decorate}. + * Module {@code iris:decorant}: the biomes' decorators ({@link DecorantSettings}), placed on the surface the mantle's + * blocks left: the surface itself, the sea surface and floor, and the shore line. A dimension turns decorating off with + * {@code decorate}. The decorators' noise is built ahead of generation, in {@link #warmUp}. */ -public final class DecorantModule implements IrisModule { +public final class DecorantModule implements IrisModule, ModuleLifecycle { private static final String VERSION = "built-in"; @Override @@ -55,6 +59,17 @@ public final class DecorantModule implements IrisModule { return ModuleInfo.of("iris:decorant", "Decorators", VERSION); } + @Override + public void register(FeatureRegistry registry) { + registry.registerSettings(DecorantSettings.class); + registry.registerLifecycle(this); + } + + @Override + public void warmUp(PackWorld world) { + BiomeDecorators.of(world).warm(); + } + @Override public void install(StageGraph graph) { graph.define(IrisStages.Decorant.DECORATE).requires(IrisStages.Matter.INSERT).run(DecorantModule::decorate); @@ -75,6 +90,7 @@ public final class DecorantModule implements IrisModule { private static final Predicate PREDICATE_SOLID = (s) -> s != null && !B.isAirOrFluid(s); private final Engine engine; + private final BiomeDecorators decorators; private final IrisSurfaceDecorator surfaceDecorator; private final EngineDecorator seaSurfaceDecorator; private final EngineDecorator seaFloorDecorator; @@ -86,6 +102,7 @@ public final class DecorantModule implements IrisModule { Decorating(Engine engine) { this.engine = engine; + decorators = BiomeDecorators.of(engine); surfaceDecorator = new IrisSurfaceDecorator(engine); seaSurfaceDecorator = new IrisSeaSurfaceDecorator(engine); shoreLineDecorator = new IrisShoreLineDecorator(engine); @@ -111,7 +128,7 @@ public final class DecorantModule implements IrisModule { height = context.getRoundedHeight(i, j); biome = context.getBiome().get(i, j); - if (biome.getDecorators().isEmpty()) { + if (!decorators.hasDecorators(biome)) { continue; } diff --git a/src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.java b/src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.java new file mode 100644 index 000000000..0e5bbbaf9 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/actuator/OreWarmUp.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.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; + +/** + * 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 + * 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 RNG root; + private int warmed; + + OreWarmUp(Engine engine) { + this.engine = engine; + this.root = new RNG(engine.getSeedManager().getComponent() + ROOT_SEED_SALT); + } + + void warm() { + KList biomes = engine.getAllBiomes(); + biomes.sort(Comparator.comparing(IrisBiome::getLoadKey)); + for (IrisBiome biome : biomes) { + warmAll(biome.getOres()); + } + + KList regions = engine.getDimension().getAllRegions(engine); + regions.sort(Comparator.comparing(IrisRegion::getLoadKey)); + for (IrisRegion region : regions) { + warmAll(region.getOres()); + } + + 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()); + } + } + } +} 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 4693cb44b..7926c0357 100644 --- a/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java +++ b/src/main/java/art/arcane/iris/engine/actuator/TerrainModule.java @@ -21,6 +21,7 @@ package art.arcane.iris.engine.actuator; import art.arcane.iris.builtin.IrisStages; 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.framework.Engine; @@ -38,17 +39,21 @@ import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.documentation.BlockCoordinates; import art.arcane.volmlib.util.math.RNG; import art.arcane.volmlib.util.scheduling.PrecisionStopwatch; +import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; +import com.volmit.ModuleLifecycle; import com.volmit.stage.ChunkStageContext; import com.volmit.stage.StageGraph; +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. + * 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}. */ -public final class TerrainModule implements IrisModule { +public final class TerrainModule implements IrisModule, ModuleLifecycle { private static final String VERSION = "built-in"; @Override @@ -56,6 +61,16 @@ public final class TerrainModule implements IrisModule { return ModuleInfo.of("iris:terrain", "Terrain", VERSION); } + @Override + public void register(FeatureRegistry registry) { + registry.registerLifecycle(this); + } + + @Override + public void warmUp(PackWorld world) { + new OreWarmUp(IrisPackWorld.of(world).engine()).warm(); + } + @Override public void install(StageGraph graph) { graph.define(IrisStages.Terrain.SHAPE).run(TerrainModule::shape); diff --git a/src/main/java/art/arcane/iris/engine/decorator/BiomeDecorators.java b/src/main/java/art/arcane/iris/engine/decorator/BiomeDecorators.java new file mode 100644 index 000000000..e288f9f2e --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/decorator/BiomeDecorators.java @@ -0,0 +1,173 @@ +/* + * 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.decorator; + +import art.arcane.iris.builtin.decorant.DecorantSettings; +import art.arcane.iris.builtin.decorant.DecorationPart; +import art.arcane.iris.builtin.decorant.Decorator; +import art.arcane.iris.core.modules.IrisPackWorld; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import com.volmit.world.PackWorld; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * What the decorant module keeps for one world: the decorators of its biomes made ready ({@link ResolvedDecorator}), + * sorted into the places they decorate, and how loaded the busiest biome is. Built from the biomes' {@link DecorantSettings} + * when first asked for, or ahead of generation by {@link #warm()}. + * + *

A decorator's noise seed is a function of the world's decorator seed, its biome's key and its place in the biome's + * list, so it does not depend on which column or which warm-up reached it first. + */ +public final class BiomeDecorators { + private static final ResolvedDecorator[] NO_DECORATORS = new ResolvedDecorator[0]; + private static final int COLUMNS_PER_CHUNK = 256; + private static final long KEY_SEED_FACTOR = 0x9E3779B97F4A7C15L; + private static final long INDEX_SEED_FACTOR = 0xC2B2AE3D27D4EB4FL; + + private final Engine engine; + private final Map> decorators = new ConcurrentHashMap<>(); + private volatile Double busiestBiomeLoad; + + /** @param world a world of an Iris engine */ + BiomeDecorators(PackWorld world) { + this(IrisPackWorld.of(world).engine()); + } + + BiomeDecorators(Engine engine) { + this.engine = engine; + } + + /** The world {@code engine} generates now. */ + public static BiomeDecorators of(Engine engine) { + return engine.getGeneration().state(BiomeDecorators.class, BiomeDecorators::new); + } + + /** The world's decorators, kept in its state store. */ + public static BiomeDecorators of(PackWorld world) { + return world.state(BiomeDecorators.class, BiomeDecorators::new); + } + + /** Whether the biome declares any decorator. */ + public boolean hasDecorators(IrisBiome biome) { + DecorantSettings settings = settingsOf(biome); + return settings != null && !settings.decorators().isEmpty(); + } + + /** The biome's decorators for {@code part}, in the order the biome lists them. */ + ResolvedDecorator[] decorators(IrisBiome biome, DecorationPart part) { + DecorantSettings settings = settingsOf(biome); + if (settings == null) { + return NO_DECORATORS; + } + return decorators.computeIfAbsent(settings, declared -> resolve(biome.getLoadKey(), declared)).getOrDefault(part, NO_DECORATORS); + } + + /** Whether the biome has a decorator for {@code part}. */ + public boolean hasDecorators(IrisBiome biome, DecorationPart part) { + return decorators(biome, part).length > 0; + } + + /** Resolves every decorator of every biome the dimension reaches and builds its noise, so that generation finds them ready. */ + public void warm() { + List biomes = engine.getAllBiomes(); + biomes.sort(Comparator.comparing(IrisBiome::getLoadKey)); + for (IrisBiome biome : biomes) { + for (DecorationPart part : DecorationPart.values()) { + for (ResolvedDecorator decorator : decorators(biome, part)) { + decorator.warm(); + } + } + } + } + + /** The most decorating any reachable biome does, as the sum of its decorators' chances times their stack heights. */ + public double busiestBiomeLoad() { + Double cached = busiestBiomeLoad; + if (cached != null) { + return cached; + } + + double busiest = 0D; + for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) { + busiest = Math.max(busiest, load(biome)); + } + busiestBiomeLoad = busiest; + return busiest; + } + + /** How loaded the biome is with decorators: the sum of their chances times their stack heights, at least one block each. */ + public double load(IrisBiome biome) { + DecorantSettings settings = settingsOf(biome); + if (settings == null) { + return 0D; + } + + double load = 0D; + for (Decorator decorator : settings.decorators()) { + load += Math.max(decorator.stackMax(), 1) * decorator.chance(); + } + return load; + } + + /** How strongly studio's decorator load view colours the biome: the sum of its decorators' chances over a chunk's columns. */ + public double colourLoad(IrisBiome biome) { + DecorantSettings settings = settingsOf(biome); + if (settings == null) { + return 0D; + } + + double load = 0D; + for (Decorator decorator : settings.decorators()) { + load += decorator.chance() * Math.min(1, decorator.stackMax()) * COLUMNS_PER_CHUNK; + } + return load; + } + + private static DecorantSettings settingsOf(IrisBiome biome) { + return biome.getModuleSettings().find(DecorantSettings.class).orElse(null); + } + + private Map resolve(String biomeKey, DecorantSettings settings) { + Map> staging = new EnumMap<>(DecorationPart.class); + List declared = settings.decorators(); + for (int index = 0; index < declared.size(); index++) { + Decorator decorator = declared.get(index); + if (decorator == null) { + continue; + } + ResolvedDecorator resolved = ResolvedDecorator.of(decorator, engine, decoratorSeed(biomeKey, index)); + staging.computeIfAbsent(decorator.partOf(), part -> new ArrayList<>()).add(resolved); + } + + Map buckets = new EnumMap<>(DecorationPart.class); + staging.forEach((part, list) -> buckets.put(part, list.toArray(NO_DECORATORS))); + return buckets; + } + + private long decoratorSeed(String biomeKey, int index) { + return engine.getSeedManager().getDecorator() + (biomeKey.hashCode() * KEY_SEED_FACTOR) + (index * INDEX_SEED_FACTOR); + } +} diff --git a/src/main/java/art/arcane/iris/engine/decorator/DecoratorCore.java b/src/main/java/art/arcane/iris/engine/decorator/DecoratorCore.java index b9407e23b..3762479c5 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/DecoratorCore.java +++ b/src/main/java/art/arcane/iris/engine/decorator/DecoratorCore.java @@ -18,11 +18,8 @@ package art.arcane.iris.engine.decorator; -import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.engine.mantle.EngineMantle; -import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks; import art.arcane.iris.platform.bukkit.BukkitBlockState; import art.arcane.iris.spi.IrisLogging; @@ -66,23 +63,18 @@ final class DecoratorCore { return baseSeed + SEED_OFFSET - (partOrdinal * PART_FACTOR); } - static long partSeed(long baseSeed, IrisDecorationPart part) { + static long partSeed(long baseSeed, DecorationPart part) { return partSeed(baseSeed, part.ordinal()); } - static IrisDecorator pickDecorator(IrisBiome biome, IrisDecorationPart part, RNG gRNG, - RNG colRng, IrisData data, double realX, double realZ) { - IrisDecorator[] bucket = biome.getDecoratorBucket(part); - if (bucket.length == 0) { - return null; - } - - IrisDecorator picked = null; + /** The decorator of {@code bucket} that decorates the column, drawing from {@code colRng} to choose between those whose chance noise passes. */ + static ResolvedDecorator pickDecorator(ResolvedDecorator[] bucket, RNG colRng, double realX, double realZ) { + ResolvedDecorator picked = null; int count = 0; - for (IrisDecorator d : bucket) { + for (ResolvedDecorator d : bucket) { try { - if (d.passesChanceGate(gRNG, realX, realZ, data)) { + if (d.passesChanceGate(realX, realZ)) { count++; if (count == 1 || colRng.nextInt(count) == 0) { picked = d; @@ -104,37 +96,32 @@ final class DecoratorCore { return half.equals("upper") || half.equals("lower") ? "lower" : "bottom"; } - static void placeSurfaceSingle(IrisDecorator decorator, + static void placeSurfaceSingle(ResolvedDecorator decorator, int x, int z, int realX, int height, int realZ, - Hunk data, RNG rng, IrisData irisData, + Hunk data, boolean underwater, boolean caveSkipFluid, EngineMantle mantle) { if (height < 0 || height >= data.getHeight()) { return; } PlatformBlockState bdx = data.get(x, height, z); - PlatformBlockState bd = decorator.pickBlockData(rng, irisData, realX, realZ); + PlatformBlockState bd = decorator.pickBlock(realX, realZ); if (!underwater && !canGoOn(bd, bdx) - && !decorator.isForcePlace() && decorator.getForceBlock() == null) { + && !decorator.isForcePlace() && decorator.forceBlock() == null) { return; } - if (decorator.getForceBlock() != null) { + if (decorator.forceBlock() != null) { if (caveSkipFluid && B.isFluid(bdx)) { return; } data.set(x, height, z, fixFacesForHunk( - decorator.getForceBlock().getBlockData(irisData), data, x, z, realX, height, realZ, mantle)); + decorator.forceBlock(), data, x, z, realX, height, realZ, mantle)); } - if (!decorator.isForcePlace()) { - if (decorator.getWhitelist() != null && !matchesPalette(decorator.getWhitelistArray(irisData), bdx)) { - return; - } - if (decorator.getBlacklist() != null && matchesPalette(decorator.getBlacklistArray(irisData), bdx)) { - return; - } + if (!decorator.isForcePlace() && decorator.rejectsSurface(bdx)) { + return; } String half = bd == null ? null : IrisProceduralBlocks.propertyValue(bd, "half"); @@ -164,20 +151,10 @@ final class DecoratorCore { } } - private static boolean matchesPalette(PlatformBlockState[] palette, PlatformBlockState surface) { - for (int i = 0; i < palette.length; i++) { - if (palette[i].equals(surface)) { - return true; - } - } - - return false; - } - - static void placeSingleAt(IrisDecorator decorator, int x, int z, + static void placeSingleAt(ResolvedDecorator decorator, int x, int z, int realX, int height, int realZ, Hunk data, - RNG rng, IrisData irisData, boolean applyFixFaces, EngineMantle mantle) { - PlatformBlockState bd = decorator.pickBlockData(rng, irisData, realX, realZ); + boolean applyFixFaces, EngineMantle mantle) { + PlatformBlockState bd = decorator.pickBlock(realX, realZ); if (bd == null) { return; } @@ -187,9 +164,9 @@ final class DecoratorCore { data.set(x, height, z, bd); } - static void placeStackUp(IrisDecorator decorator, int x, int z, int realX, int realZ, + static void placeStackUp(ResolvedDecorator decorator, int x, int z, int realX, int realZ, int height, int max, Hunk data, - RNG rng, IrisData irisData, PlaceOpts opts) { + PlaceOpts opts) { if (height < 0 || height >= data.getHeight()) { return; } @@ -199,7 +176,7 @@ final class DecoratorCore { effectiveMax = opts.fluidHeight; } - int stack = computeStack(decorator, rng, realX, realZ, irisData, effectiveMax); + int stack = computeStack(decorator, realX, realZ, effectiveMax); if (stack == 1) { int targetY = height + 1; @@ -213,7 +190,7 @@ final class DecoratorCore { return; } - PlatformBlockState block = decorator.pickBlockDataTop(rng, irisData, realX, realZ); + PlatformBlockState block = decorator.pickTopBlock(realX, realZ); if (block == null || (!opts.underwater && !canGoOn(block, data.get(x, height, z)))) { return; } @@ -228,9 +205,9 @@ final class DecoratorCore { for (int i = 0; i < stack; i++) { int h = height + i; double threshold = ((double) i) / (stack - 1); - PlatformBlockState bd = threshold >= decorator.getTopThreshold() - ? decorator.pickBlockDataTop(rng, irisData, realX, realZ) - : decorator.pickBlockData(rng, irisData, realX, realZ); + PlatformBlockState bd = threshold >= decorator.topThreshold() + ? decorator.pickTopBlock(realX, realZ) + : decorator.pickBlock(realX, realZ); if (bd == null) { break; @@ -263,20 +240,20 @@ final class DecoratorCore { } } - static void placeStackDown(IrisDecorator decorator, int x, int z, int realX, int realZ, + static void placeStackDown(ResolvedDecorator decorator, int x, int z, int realX, int realZ, int height, int minHeight, Hunk data, - RNG rng, IrisData irisData, int max, PlaceOpts opts, EngineMantle mantle) { + int max, PlaceOpts opts, EngineMantle mantle) { if (height < 0 || height >= data.getHeight()) { return; } - int stack = computeStack(decorator, rng, realX, realZ, irisData, max); + int stack = computeStack(decorator, realX, realZ, max); if (stack == 1) { if (opts.caveSkipFluid && B.isFluid(data.get(x, height, z))) { return; } - PlatformBlockState block = decorator.pickBlockDataTop(rng, irisData, realX, realZ); + PlatformBlockState block = decorator.pickTopBlock(realX, realZ); if (block == null) { return; } @@ -292,9 +269,9 @@ final class DecoratorCore { } double threshold = ((double) i) / (double) (stack - 1); - PlatformBlockState bd = threshold >= decorator.getTopThreshold() - ? decorator.pickBlockDataTop(rng, irisData, realX, realZ) - : decorator.pickBlockData(rng, irisData, realX, realZ); + PlatformBlockState bd = threshold >= decorator.topThreshold() + ? decorator.pickTopBlock(realX, realZ) + : decorator.pickBlock(realX, realZ); if (bd == null) { break; @@ -312,11 +289,10 @@ final class DecoratorCore { } } - static void placeFloatingSimple(IrisDecorator decorator, + static void placeFloatingSimple(ResolvedDecorator decorator, int xf, int zf, int realX, int realZ, - int height, int max, Hunk data, - RNG rng, IrisData irisData) { - PlatformBlockState bd = decorator.pickBlockData(rng, irisData, realX, realZ); + int height, int max, Hunk data) { + PlatformBlockState bd = decorator.pickBlock(realX, realZ); if (bd == null) { return; } @@ -345,13 +321,12 @@ final class DecoratorCore { } } - static int placeFloatingStacked(IrisDecorator decorator, + static int placeFloatingStacked(ResolvedDecorator decorator, int xf, int zf, int realX, int realZ, - int height, int max, Hunk data, - RNG rng, IrisData irisData) { - int stack = decorator.getHeight(rng, realX, realZ, irisData); + int height, int max, Hunk data) { + int stack = decorator.stackHeight(realX, realZ); if (decorator.isScaleStack()) { - stack = Math.min((int) Math.ceil((double) max * ((double) stack / 100)), decorator.getAbsoluteMaxStack()); + stack = Math.min((int) Math.ceil((double) max * ((double) stack / 100)), decorator.absoluteMaxStack()); } else { stack = Math.min(max, stack); } @@ -363,9 +338,9 @@ final class DecoratorCore { break; } double threshold = stack == 1 ? 0.0 : ((double) i) / (stack - 1); - PlatformBlockState bd = threshold >= decorator.getTopThreshold() - ? decorator.pickBlockDataTop(rng, irisData, realX, realZ) - : decorator.pickBlockData(rng, irisData, realX, realZ); + PlatformBlockState bd = threshold >= decorator.topThreshold() + ? decorator.pickTopBlock(realX, realZ) + : decorator.pickBlock(realX, realZ); if (bd == null) { break; } @@ -444,7 +419,7 @@ final class DecoratorCore { return ((BlockData) surface.nativeHandle()).isFaceSturdy(BlockFace.UP, BlockSupport.FULL); } - static boolean isValidShorelineSupport(IrisDecorator decorator, PlatformBlockState decorant, PlatformBlockState surface) { + static boolean isValidShorelineSupport(ResolvedDecorator decorator, PlatformBlockState decorant, PlatformBlockState surface) { return surface != null && B.isSolid(surface) && (decorator.isForcePlace() || canGoOn(decorant, surface)); @@ -466,11 +441,10 @@ final class DecoratorCore { && (!caveSkipFluid || !B.isFluid(lower) && !B.isFluid(upper)); } - private static int computeStack(IrisDecorator decorator, RNG rng, double realX, double realZ, - IrisData irisData, int max) { - int stack = decorator.getHeight(rng, realX, realZ, irisData); + private static int computeStack(ResolvedDecorator decorator, double realX, double realZ, int max) { + int stack = decorator.stackHeight(realX, realZ); if (decorator.isScaleStack()) { - stack = Math.min((int) Math.ceil((double) max * ((double) stack / 100)), decorator.getAbsoluteMaxStack()); + stack = Math.min((int) Math.ceil((double) max * ((double) stack / 100)), decorator.absoluteMaxStack()); } else { stack = Math.min(max, stack); } diff --git a/src/main/java/art/arcane/iris/engine/decorator/FloatingDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/FloatingDecorator.java index d8d31447b..ebf564456 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/FloatingDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/FloatingDecorator.java @@ -18,10 +18,9 @@ package art.arcane.iris.engine.decorator; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; import art.arcane.iris.util.project.hunk.Hunk; import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.spi.PlatformBlockState; @@ -33,12 +32,11 @@ import art.arcane.iris.spi.PlatformBlockState; */ public class FloatingDecorator { - public static int decorateColumn(Engine engine, IrisBiome target, IrisDecorationPart part, + public static int decorateColumn(Engine engine, IrisBiome target, DecorationPart part, int xf, int zf, int realX, int realZ, int height, int max, Hunk data, RNG rng, Runnable candidatesNullCallback) { - RNG gRNG = new RNG(DecoratorCore.partSeed(engine.getSeedManager().getDecorator(), part)); - IrisDecorator decorator = DecoratorCore.pickDecorator(target, part, gRNG, rng, engine.getData(), realX, realZ); + ResolvedDecorator decorator = DecoratorCore.pickDecorator(BiomeDecorators.of(engine).decorators(target, part), rng, realX, realZ); if (decorator == null) { candidatesNullCallback.run(); @@ -46,10 +44,10 @@ public class FloatingDecorator { } if (!decorator.isStacking()) { - DecoratorCore.placeFloatingSimple(decorator, xf, zf, realX, realZ, height, max, data, rng, engine.getData()); + DecoratorCore.placeFloatingSimple(decorator, xf, zf, realX, realZ, height, max, data); return max > 1 ? 1 : 0; } - return DecoratorCore.placeFloatingStacked(decorator, xf, zf, realX, realZ, height, max, data, rng, engine.getData()); + return DecoratorCore.placeFloatingStacked(decorator, xf, zf, realX, realZ, height, max, data); } } diff --git a/src/main/java/art/arcane/iris/engine/decorator/IrisCeilingDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/IrisCeilingDecorator.java index 6efb73a6a..ccbb7e951 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/IrisCeilingDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/IrisCeilingDecorator.java @@ -21,8 +21,7 @@ package art.arcane.iris.engine.decorator; 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.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.util.common.data.B; import art.arcane.iris.util.project.hunk.Hunk; import art.arcane.volmlib.util.documentation.BlockCoordinates; @@ -30,11 +29,8 @@ import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.spi.PlatformBlockState; public class IrisCeilingDecorator extends IrisEngineDecorator { - private final RNG partRNG; - public IrisCeilingDecorator(Engine engine) { - super(engine, "Ceiling", IrisDecorationPart.CEILING); - this.partRNG = new RNG(DecoratorCore.partSeed(getSeed(), IrisDecorationPart.CEILING)); + super(engine, "Ceiling", DecorationPart.CEILING); } @BlockCoordinates @@ -49,7 +45,7 @@ public class IrisCeilingDecorator extends IrisEngineDecorator { Hunk data, IrisBiome biome, InferredType inferredType, int height, int max) { boolean caveSkipFluid = IrisSurfaceDecorator.skipsFluid(inferredType); RNG rng = getRNG(realX, realZ); - IrisDecorator decorator = DecoratorCore.pickDecorator(biome, getPart(), partRNG, rng, getData(), realX, realZ); + ResolvedDecorator decorator = DecoratorCore.pickDecorator(decorators.decorators(biome, getPart()), rng, realX, realZ); if (decorator == null) { return; @@ -62,13 +58,13 @@ public class IrisCeilingDecorator extends IrisEngineDecorator { return; } } - DecoratorCore.placeSingleAt(decorator, x, z, realX, height, realZ, data, rng, getData(), true, getEngine().getMantle()); + DecoratorCore.placeSingleAt(decorator, x, z, realX, height, realZ, data, true, getEngine().getMantle()); return; } DecoratorCore.PlaceOpts opts = DecoratorCore.SCRATCH_OPTS.get(); opts.reset(); opts.caveSkipFluid = caveSkipFluid; - DecoratorCore.placeStackDown(decorator, x, z, realX, realZ, height, 0, data, rng, getData(), max, opts, getEngine().getMantle()); + DecoratorCore.placeStackDown(decorator, x, z, realX, realZ, height, 0, data, max, opts, getEngine().getMantle()); } } diff --git a/src/main/java/art/arcane/iris/engine/decorator/IrisEngineDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/IrisEngineDecorator.java index 9dde144e7..5c07087a6 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/IrisEngineDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/IrisEngineDecorator.java @@ -21,18 +21,20 @@ package art.arcane.iris.engine.decorator; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.EngineAssignedComponent; import art.arcane.iris.engine.framework.EngineDecorator; -import art.arcane.iris.engine.object.decoration.IrisDecorationPart; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.volmlib.util.documentation.BlockCoordinates; import art.arcane.volmlib.util.math.RNG; import lombok.Getter; public abstract class IrisEngineDecorator extends EngineAssignedComponent implements EngineDecorator { @Getter - private final IrisDecorationPart part; + private final DecorationPart part; + protected final BiomeDecorators decorators; - public IrisEngineDecorator(Engine engine, String name, IrisDecorationPart part) { + public IrisEngineDecorator(Engine engine, String name, DecorationPart part) { super(engine, name + " Decorator"); this.part = part; + this.decorators = BiomeDecorators.of(engine); } @BlockCoordinates diff --git a/src/main/java/art/arcane/iris/engine/decorator/IrisSeaFloorDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/IrisSeaFloorDecorator.java index 6f4abf0b9..b183bece4 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/IrisSeaFloorDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/IrisSeaFloorDecorator.java @@ -20,19 +20,15 @@ package art.arcane.iris.engine.decorator; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.util.project.hunk.Hunk; import art.arcane.volmlib.util.documentation.BlockCoordinates; import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.spi.PlatformBlockState; public class IrisSeaFloorDecorator extends IrisEngineDecorator { - private final RNG partRNG; - public IrisSeaFloorDecorator(Engine engine) { - super(engine, "Sea Floor", IrisDecorationPart.SEA_FLOOR); - this.partRNG = new RNG(DecoratorCore.partSeed(getSeed(), IrisDecorationPart.SEA_FLOOR)); + super(engine, "Sea Floor", DecorationPart.SEA_FLOOR); } @BlockCoordinates @@ -40,24 +36,23 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator { public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk data, IrisBiome biome, int height, int max) { RNG rng = getRNG(realX, realZ); - IrisDecorator decorator = DecoratorCore.pickDecorator(biome, getPart(), partRNG, rng, getData(), realX, realZ); + ResolvedDecorator decorator = DecoratorCore.pickDecorator(decorators.decorators(biome, getPart()), rng, realX, realZ); if (decorator == null) { return; } if (!decorator.isStacking()) { - if (!decorator.isForcePlace() && !decorator.getSlopeCondition().isDefault() - && !decorator.getSlopeCondition().isValid(getComplex().getSlopeStream().get(realX, realZ))) { + if (decorator.slopeBlocks(() -> getComplex().getSlopeStream().get(realX, realZ))) { return; } if (height >= 0 && height < getEngine().getHeight()) { - data.set(x, height, z, decorator.getBlockData100(biome, rng, realX, height, realZ, getData())); + data.set(x, height, z, decorator.blockAt(biome, realX, height, realZ)); } return; } - int stack = decorator.getHeight(rng, realX, realZ, getData()); + int stack = decorator.stackHeight(realX, realZ); if (decorator.isScaleStack()) { stack = (int) Math.ceil((double) (max - height) * ((double) stack / 100)); } else { @@ -65,7 +60,7 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator { } if (stack == 1) { - data.set(x, height, z, decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData())); + data.set(x, height, z, decorator.topBlockAt(biome, realX, height, realZ)); return; } @@ -76,9 +71,9 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator { continue; } double threshold = ((double) i) / (stack - 1); - data.set(x, h, z, threshold >= decorator.getTopThreshold() - ? decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) - : decorator.getBlockData100(biome, rng, realX, h, realZ, getData())); + data.set(x, h, z, threshold >= decorator.topThreshold() + ? decorator.topBlockAt(biome, realX, h, realZ) + : decorator.blockAt(biome, realX, h, realZ)); } } } diff --git a/src/main/java/art/arcane/iris/engine/decorator/IrisSeaSurfaceDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/IrisSeaSurfaceDecorator.java index 62d470345..aaca4f012 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/IrisSeaSurfaceDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/IrisSeaSurfaceDecorator.java @@ -20,19 +20,15 @@ package art.arcane.iris.engine.decorator; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.util.project.hunk.Hunk; import art.arcane.volmlib.util.documentation.BlockCoordinates; import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.spi.PlatformBlockState; public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { - private final RNG partRNG; - public IrisSeaSurfaceDecorator(Engine engine) { - super(engine, "Sea Surface", IrisDecorationPart.SEA_SURFACE); - this.partRNG = new RNG(DecoratorCore.partSeed(getSeed(), IrisDecorationPart.SEA_SURFACE)); + super(engine, "Sea Surface", DecorationPart.SEA_SURFACE); } @BlockCoordinates @@ -40,7 +36,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk data, IrisBiome biome, int height, int max) { RNG rng = getRNG(realX, realZ); - IrisDecorator decorator = DecoratorCore.pickDecorator(biome, getPart(), partRNG, rng, getData(), realX, realZ); + ResolvedDecorator decorator = DecoratorCore.pickDecorator(decorators.decorators(biome, getPart()), rng, realX, realZ); if (decorator == null) { return; @@ -50,7 +46,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { int targetY = height + 1; if (height >= 0 && targetY < getEngine().getHeight() && DecoratorCore.canReplaceStackTarget(data.get(x, targetY, z), false)) { - PlatformBlockState block = decorator.getBlockData100(biome, rng, realX, height, realZ, getData()); + PlatformBlockState block = decorator.blockAt(biome, realX, height, realZ); if (block != null) { data.set(x, targetY, z, block); } @@ -58,7 +54,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { return; } - int stack = decorator.getHeight(rng, realX, realZ, getData()); + int stack = decorator.stackHeight(realX, realZ); if (decorator.isScaleStack()) { stack = (int) Math.ceil((double) (max - height) * ((double) stack / 100)); } @@ -69,7 +65,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { return; } - PlatformBlockState block = decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData()); + PlatformBlockState block = decorator.topBlockAt(biome, realX, height, realZ); if (block != null) { data.set(x, targetY, z, block); } @@ -85,9 +81,9 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator { break; } double threshold = ((double) i) / (stack - 1); - PlatformBlockState block = threshold >= decorator.getTopThreshold() - ? decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) - : decorator.getBlockData100(biome, rng, realX, h, realZ, getData()); + PlatformBlockState block = threshold >= decorator.topThreshold() + ? decorator.topBlockAt(biome, realX, h, realZ) + : decorator.blockAt(biome, realX, h, realZ); if (block == null) { break; } diff --git a/src/main/java/art/arcane/iris/engine/decorator/IrisShoreLineDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/IrisShoreLineDecorator.java index d07750a71..39bbd4cc8 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/IrisShoreLineDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/IrisShoreLineDecorator.java @@ -20,8 +20,7 @@ package art.arcane.iris.engine.decorator; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import art.arcane.iris.engine.object.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.util.project.hunk.Hunk; import art.arcane.iris.util.project.stream.ProceduralStream; import art.arcane.volmlib.util.documentation.BlockCoordinates; @@ -29,11 +28,8 @@ import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.spi.PlatformBlockState; public class IrisShoreLineDecorator extends IrisEngineDecorator { - private final RNG partRNG; - public IrisShoreLineDecorator(Engine engine) { - super(engine, "Shore Line", IrisDecorationPart.SHORE_LINE); - this.partRNG = new RNG(DecoratorCore.partSeed(getSeed(), IrisDecorationPart.SHORE_LINE)); + super(engine, "Shore Line", DecorationPart.SHORE_LINE); } @BlockCoordinates @@ -54,14 +50,13 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator { } RNG rng = getRNG(realX, realZ); - IrisDecorator decorator = DecoratorCore.pickDecorator(biome, getPart(), partRNG, rng, getData(), realX, realZ); + ResolvedDecorator decorator = DecoratorCore.pickDecorator(decorators.decorators(biome, getPart()), rng, realX, realZ); if (decorator == null) { return; } - if (!decorator.isForcePlace() && !decorator.getSlopeCondition().isDefault() - && !decorator.getSlopeCondition().isValid(getComplex().getSlopeStream().get(realX, realZ))) { + if (decorator.slopeBlocks(() -> getComplex().getSlopeStream().get(realX, realZ))) { return; } @@ -76,14 +71,14 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator { || !DecoratorCore.canReplaceStackTarget(data.get(x, targetY, z), false)) { return; } - PlatformBlockState block = decorator.getBlockData100(biome, rng, realX, height, realZ, getData()); + PlatformBlockState block = decorator.blockAt(biome, realX, height, realZ); if (block != null && DecoratorCore.isValidShorelineSupport(decorator, block, support)) { data.set(x, targetY, z, block); } return; } - int stack = decorator.getHeight(rng, realX, realZ, getData()); + int stack = decorator.stackHeight(realX, realZ); if (decorator.isScaleStack()) { stack = (int) Math.ceil((double) (max - height) * ((double) stack / 100)); } else { @@ -96,7 +91,7 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator { return; } - PlatformBlockState block = decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData()); + PlatformBlockState block = decorator.topBlockAt(biome, realX, height, realZ); if (block != null && DecoratorCore.isValidShorelineSupport(decorator, block, support)) { data.set(x, targetY, z, block); } @@ -111,9 +106,9 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator { break; } double threshold = ((double) i) / (stack - 1); - PlatformBlockState block = threshold >= decorator.getTopThreshold() - ? decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) - : decorator.getBlockData100(biome, rng, realX, h, realZ, getData()); + PlatformBlockState block = threshold >= decorator.topThreshold() + ? decorator.topBlockAt(biome, realX, h, realZ) + : decorator.blockAt(biome, realX, h, realZ); if (block == null) { break; } diff --git a/src/main/java/art/arcane/iris/engine/decorator/IrisSurfaceDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/IrisSurfaceDecorator.java index 0b18b6a84..fde5ae2b5 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/IrisSurfaceDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/IrisSurfaceDecorator.java @@ -21,31 +21,23 @@ package art.arcane.iris.engine.decorator; 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.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.util.project.hunk.Hunk; import art.arcane.volmlib.util.documentation.BlockCoordinates; import art.arcane.volmlib.util.math.RNG; import art.arcane.iris.spi.PlatformBlockState; public class IrisSurfaceDecorator extends IrisEngineDecorator { - private final RNG partRNG; - public IrisSurfaceDecorator(Engine engine) { - super(engine, "Surface", IrisDecorationPart.NONE); - this.partRNG = new RNG(DecoratorCore.partSeed(getSeed(), IrisDecorationPart.NONE)); + super(engine, "Surface", DecorationPart.NONE); } protected IrisSurfaceDecorator(Engine engine, String name) { - super(engine, name, IrisDecorationPart.NONE); - this.partRNG = new RNG(DecoratorCore.partSeed(getSeed(), IrisDecorationPart.NONE)); + super(engine, name, DecorationPart.NONE); } - protected boolean isSlopeValid(IrisDecorator decorator, int realX, int realZ) { - if (decorator.isForcePlace() || decorator.getSlopeCondition().isDefault()) { - return true; - } - return decorator.getSlopeCondition().isValid(getComplex().getSlopeStream().get(realX, realZ)); + protected boolean isSlopeValid(ResolvedDecorator decorator, int realX, int realZ) { + return !decorator.slopeBlocks(() -> getComplex().getSlopeStream().get(realX, realZ)); } @BlockCoordinates @@ -66,7 +58,7 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator { boolean underwater = isUnderwater(inferredType, height, fluidHeight); boolean caveSkipFluid = skipsFluid(inferredType); RNG rng = getRNG(realX, realZ); - IrisDecorator decorator = DecoratorCore.pickDecorator(biome, getPart(), partRNG, rng, getData(), realX, realZ); + ResolvedDecorator decorator = DecoratorCore.pickDecorator(decorators.decorators(biome, getPart()), rng, realX, realZ); if (decorator == null || !isSlopeValid(decorator, realX, realZ)) { return; @@ -78,12 +70,12 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator { opts.underwater = underwater; opts.fluidHeight = fluidHeight; opts.caveSkipFluid = caveSkipFluid; - DecoratorCore.placeStackUp(decorator, x, z, realX, realZ, height, max, data, rng, getData(), opts); + DecoratorCore.placeStackUp(decorator, x, z, realX, realZ, height, max, data, opts); return; } DecoratorCore.placeSurfaceSingle(decorator, x, z, realX, height, realZ, - data, rng, getData(), underwater, caveSkipFluid, getEngine().getMantle()); + data, underwater, caveSkipFluid, getEngine().getMantle()); } static boolean isUnderwater(InferredType inferredType, int height, int fluidHeight) { diff --git a/src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java new file mode 100644 index 000000000..b6c529176 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java @@ -0,0 +1,269 @@ +/* + * 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.decorator; + +import art.arcane.iris.builtin.decorant.DecorationPart; +import art.arcane.iris.builtin.decorant.Decorator; +import art.arcane.iris.engine.data.cache.AtomicCache; +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import art.arcane.iris.spi.IrisLogging; +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.noise.NoiseFactory; +import com.volmit.noise.NoiseSampler; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.DoubleSupplier; + +/** + * One {@link Decorator} made ready for one world: its palettes resolved to the platform's blocks, and the noise that + * decides where it places, which block of the palette it picks and how tall it stacks, built when first asked for. What + * the decorator describes stays in the settings; everything that needs the platform, the pack or the world seed is here. + * + *

The noise seeds are the decorator's own seed plus the same offsets Iris's decorator always used, so a decorator + * noise is a pure function of its seed. + */ +final class ResolvedDecorator { + private final Decorator settings; + private final long seed; + private final NoiseFactory noise; + private final List blocks; + private final List topBlocks; + private final PlatformBlockState[] blockArray; + private final PlatformBlockState[] topBlockArray; + private final PlatformBlockState forceBlock; + private final PlatformBlockState[] whitelist; + private final PlatformBlockState[] blacklist; + private final AtomicCache chanceNoise = new AtomicCache<>(); + private final AtomicCache varianceNoise = new AtomicCache<>(); + private final AtomicCache heightNoise = new AtomicCache<>(); + + /** + * @param blocks the palette as the platform's blocks, each repeated by its weight + * @param topBlocks the top palette the same way + * @param forceBlock the block it forces onto the surface, or null + * @param whitelist the blocks it may only be placed onto; ignored unless the decorator has a whitelist + * @param blacklist the blocks it is never placed onto; ignored unless the decorator has a blacklist + */ + ResolvedDecorator(Decorator settings, long seed, NoiseFactory noise, List blocks, List topBlocks, + PlatformBlockState forceBlock, List whitelist, List blacklist) { + this.settings = settings; + this.seed = seed; + this.noise = noise; + this.blocks = List.copyOf(blocks); + this.topBlocks = List.copyOf(topBlocks); + this.blockArray = blocks.toArray(new PlatformBlockState[0]); + this.topBlockArray = topBlocks.toArray(new PlatformBlockState[0]); + this.forceBlock = forceBlock; + this.whitelist = whitelist.toArray(new PlatformBlockState[0]); + this.blacklist = blacklist.toArray(new PlatformBlockState[0]); + } + + /** {@code settings} ready for {@code engine}: its blocks resolved through the pack, its noise seeded from {@code seed}. */ + static ResolvedDecorator of(Decorator settings, Engine engine, long seed) { + var resources = engine.getData().getPackResources(); + BlockRegistry registry = resources.blocks(); + PlatformBlockState forced = settings.forceBlock().map(spec -> platformState(registry, spec)).orElse(null); + return new ResolvedDecorator(settings, seed, resources.noise(), weighted(registry, settings.palette()), + weighted(registry, settings.topPalette()), forced, each(registry, settings.whitelist()), each(registry, settings.blacklist())); + } + + private static PlatformBlockState platformState(BlockRegistry registry, BlockSpec spec) { + return B.getState(registry.resolve(spec).key()); + } + + private static List weighted(BlockRegistry registry, List palette) { + List weighted = new ArrayList<>(); + for (BlockSpec spec : palette) { + PlatformBlockState state = platformState(registry, spec); + if (state == null) { + continue; + } + for (int n = 0; n < spec.weight(); n++) { + weighted.add(state); + } + } + return weighted; + } + + private static List each(BlockRegistry registry, List palette) { + return palette.stream().map(spec -> platformState(registry, spec)).toList(); + } + + Decorator settings() { + return settings; + } + + DecorationPart part() { + return settings.partOf(); + } + + boolean isStacking() { + return settings.isStacking(); + } + + boolean isForcePlace() { + return settings.forcePlace(); + } + + boolean isScaleStack() { + return settings.scaleStack(); + } + + int absoluteMaxStack() { + return settings.absoluteMaxStack(); + } + + double topThreshold() { + return settings.topThreshold(); + } + + /** The block it forces onto the surface instead of the one found there, or null. */ + PlatformBlockState forceBlock() { + return forceBlock; + } + + /** Whether the terrain's slope keeps the decorator off; the slope is only worked out when the decorator limits it. */ + boolean slopeBlocks(DoubleSupplier slope) { + if (settings.forcePlace() || settings.slopeCondition().isDefault()) { + return false; + } + return !settings.slopeCondition().isValid(slope.getAsDouble()); + } + + /** Whether the white and black lists keep the decorator off {@code surface}. */ + boolean rejectsSurface(PlatformBlockState surface) { + if (settings.hasWhitelist() && !matches(whitelist, surface)) { + return true; + } + return settings.hasBlacklist() && matches(blacklist, surface); + } + + private static boolean matches(PlatformBlockState[] palette, PlatformBlockState surface) { + for (PlatformBlockState state : palette) { + if (state.equals(surface)) { + return true; + } + } + return false; + } + + /** How many blocks the decorator stacks at the column: the minimum, or a height between the limits drawn from its height noise. */ + int stackHeight(double x, double z) { + if (settings.stackMin() == settings.stackMax()) { + return settings.stackMin(); + } + + double zoom = settings.heightVariance().zoom(); + return fit(settings.stackMin(), settings.stackMax(), heightNoise().sample(x / zoom, z / zoom)); + } + + /** Whether the chance noise lets the decorator place at the column. */ + boolean passesChanceGate(double x, double z) { + if (blocks.isEmpty()) { + return false; + } + double zoom = settings.style().zoom(); + return chanceNoise().sample(x / zoom, z / zoom) <= settings.chance(); + } + + /** The block of the palette at the position, for decorations that fill a column block by block; null when the palette has no block. */ + PlatformBlockState blockAt(IrisBiome biome, double x, double y, double z) { + if (blocks.isEmpty()) { + IrisLogging.warnOnce("decorator-empty:" + biome.getName(), "Empty Block Data for " + biome.getName()); + return null; + } + + if (blocks.size() == 1) { + return blocks.get(0); + } + + return blocks.get(fit(0, blocks.size() - 1, varianceNoise().sample(z, y, x))); // X and Z are switched + } + + /** The top palette's block at the position, or the palette's when there is no top palette; null where the chance noise declines. */ + PlatformBlockState topBlockAt(IrisBiome biome, double x, double y, double z) { + if (topBlocks.isEmpty()) { + return blockAt(biome, x, y, z); + } + + double zoom = settings.style().zoom(); + if (!(chanceNoise().sample(x / zoom, z / zoom) <= settings.chance())) { + return null; + } + + if (blocks.size() == 1) { + return topBlocks.get(0); + } + + return topBlocks.get(fit(0, topBlocks.size() - 1, varianceNoise().sample(z, y, x))); + } + + /** The palette's block for the column, or null when the palette has no block. */ + PlatformBlockState pickBlock(double x, double z) { + return pick(blockArray, x, z); + } + + /** The top palette's block for the column; the palette's when there is no top palette. */ + PlatformBlockState pickTopBlock(double x, double z) { + if (topBlockArray.length == 0) { + return pickBlock(x, z); + } + return pick(topBlockArray, x, z); + } + + private PlatformBlockState pick(PlatformBlockState[] palette, double x, double z) { + if (palette.length == 0) { + return null; + } + if (palette.length == 1) { + return palette[0]; + } + return palette[Math.abs(fit(0, palette.length - 1, varianceNoise().sample(z, x)))]; + } + + /** Builds the noise now instead of when first asked for. */ + void warm() { + heightNoise(); + chanceNoise(); + varianceNoise(); + } + + private NoiseSampler heightNoise() { + return heightNoise.aquireOrThrow(() -> noise.sampler(settings.heightVariance(), + seed + blocks.size() + settings.stackMax() + settings.stackMin())); + } + + private NoiseSampler chanceNoise() { + return chanceNoise.aquireOrThrow(() -> noise.sampler(settings.style(), seed + blocks.size())); + } + + private NoiseSampler varianceNoise() { + return varianceNoise.aquireOrThrow(() -> noise.sampler(settings.variance(), seed + blocks.size())); + } + + /** The whole number between {@code min} and {@code max} that {@code fraction}, from 0 to 1, is the way along. */ + private static int fit(int min, int max, double fraction) { + return (int) Math.round(min + (fraction * (max - min))); + } +} diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java index 6e7b4fd5e..fcb5c66b3 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java @@ -26,6 +26,7 @@ import art.arcane.iris.engine.framework.Engine; import com.volmit.FeatureRegistry; import com.volmit.IrisModule; import com.volmit.ModuleInfo; +import com.volmit.ModuleLifecycle; import com.volmit.config.PackSettings; import com.volmit.service.ObjectsAt; import com.volmit.stage.MantleStageContext; @@ -37,10 +38,11 @@ import java.util.Set; /** * Module {@code iris:objects}: the objects the dimension's regions and biomes place, written into the mantle * once the caves they may anchor in are planned. A port of what was Iris's object mantle component, its work - * done by {@link ObjectPlacing}, one per engine runtime. Its reach is the pack's largest object placement. It tells + * done by {@link ObjectPlacing}, one per engine runtime, with the noise of its placements and the variants of its procedural + * objects built ahead of generation ({@link #warmUp}). Its reach is the pack's largest object placement. It tells * Iris which objects a chunk would get ({@link ObjectsAt}), for the object search and studio tools. */ -public final class ObjectModule implements IrisModule { +public final class ObjectModule implements IrisModule, ModuleLifecycle { private static final String VERSION = "built-in"; @Override @@ -56,6 +58,12 @@ public final class ObjectModule implements IrisModule { @Override public void register(FeatureRegistry registry) { registry.registerService(ObjectsAt.class, ObjectModule::objectsAt); + registry.registerLifecycle(this); + } + + @Override + public void warmUp(PackWorld world) { + new ObjectWarmUp(IrisPackWorld.of(world).engine()).warm(); } private static void place(MantleStageContext context) { diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java new file mode 100644 index 000000000..71880284c --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java @@ -0,0 +1,91 @@ +/* + * 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.mantle.components; + +import art.arcane.iris.engine.framework.Engine; +import art.arcane.iris.engine.object.placement.IrisObjectPlacement; +import art.arcane.iris.engine.object.procedural.IrisProceduralObjects; +import art.arcane.iris.engine.object.procedural.IrisProceduralPlacement; +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; + +/** + * Builds what object placing would build on first use, for every object placement and procedural object the world's + * biomes and regions declare: the placement's surface warp and density noise, and a procedural object's variants. None + * of it depends on the random it is warmed with; the warp is seeded from the world, the density noise is cached per seed + * and the variants are baked whatever picks one. + */ +final class ObjectWarmUp { + private static final long ROOT_SEED_SALT = 7777L; + private static final int PROBE_COORDINATE = 0; + + private final Engine engine; + private final RNG root; + private int warmed; + + ObjectWarmUp(Engine engine) { + this.engine = engine; + this.root = new RNG(engine.getSeedManager().getComponent() + ROOT_SEED_SALT); + } + + void warm() { + KList biomes = engine.getAllBiomes(); + biomes.sort(Comparator.comparing(IrisBiome::getLoadKey)); + for (IrisBiome biome : biomes) { + warmPlacements(biome.getObjects()); + warmProcedural(biome.getProceduralObjects()); + } + + KList regions = engine.getDimension().getAllRegions(engine); + regions.sort(Comparator.comparing(IrisRegion::getLoadKey)); + for (IrisRegion region : regions) { + warmPlacements(region.getObjects()); + warmProcedural(region.getProceduralObjects()); + } + } + + private void warmPlacements(KList placements) { + if (placements == null) { + return; + } + for (IrisObjectPlacement placement : placements) { + if (placement == null) { + continue; + } + RNG rng = root.nextParallelRNG(warmed++); + placement.getSurfaceWarp(rng, engine.getData(), engine); + placement.getDensity(rng, PROBE_COORDINATE, PROBE_COORDINATE, engine.getData()); + } + } + + private void warmProcedural(IrisProceduralObjects procedural) { + if (procedural == null) { + return; + } + for (IrisProceduralPlacement placement : procedural.getAllPlacements()) { + if (placement != null) { + placement.getVariantObject(engine.getData(), root.nextParallelRNG(warmed++)); + } + } + } +} 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 67b9ac805..15242fee5 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java +++ b/src/main/java/art/arcane/iris/engine/modifier/CaveApplying.java @@ -19,13 +19,13 @@ 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.decorator.IrisCeilingDecorator; 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.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; 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; @@ -65,12 +65,14 @@ public class CaveApplying { private final RNG rng; private final PlatformBlockState AIR = B.getState("CAVE_AIR"); private final PlatformBlockState LAVA = B.getState("LAVA"); + private final BiomeDecorators decorators; private final IrisSurfaceDecorator surfaceDecorator; private final IrisCeilingDecorator ceilingDecorator; public CaveApplying(Engine engine) { this.engine = engine; rng = new RNG(engine.getSeedManager().getCarve()); + decorators = BiomeDecorators.of(engine); surfaceDecorator = new IrisSurfaceDecorator(engine); ceilingDecorator = new IrisCeilingDecorator(engine); } @@ -640,17 +642,11 @@ public class CaveApplying { } } - IrisDecorator[] surfaceDecorators = floorBiome == null - ? new IrisDecorator[0] - : floorBiome.getDecoratorBucket(IrisDecorationPart.NONE); - if (surfaceDecorators.length > 0 && hasStableCaveFloorSupport(output, rx, zone.getFloor(), rz)) { + if (floorBiome != null && decorators.hasDecorators(floorBiome, DecorationPart.NONE) && hasStableCaveFloorSupport(output, rx, zone.getFloor(), rz)) { surfaceDecorator.decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, floorBiome, InferredType.CAVE, zone.getFloor() - 1, zone.airThickness()); } - IrisDecorator[] ceilingDecorators = ceilingBiome == null - ? new IrisDecorator[0] - : ceilingBiome.getDecoratorBucket(IrisDecorationPart.CEILING); - if (ceilingDecorators.length > 0 && zone.getCeiling() + 1 < maxY && B.isSolid(output.getRaw(rx, zone.getCeiling() + 1, rz))) { + if (ceilingBiome != null && decorators.hasDecorators(ceilingBiome, DecorationPart.CEILING) && zone.getCeiling() + 1 < maxY && B.isSolid(output.getRaw(rx, zone.getCeiling() + 1, rz))) { ceilingDecorator.decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, ceilingBiome, InferredType.CAVE, zone.getCeiling(), zone.airThickness()); } } 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 4a97bcd25..5abfef7f5 100644 --- a/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java +++ b/src/main/java/art/arcane/iris/engine/modifier/FloatingIslands.java @@ -31,7 +31,7 @@ import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySamp 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.object.decoration.IrisDecorationPart; +import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.terrain.floating.IrisFloatingChildBiomes; import art.arcane.iris.engine.object.placement.IrisSlopeClip; @@ -331,7 +331,7 @@ public class FloatingIslands { if (above == null || above.isAir()) { try { RNG colRng = rng.nextParallelRNG((int) FloatingIslandSample.columnSeed(baseSeed, wx, wz)); - FloatingDecorator.decorateColumn(engine, target, IrisDecorationPart.NONE, xf, zf, wx, wz, topY, max, output, colRng, NOOP_DECORATION_MISS); + FloatingDecorator.decorateColumn(engine, target, DecorationPart.NONE, xf, zf, wx, wz, topY, max, output, colRng, NOOP_DECORATION_MISS); } catch (Throwable e) { IrisLogging.reportError(e); } diff --git a/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorator.java b/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorator.java deleted file mode 100644 index 8c3e6123c..000000000 --- a/src/main/java/art/arcane/iris/engine/object/decoration/IrisDecorator.java +++ /dev/null @@ -1,356 +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.decoration; - -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.engine.object.placement.IrisSlopeClip; -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.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.spi.IrisLogging; -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("decorator") -@Accessors(chain = true) -@NoArgsConstructor -@AllArgsConstructor -@Desc("A biome decorator is used for placing flowers, grass, cacti and so on") -@Data -public class IrisDecorator { - private final transient AtomicCache layerGenerator = new AtomicCache<>(); - private final transient AtomicCache varianceGenerator = new AtomicCache<>(); - private final transient AtomicCache heightGenerator = new AtomicCache<>(); - private final transient AtomicCache> blockData = new AtomicCache<>(); - private final transient AtomicCache> blockDataTops = new AtomicCache<>(); - private final transient AtomicCache blockDataArray = new AtomicCache<>(); - private final transient AtomicCache blockDataTopsArray = new AtomicCache<>(); - private final transient AtomicCache whitelistArray = new AtomicCache<>(); - private final transient AtomicCache blacklistArray = new AtomicCache<>(); - @Desc("The varience dispersion is used when multiple blocks are put in the palette. Scatter scrambles them, Wispy shows streak-looking varience") - private IrisGeneratorStyle variance = NoiseStyle.STATIC.style(); - @Desc("Forcefully place this decorant anywhere it is supposed to go even if it should not go on a specific surface block. For example, you could force tallgrass to place on top of stone by using this.") - private boolean forcePlace = false; - @Desc("Forced the surface block of this decorant to be the specified block. Assumes forcePlace.") - private IrisBlockData forceBlock; - @ArrayType(min = 1, type = IrisBlockData.class) - @Desc("When set, the decorator can only place onto any of these blocks.") - private KList whitelist; - @ArrayType(min = 1, type = IrisBlockData.class) - @Desc("When set, the decorator will never place onto any of these blocks.") - private KList 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 IrisSlopeClip slopeCondition = new IrisSlopeClip(); - @DependsOn({"scaleStack", "stackMin", "stackMax"}) - @Desc("If stackMax is set to true, use this to limit its max height for large caverns") - private int absoluteMaxStack = 30; - @Desc("Dispersion is used to pick places to spawn. Scatter randomly places them (vanilla) or Wispy for a streak like patch system.") - private IrisGeneratorStyle style = NoiseStyle.STATIC.style(); - @DependsOn({"stackMin", "stackMax"}) - @Desc("If this decorator has a height more than 1 this changes how it picks the height between your maxes. Scatter = random, Wispy = wavy heights") - private IrisGeneratorStyle heightVariance = NoiseStyle.STATIC.style(); - @Desc("Tells iris where this decoration is a part of. I.e. SHORE_LINE or SEA_SURFACE") - private IrisDecorationPart partOf = IrisDecorationPart.NONE; - @DependsOn({"stackMin", "stackMax"}) - @MinNumber(1) - @MaxNumber(2032) - @Desc("The minimum repeat stack height (setting to 3 would stack 3 of on top of each other") - private int stackMin = 1; - @DependsOn({"stackMin", "stackMax"}) - @MinNumber(1) - @MaxNumber(2032) - @Desc("The maximum repeat stack height") - private int stackMax = 1; - @DependsOn({"stackMin", "stackMax"}) - @Desc(""" - Changes stackMin and stackMin from being absolute block heights and instead uses them as a percentage to scale the stack based on the cave height - - Within a cave, setting them stackMin/max to 50 would make the stack 50% of the cave height""") - private boolean scaleStack = false; - @Required - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance for this decorator to decorate at a given X,Y coordinate. This is hit 256 times per chunk (per surface block)") - private double chance = 0.1; - @Required - @ArrayType(min = 1, type = IrisBlockData.class) - @Desc("The palette of blocks to pick from when this decorator needs to place.") - private KList palette = new KList().qadd(new IrisBlockData("grass")); - @ArrayType(min = 1, type = IrisBlockData.class) - @Desc("The palette of blocks used at the very top of a 'stackMax' of higher than 1. For example, bamboo tops.") - private KList topPalette = new KList<>(); - @DependsOn("topPalette") - @MinNumber(0.01) - @MaxNumber(1.0) - @Desc("When the stack passes the top threshold, the top palette will start being used instead of the normal palette.") - private double topThreshold = 1.0; - - public int getHeight(RNG rng, double x, double z, IrisData data) { - if (stackMin == stackMax) { - return stackMin; - } - - return getHeightGenerator(rng, data) - .fit(stackMin, stackMax, - x / heightVariance.getZoom(), - z / heightVariance.getZoom()); - } - - public CNG getHeightGenerator(RNG rng, IrisData data) { - CNG cached = heightGenerator.getIfPresent(); - - if (cached != null) { - return cached; - } - - return heightGenerator.aquire(() -> - heightVariance.create(rng.nextParallelRNG(getBlockData(data).size() + stackMax + stackMin), data)); - } - - public CNG getGenerator(RNG rng, IrisData data) { - CNG cached = layerGenerator.getIfPresent(); - - if (cached != null) { - return cached; - } - - return layerGenerator.aquire(() -> style.create(rng.nextParallelRNG(getBlockData(data).size()), data)); - } - - public CNG getVarianceGenerator(RNG rng, IrisData data) { - CNG cached = varianceGenerator.getIfPresent(); - - if (cached != null) { - return cached; - } - - return varianceGenerator.aquire(() -> - variance.create( - rng.nextParallelRNG(getBlockData(data).size()), data) - .scale(1D / variance.getZoom())); - } - - public KList add(String b) { - palette.add(new IrisBlockData(b)); - return palette; - } - - public boolean passesChanceGate(RNG rng, double x, double z, IrisData data) { - if (getBlockData(data).isEmpty()) { - return false; - } - double xx = x / style.getZoom(); - double zz = z / style.getZoom(); - return getGenerator(rng, data).fitDouble(0D, 1D, xx, zz) <= chance; - } - - public PlatformBlockState getBlockData(IrisBiome b, RNG rng, double x, double z, IrisData data) { - if (!passesChanceGate(rng, x, z, data)) { - return null; - } - if (getBlockData(data).size() == 1) { - return getBlockData(data).get(0); - } - return getVarianceGenerator(rng, data).fit(getBlockData(data), z, x); - } - - public PlatformBlockState getBlockData100(IrisBiome b, RNG rng, double x, double y, double z, IrisData data) { - if (getBlockData(data).isEmpty()) { - IrisLogging.warnOnce("decorator-empty:" + b.getName(), "Empty Block Data for " + b.getName()); - return null; - } - - if (getBlockData(data).size() == 1) { - return getBlockData(data).get(0); - } - - return getVarianceGenerator(rng, data).fit(getBlockData(data), z, y, x); //X and Z must be switched - } - - public PlatformBlockState getBlockDataForTop(IrisBiome b, RNG rng, double x, double y, double z, IrisData data) { - if (getBlockDataTops(data).isEmpty()) { - return getBlockData100(b, rng, x, y, z, data); - } - - double xx = x / style.getZoom(); - double zz = z / style.getZoom(); - - if (getGenerator(rng, data).fitDouble(0D, 1D, xx, zz) <= chance) { //Exclude y from here - if (getBlockData(data).size() == 1) { - return getBlockDataTops(data).get(0); - } - - return getVarianceGenerator(rng, data).fit(getBlockDataTops(data), z, y, x); //X and Z must be switched - } - - return null; - } - - public KList getBlockData(IrisData data) { - KList cached = blockData.getIfPresent(); - - if (cached != null) { - return cached; - } - - return blockData.aquire(() -> - { - KList blockData = new KList<>(); - for (IrisBlockData i : palette) { - PlatformBlockState bx = i.getBlockData(data); - if (bx != null) { - for (int n = 0; n < i.getWeight(); n++) { - blockData.add(bx); - } - } - } - - return blockData; - }); - } - - public KList getBlockDataTops(IrisData data) { - KList cached = blockDataTops.getIfPresent(); - - if (cached != null) { - return cached; - } - - return blockDataTops.aquire(() -> - { - KList blockDataTops = new KList<>(); - for (IrisBlockData i : topPalette) { - PlatformBlockState bx = i.getBlockData(data); - if (bx != null) { - for (int n = 0; n < i.getWeight(); n++) { - blockDataTops.add(bx); - } - } - } - - return blockDataTops; - }); - } - - public PlatformBlockState[] getBlockDataArray(IrisData data) { - PlatformBlockState[] cached = blockDataArray.getIfPresent(); - - if (cached != null) { - return cached; - } - - return blockDataArray.aquire(() -> { - KList list = getBlockData(data); - return list.toArray(new PlatformBlockState[0]); - }); - } - - public PlatformBlockState[] getBlockDataTopsArray(IrisData data) { - PlatformBlockState[] cached = blockDataTopsArray.getIfPresent(); - - if (cached != null) { - return cached; - } - - return blockDataTopsArray.aquire(() -> { - KList list = getBlockDataTops(data); - return list.toArray(new PlatformBlockState[0]); - }); - } - - /** - * The resolved whitelist palette. Empty when no whitelist is configured; callers must still gate on - * {@link #getWhitelist()} being non null, because an explicitly empty whitelist blocks all placement. - */ - public PlatformBlockState[] getWhitelistArray(IrisData data) { - PlatformBlockState[] cached = whitelistArray.getIfPresent(); - - if (cached != null) { - return cached; - } - - return whitelistArray.aquire(() -> resolvePalette(whitelist, data)); - } - - public PlatformBlockState[] getBlacklistArray(IrisData data) { - PlatformBlockState[] cached = blacklistArray.getIfPresent(); - - if (cached != null) { - return cached; - } - - return blacklistArray.aquire(() -> resolvePalette(blacklist, data)); - } - - private static PlatformBlockState[] resolvePalette(KList list, IrisData data) { - if (list == null) { - return new PlatformBlockState[0]; - } - - PlatformBlockState[] resolved = new PlatformBlockState[list.size()]; - - for (int i = 0; i < resolved.length; i++) { - resolved[i] = list.get(i).getBlockData(data); - } - - return resolved; - } - - public PlatformBlockState pickBlockData(RNG rng, IrisData data, double x, double z) { - PlatformBlockState[] arr = getBlockDataArray(data); - if (arr.length == 0) { - return null; - } - if (arr.length == 1) { - return arr[0]; - } - return arr[Math.abs((int) getVarianceGenerator(rng, data).fit(0, arr.length - 1, z, x))]; - } - - public PlatformBlockState pickBlockDataTop(RNG rng, IrisData data, double x, double z) { - PlatformBlockState[] arr = getBlockDataTopsArray(data); - if (arr.length == 0) { - return pickBlockData(rng, data, x, z); - } - if (arr.length == 1) { - return arr[0]; - } - return arr[Math.abs((int) getVarianceGenerator(rng, data).fit(0, arr.length - 1, z, x))]; - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean isStacking() { - return getStackMax() > 1; - } -} 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 10f40aafc..471c20236 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.engine.object.decoration.IrisDecorationPart; -import art.arcane.iris.engine.object.decoration.IrisDecorator; 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; @@ -118,12 +116,10 @@ public class IrisBiome extends IrisRegistrant implements IRare { 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> decoratorBuckets = new AtomicCache<>(); private final transient AtomicCache derivativeResolved = new AtomicCache<>(); private final transient AtomicCache vanillaDerivativeResolved = new AtomicCache<>(); private final transient AtomicCache> biomeScatterResolved = new AtomicCache<>(); private final transient AtomicCache> biomeSkyScatterResolved = new AtomicCache<>(); - private static final IrisDecorator[] EMPTY_BUCKET = new IrisDecorator[0]; @MinNumber(2) @Required @Desc("This is the human readable name for this biome. This can and should be different than the file name. This is not used for loading biomes in other objects.") @@ -205,9 +201,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { @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 = IrisDecorator.class) - @Desc("Decorators are used for things like tall grass, bisected flowers, and even kelp or cactus (random heights)") - private KList decorators = 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<>(); @@ -635,23 +628,6 @@ public class IrisBiome extends IrisRegistrant implements IRare { return "biomes"; } - public IrisDecorator[] getDecoratorBucket(IrisDecorationPart part) { - return decoratorBuckets.aquire(this::buildDecoratorBuckets).getOrDefault(part, EMPTY_BUCKET); - } - - private EnumMap buildDecoratorBuckets() { - EnumMap> staging = new EnumMap<>(IrisDecorationPart.class); - for (IrisDecorator d : decorators) { - staging.computeIfAbsent(d.getPartOf(), k -> new KList<>()).add(d); - } - EnumMap result = new EnumMap<>(IrisDecorationPart.class); - for (IrisDecorationPart part : IrisDecorationPart.values()) { - KList list = staging.get(part); - result.put(part, list == null ? EMPTY_BUCKET : list.toArray(EMPTY_BUCKET)); - } - return result; - } - public String getTypeName() { return "Biome"; } 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 ec1bdcb93..44e9ce0fe 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 @@ -18,7 +18,7 @@ package art.arcane.iris.engine.object.world.biome; -import art.arcane.iris.engine.object.decoration.IrisDecorator; +import art.arcane.iris.engine.decorator.BiomeDecorators; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.render.RenderType; @@ -76,13 +76,8 @@ final class IrisBiomeColorRenderer { } case DECORATOR_LOAD -> { return biome.getCacheColorDecoratorLoad().aquire(() -> { - double density = 0; - - for (IrisDecorator i : biome.getDecorators()) { - density += i.getChance() * Math.min(1, i.getStackMax()) * 256; - } - - return Color.getHSBColor(0.41f, (float) (density / engine.getMaxBiomeDecoratorDensity()), 1f); + BiomeDecorators decorators = BiomeDecorators.of(engine); + return Color.getHSBColor(0.41f, (float) (decorators.colourLoad(biome) / decorators.busiestBiomeLoad()), 1f); }); } case LAYER_LOAD -> { From 8cf11774dac71b973c084e519f744820626072c2 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 9 Oct 2026 22:46:24 +0200 Subject: [PATCH 2/2] ResolvedDecorator exposes its seed; README describes iris:decorant --- README.md | 8 ++++++++ .../arcane/iris/engine/decorator/ResolvedDecorator.java | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 8de696f27..e3b8b082b 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,14 @@ only: `DepositSettings` holds `DepositGenerator`s (blocks as `BlockSpec`, its en `art.arcane.iris.builtin.deposit`), and packs write `"iris:deposit": {"generators": [...]}` (the old `"deposits": [...]` is converted by the pack migration script). What needs Iris (resolving the palette, ore checks, clump shapes per world seed) lives in the module's own code, `ResolvedDeposit`. +`iris:decorant` is the second: `DecorantSettings` (biome level) holds `Decorator`s in `art.arcane.iris.builtin.decorant`, +written `"iris:decorant": {"decorators": [...]}` (the old `"decorators": [...]` is converted by the migration script). +`ResolvedDecorator` resolves one decorator's blocks and noise for a world; `BiomeDecorators`, the world's state, keeps them +per biome and place. Other modules that decorate (`iris:cave`'s ceilings, floating islands) ask it. A decorator's noise +seed is the world's decorator seed, its biome's key and its place in the biome's list. The module's `warmUp` builds +them ahead of generation; `iris:terrain` and `iris:objects` warm their ore generators, placements and procedural +objects the same way. + Every built-in stage is a full port: the module owns its logic and per-engine state, and the mantle stages work out their reach from the pack when it loads. A dimension's `disabledComponents` turns a mantle stage off by its flag (`CARVED`, `OBJECT`, `FLOATING_OBJECT`, `JIGSAW`) or by its stage id. diff --git a/src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java b/src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java index b6c529176..8f9296005 100644 --- a/src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java +++ b/src/main/java/art/arcane/iris/engine/decorator/ResolvedDecorator.java @@ -114,6 +114,11 @@ final class ResolvedDecorator { return settings; } + /** The seed the decorator's noise is built from. */ + long seed() { + return seed; + } + DecorationPart part() { return settings.partOf(); }