Inherit parent biome policy

- IrisHydrologyPolicy.inherited walks the column's biome lineage (child, then the parents it grew inside), then region, then dimension
- IrisComplex.baseBiomeLineage recovers the per-column child chain from the implosion and fails closed if it disagrees with the base biome
- BiomeLineages limits chain recovery to biomes a policy-bearing biome can implode into and interns lineages for identity caches
- Terrain source, shore biomes and water decorators resolve by lineage; cave pools keep the cave biome alone
- Datapack river areas enumerate each region's child chains and RiverLimits attributes inherited values to the parent
- Policy description names the parent step; schema digest recaptured
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 00:57:34 -05:00
1 parent 95fa3ce105
commit ff0a95a6fd
18 files changed
+460 -140

No files matched your search

@@ -14,11 +14,12 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.List;
import java.util.function.Function;
@Accessors(chain = true)
@NoArgsConstructor
@Description("Hydrology settings for a dimension, region or biome. A value left unset is inherited from the region, then from the dimension.")
@Description("Hydrology settings for a dimension, region or biome. A value a biome leaves unset is inherited from the biome it grows inside as a child, up through that biome's own parents, then from the region, then from the dimension.")
@Data
public class IrisHydrologyPolicy {
@MinNumber(0)
@@ -57,11 +58,14 @@ public class IrisHydrologyPolicy {
@Description("Plants for the rivers, streams, ponds and lakes in this area, replacing the decorators of the tiers and ponds there. Written like the tier and pond decorators: partOf SEA_FLOOR, SEA_SURFACE or SHORE_LINE. An empty list grows no plants here. With no value set anywhere, the tiers and ponds use their own decorators.")
private KList<IrisDecorator> decorators = null;
public static <T> T inherited(IrisBiome biome, IrisRegion region, IrisDimension dimension, Function<IrisHydrologyPolicy, T> field) {
T value = value(biome == null ? null : biome.getHydrologyPolicy(), field);
if (value == null) {
value = value(region == null ? null : region.getHydrologyPolicy(), field);
public static <T> T inherited(List<IrisBiome> biomes, IrisRegion region, IrisDimension dimension, Function<IrisHydrologyPolicy, T> field) {
for (int index = 0; index < biomes.size(); index++) {
T value = value(biomes.get(index).getHydrologyPolicy(), field);
if (value != null) {
return value;
}
}
T value = value(region == null ? null : region.getHydrologyPolicy(), field);
return value != null ? value : value(dimension == null ? null : dimension.getHydrologyPolicy(), field);
}
@@ -38,7 +38,6 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
private final ExecutorService pool;
private final int parallelism;
private final ProceduralStream<IrisRegion> regions;
private final ProceduralStream<IrisBiome> biomes;
private final ProceduralStream<InferredType> continents;
private final BiomeBuffetLayout buffet;
private final IrisBiome focus;
@@ -55,7 +54,6 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
this.pool = pool;
this.parallelism = Math.max(1, parallelism);
this.regions = Objects.requireNonNull(complex.getRegionStream(), "region stream");
this.biomes = Objects.requireNonNull(complex.getBaseBiomeStream(), "base biome stream");
this.continents = Objects.requireNonNull(complex.getBridgeStream(), "continent stream");
this.buffet = complex.getBiomeBuffet();
this.focus = complex.getFocusBiome();
@@ -88,7 +86,7 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
public String channelFluid(int x, int z) {
ChunkBakeCache.enterSparse();
try {
return policy(biomes.get(x, z), regions.get(x, z)).fluid();
return policy(complex.baseBiomeLineage(x, z), regions.get(x, z)).fluid();
} finally {
ChunkBakeCache.exitSparse();
}
@@ -164,7 +162,7 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
if (!Double.isFinite(height)) {
throw new IllegalStateException("Hydrology " + (baseOnly ? "base" : "natural") + " height at " + x + "," + z + " is " + height);
}
Policy policy = policy(biomes.get(x, z), regions.get(x, z));
Policy policy = policy(complex.baseBiomeLineage(x, z), regions.get(x, z));
out.height()[index] = (float) height;
out.ocean()[index] = StrictMath.round(height) < settings.seaLevel() && oceanIntent(x, z);
float wet = policy.climateZones() ? wetness(x, z) : 1f;
@@ -185,13 +183,13 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
return type == InferredType.SEA;
}
private Policy policy(IrisBiome biome, IrisRegion region) {
PolicyKey key = new PolicyKey(biome, region);
private Policy policy(List<IrisBiome> biomes, IrisRegion region) {
PolicyKey key = new PolicyKey(biomes, region);
Policy known = policies.get(key);
if (known != null) {
return known;
}
Policy resolved = resolve(biome, region);
Policy resolved = resolve(biomes, region);
if (policies.size() >= POLICY_CAPACITY) {
policies.clear();
}
@@ -199,23 +197,23 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
return raced == null ? resolved : raced;
}
private Policy resolve(IrisBiome biome, IrisRegion region) {
double rainfall = inherited(biome, region, IrisHydrologyPolicy::getRainfall, 1D);
double pondDensity = inherited(biome, region, IrisHydrologyPolicy::getPondDensity, 1D);
IrisHydrologyPermission streams = inherited(biome, region, IrisHydrologyPolicy::getStreams, IrisHydrologyPermission.ALLOW);
IrisHydrologyPermission ponds = inherited(biome, region, IrisHydrologyPolicy::getPonds, IrisHydrologyPermission.ALLOW);
String fluid = inherited(biome, region, IrisHydrologyPolicy::getFluid, null);
boolean climateZones = inherited(biome, region, IrisHydrologyPolicy::getClimateZones, Boolean.TRUE);
requireMultiplier("rainfall", rainfall, biome, region);
requireMultiplier("pondDensity", pondDensity, biome, region);
private Policy resolve(List<IrisBiome> biomes, IrisRegion region) {
double rainfall = inherited(biomes, region, IrisHydrologyPolicy::getRainfall, 1D);
double pondDensity = inherited(biomes, region, IrisHydrologyPolicy::getPondDensity, 1D);
IrisHydrologyPermission streams = inherited(biomes, region, IrisHydrologyPolicy::getStreams, IrisHydrologyPermission.ALLOW);
IrisHydrologyPermission ponds = inherited(biomes, region, IrisHydrologyPolicy::getPonds, IrisHydrologyPermission.ALLOW);
String fluid = inherited(biomes, region, IrisHydrologyPolicy::getFluid, null);
boolean climateZones = inherited(biomes, region, IrisHydrologyPolicy::getClimateZones, Boolean.TRUE);
requireMultiplier("rainfall", rainfall, biomes, region);
requireMultiplier("pondDensity", pondDensity, biomes, region);
if (fluid != null) {
settings.requireFillingFluid(fluid, "the hydrology policy for " + where(biome, region));
settings.requireFillingFluid(fluid, "the hydrology policy for " + where(biomes, region));
}
return new Policy((float) rainfall, (float) pondDensity, permission(streams, ponds), fluid, climateZones);
}
private <T> T inherited(IrisBiome biome, IrisRegion region, Function<IrisHydrologyPolicy, T> field, T fallback) {
T value = IrisHydrologyPolicy.inherited(biome, region, dimension, field);
private <T> T inherited(List<IrisBiome> biomes, IrisRegion region, Function<IrisHydrologyPolicy, T> field, T fallback) {
T value = IrisHydrologyPolicy.inherited(biomes, region, dimension, field);
return value == null ? fallback : value;
}
@@ -225,29 +223,33 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
return (byte) bits;
}
private static void requireMultiplier(String field, double value, IrisBiome biome, IrisRegion region) {
private static void requireMultiplier(String field, double value, List<IrisBiome> biomes, IrisRegion region) {
if (!Double.isFinite(value) || value < 0D) {
throw new IllegalArgumentException("Hydrology policy " + field + " for " + where(biome, region) + " must be a finite value of 0 or more, got "
throw new IllegalArgumentException("Hydrology policy " + field + " for " + where(biomes, region) + " must be a finite value of 0 or more, got "
+ value);
}
}
private static String where(IrisBiome biome, IrisRegion region) {
return "biome " + (biome == null ? "none" : biome.getLoadKey()) + " in region " + (region == null ? "none" : region.getLoadKey());
private static String where(List<IrisBiome> biomes, IrisRegion region) {
StringBuilder where = new StringBuilder("biome ").append(biomes.isEmpty() ? "none" : biomes.getFirst().getLoadKey());
for (int index = 1; index < biomes.size(); index++) {
where.append(" inside ").append(biomes.get(index).getLoadKey());
}
return where.append(" in region ").append(region == null ? "none" : region.getLoadKey()).toString();
}
private record Policy(float rainfall, float pondDensity, byte permission, String fluid, boolean climateZones) {
}
private record PolicyKey(IrisBiome biome, IrisRegion region) {
private record PolicyKey(List<IrisBiome> biomes, IrisRegion region) {
@Override
public boolean equals(Object other) {
return other instanceof PolicyKey key && key.biome == biome && key.region == region;
return other instanceof PolicyKey key && key.biomes == biomes && key.region == region;
}
@Override
public int hashCode() {
return 31 * System.identityHashCode(biome) + System.identityHashCode(region);
return 31 * System.identityHashCode(biomes) + System.identityHashCode(region);
}
}
@@ -117,7 +117,7 @@ final class MantleCarvedTerrain implements CarvedTerrain {
IrisBiome biome = engine.getCaveBiomeBelowSurface(x, y, z);
IrisRegion region = complex.getRegionStream().get(x, z);
requireFinal(revision, x, z);
return IrisHydrologyPolicy.inherited(biome, region, dimension, IrisHydrologyPolicy::getFluid);
return IrisHydrologyPolicy.inherited(biome == null ? List.of() : List.of(biome), region, dimension, IrisHydrologyPolicy::getFluid);
}
private static Collection<SeaInlet> inlets(HydrologyRuntime runtime, int chunkX, int chunkZ) {
@@ -0,0 +1,124 @@
package art.arcane.iris.generation.runtime;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.block.DataProvider;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
final class BiomeLineages {
private final Set<String> heirs;
private final Object lock = new Object();
private volatile IdentityHashMap<IrisBiome, List<IrisBiome>> roots = new IdentityHashMap<>();
private volatile Map<Chain, List<IrisBiome>> chains = new HashMap<>();
private BiomeLineages(Set<String> heirs) {
this.heirs = heirs;
}
static BiomeLineages compile(Collection<IrisBiome> biomes, DataProvider provider) {
Set<String> heirs = new HashSet<>();
for (IrisBiome biome : biomes) {
if (biome.getHydrologyPolicy() != null) {
addDescendants(biome, provider, heirs);
}
}
return new BiomeLineages(heirs);
}
boolean inherits(IrisBiome biome) {
return heirs.contains(biome.getLoadKey());
}
List<IrisBiome> root(IrisBiome biome) {
List<IrisBiome> known = roots.get(biome);
if (known != null) {
return known;
}
synchronized (lock) {
List<IrisBiome> raced = roots.get(biome);
if (raced != null) {
return raced;
}
List<IrisBiome> created = List.of(biome);
IdentityHashMap<IrisBiome, List<IrisBiome>> next = new IdentityHashMap<>(roots);
next.put(biome, created);
roots = next;
return created;
}
}
List<IrisBiome> chain(IrisBiome[] leafFirst) {
if (leafFirst.length == 1) {
return root(leafFirst[0]);
}
Chain key = new Chain(leafFirst);
List<IrisBiome> known = chains.get(key);
if (known != null) {
return known;
}
synchronized (lock) {
List<IrisBiome> raced = chains.get(key);
if (raced != null) {
return raced;
}
List<IrisBiome> created = List.of(leafFirst);
Map<Chain, List<IrisBiome>> next = new HashMap<>(chains);
next.put(key, created);
chains = next;
return created;
}
}
private static void addDescendants(IrisBiome parent, DataProvider provider, Set<String> heirs) {
Set<IrisBiome> visited = Collections.newSetFromMap(new IdentityHashMap<>());
ArrayDeque<IrisBiome> pending = new ArrayDeque<>();
addChildren(parent, provider, pending);
while (!pending.isEmpty()) {
IrisBiome child = pending.poll();
if (visited.add(child)) {
heirs.add(child.getLoadKey());
addChildren(child, provider, pending);
}
}
}
private static void addChildren(IrisBiome parent, DataProvider provider, ArrayDeque<IrisBiome> pending) {
for (IrisBiome child : parent.getRealChildren(provider)) {
if (child != null) {
pending.add(child);
}
}
}
private record Chain(IrisBiome[] biomes) {
@Override
public boolean equals(Object other) {
if (!(other instanceof Chain chain) || chain.biomes.length != biomes.length) {
return false;
}
for (int index = 0; index < biomes.length; index++) {
if (chain.biomes[index] != biomes[index]) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
int hash = 1;
for (IrisBiome biome : biomes) {
hash = 31 * hash + System.identityHashCode(biome);
}
return hash;
}
}
}
@@ -22,7 +22,7 @@ final class HydrologyShoreBiomes {
private final IrisData data;
private final long seed;
private final Object policyLock = new Object();
private volatile IdentityHashMap<IrisBiome, IdentityHashMap<IrisRegion, Policy>> policies = new IdentityHashMap<>();
private volatile IdentityHashMap<List<IrisBiome>, IdentityHashMap<IrisRegion, Policy>> policies = new IdentityHashMap<>();
private int policyCount;
HydrologyShoreBiomes(IrisDimension dimension, IrisData data, long seed) {
@@ -31,8 +31,8 @@ final class HydrologyShoreBiomes {
this.seed = seed;
}
IrisBiome select(IrisBiome biome, IrisRegion region, int x, int z, int shoreDistance) {
Policy policy = policy(biome, region);
IrisBiome select(List<IrisBiome> lineage, IrisRegion region, int x, int z, int shoreDistance) {
Policy policy = policy(lineage, region);
IrisBiome[] biomes = policy.biomes();
if (shoreDistance > policy.width() || biomes.length == 0) {
return null;
@@ -44,39 +44,39 @@ final class HydrologyShoreBiomes {
return biomes[(int) Long.remainderUnsigned(patch, biomes.length)];
}
private Policy policy(IrisBiome biome, IrisRegion region) {
IdentityHashMap<IrisRegion, Policy> regions = policies.get(biome);
private Policy policy(List<IrisBiome> lineage, IrisRegion region) {
IdentityHashMap<IrisRegion, Policy> regions = policies.get(lineage);
Policy known = regions == null ? null : regions.get(region);
return known != null ? known : remember(biome, region, resolve(biome, region));
return known != null ? known : remember(lineage, region, resolve(lineage, region));
}
private Policy remember(IrisBiome biome, IrisRegion region, Policy resolved) {
private Policy remember(List<IrisBiome> lineage, IrisRegion region, Policy resolved) {
synchronized (policyLock) {
IdentityHashMap<IrisRegion, Policy> current = policies.get(biome);
IdentityHashMap<IrisRegion, Policy> current = policies.get(lineage);
Policy raced = current == null ? null : current.get(region);
if (raced != null) {
return raced;
}
boolean full = policyCount >= CAPACITY;
IdentityHashMap<IrisBiome, IdentityHashMap<IrisRegion, Policy>> next = full ? new IdentityHashMap<>() : new IdentityHashMap<>(policies);
IdentityHashMap<List<IrisBiome>, IdentityHashMap<IrisRegion, Policy>> next = full ? new IdentityHashMap<>() : new IdentityHashMap<>(policies);
IdentityHashMap<IrisRegion, Policy> regions = full || current == null ? new IdentityHashMap<>() : new IdentityHashMap<>(current);
regions.put(region, resolved);
next.put(biome, regions);
next.put(lineage, regions);
policyCount = full ? 1 : policyCount + 1;
policies = next;
return resolved;
}
}
private Policy resolve(IrisBiome biome, IrisRegion region) {
Integer width = IrisHydrologyPolicy.inherited(biome, region, dimension, IrisHydrologyPolicy::getShoreBiomeWidth);
List<String> keys = IrisHydrologyPolicy.inherited(biome, region, dimension, IrisHydrologyPolicy::getShoreBiomes);
private Policy resolve(List<IrisBiome> lineage, IrisRegion region) {
Integer width = IrisHydrologyPolicy.inherited(lineage, region, dimension, IrisHydrologyPolicy::getShoreBiomeWidth);
List<String> keys = IrisHydrologyPolicy.inherited(lineage, region, dimension, IrisHydrologyPolicy::getShoreBiomes);
if (width == null || width <= 0 || keys == null || keys.isEmpty()) {
return NONE;
}
IrisBiome[] biomes = new IrisBiome[keys.size()];
for (int index = 0; index < biomes.length; index++) {
biomes[index] = load(keys.get(index), biome, region).withInferredType(InferredType.SHORE);
biomes[index] = load(keys.get(index), lineage.isEmpty() ? null : lineage.getFirst(), region).withInferredType(InferredType.SHORE);
}
return new Policy(biomes, width);
}
@@ -26,7 +26,7 @@ final class HydrologyVegetationSource {
private final Object lock = new Object();
private boolean planted;
private volatile IdentityHashMap<List<IrisDecorator>, HydrologyVegetation.Decorators> compiled = new IdentityHashMap<>();
private volatile IdentityHashMap<IrisBiome, IdentityHashMap<IrisRegion, Resolved>> overrides = new IdentityHashMap<>();
private volatile IdentityHashMap<List<IrisBiome>, IdentityHashMap<IrisRegion, Resolved>> overrides = new IdentityHashMap<>();
private HydrologyVegetationSource(IrisData data, IrisDimension dimension, Map<HydrologyTier, HydrologyVegetation.Decorators> tiers,
HydrologyVegetation.Decorators ponds) {
@@ -62,11 +62,11 @@ final class HydrologyVegetationSource {
return planted;
}
HydrologyVegetation.Decorators decorators(HydrologyTier tier, IrisBiome biome, IrisRegion region) {
HydrologyVegetation.Decorators decorators(HydrologyTier tier, List<IrisBiome> lineage, IrisRegion region) {
if (data == null) {
return HydrologyVegetation.Decorators.EMPTY;
}
Resolved override = override(biome, region);
Resolved override = override(lineage, region);
if (override.decorators() != null) {
return override.decorators();
}
@@ -80,28 +80,28 @@ final class HydrologyVegetationSource {
return known;
}
private Resolved override(IrisBiome biome, IrisRegion region) {
IdentityHashMap<IrisRegion, Resolved> regions = overrides.get(biome);
private Resolved override(List<IrisBiome> lineage, IrisRegion region) {
IdentityHashMap<IrisRegion, Resolved> regions = overrides.get(lineage);
Resolved known = regions == null ? null : regions.get(region);
return known != null ? known : remember(biome, region, resolve(biome, region));
return known != null ? known : remember(lineage, region, resolve(lineage, region));
}
private Resolved resolve(IrisBiome biome, IrisRegion region) {
List<IrisDecorator> decorators = IrisHydrologyPolicy.inherited(biome, region, dimension, IrisHydrologyPolicy::getDecorators);
private Resolved resolve(List<IrisBiome> lineage, IrisRegion region) {
List<IrisDecorator> decorators = IrisHydrologyPolicy.inherited(lineage, region, dimension, IrisHydrologyPolicy::getDecorators);
return decorators == null ? Resolved.INHERIT : new Resolved(compiled(decorators, LAZY_POLICY));
}
private Resolved remember(IrisBiome biome, IrisRegion region, Resolved resolved) {
private Resolved remember(List<IrisBiome> lineage, IrisRegion region, Resolved resolved) {
synchronized (lock) {
IdentityHashMap<IrisRegion, Resolved> current = overrides.get(biome);
IdentityHashMap<IrisRegion, Resolved> current = overrides.get(lineage);
Resolved raced = current == null ? null : current.get(region);
if (raced != null) {
return raced;
}
IdentityHashMap<IrisBiome, IdentityHashMap<IrisRegion, Resolved>> next = new IdentityHashMap<>(overrides);
IdentityHashMap<List<IrisBiome>, IdentityHashMap<IrisRegion, Resolved>> next = new IdentityHashMap<>(overrides);
IdentityHashMap<IrisRegion, Resolved> regions = current == null ? new IdentityHashMap<>() : new IdentityHashMap<>(current);
regions.put(region, resolved);
next.put(biome, regions);
next.put(lineage, regions);
overrides = next;
return resolved;
}
@@ -121,8 +121,8 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiFunction;
@Data
@EqualsAndHashCode(exclude = {"data", "gridBoundsCache", "sharedCornerBounds", "sharedBaseHeights", "sharedBoundsBiomes", "regionBounds", "contextRegionStream", "terrainProgram", "bakeCache", "regionSource", "baseBiomeSource", "caveSource", "rockSource", "fluidSource", "childStyleSeed", "inferredByType", "naturalHeightSource", "naturalTrueBiomeSource", "trueBiomeSource", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "imageMapRuntime", "terrainEngine", "terrain3D", "hydrologyRuntime", "shoreBiomes", "waterVegetation", "effectiveChunks"})
@ToString(exclude = {"data", "gridBoundsCache", "sharedCornerBounds", "sharedBaseHeights", "sharedBoundsBiomes", "regionBounds", "contextRegionStream", "terrainProgram", "bakeCache", "regionSource", "baseBiomeSource", "caveSource", "rockSource", "fluidSource", "childStyleSeed", "inferredByType", "naturalHeightSource", "naturalTrueBiomeSource", "trueBiomeSource", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "imageMapRuntime", "terrainEngine", "terrain3D", "hydrologyRuntime", "shoreBiomes", "waterVegetation", "effectiveChunks"})
@EqualsAndHashCode(exclude = {"data", "gridBoundsCache", "sharedCornerBounds", "sharedBaseHeights", "sharedBoundsBiomes", "regionBounds", "contextRegionStream", "terrainProgram", "bakeCache", "regionSource", "baseBiomeSource", "caveSource", "rockSource", "fluidSource", "childStyleSeed", "inferredByType", "naturalHeightSource", "naturalTrueBiomeSource", "trueBiomeSource", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "imageMapRuntime", "terrainEngine", "terrain3D", "hydrologyRuntime", "shoreBiomes", "waterVegetation", "effectiveChunks", "biomeLineages"})
@ToString(exclude = {"data", "gridBoundsCache", "sharedCornerBounds", "sharedBaseHeights", "sharedBoundsBiomes", "regionBounds", "contextRegionStream", "terrainProgram", "bakeCache", "regionSource", "baseBiomeSource", "caveSource", "rockSource", "fluidSource", "childStyleSeed", "inferredByType", "naturalHeightSource", "naturalTrueBiomeSource", "trueBiomeSource", "frozenInterpolators", "frozenGenerators", "inferredBiomeStreams", "imageMapRuntime", "terrainEngine", "terrain3D", "hydrologyRuntime", "shoreBiomes", "waterVegetation", "effectiveChunks", "biomeLineages"})
public class IrisComplex implements DataProvider {
private static final NoiseBounds ZERO_NOISE_BOUNDS = new NoiseBounds(0D, 0D);
private static final long NEGATIVE_ZERO_BITS = Double.doubleToRawLongBits(-0D);
@@ -147,6 +147,7 @@ public class IrisComplex implements DataProvider {
IrisGenerator::getLoadKey,
Comparator.nullsFirst(Comparator.naturalOrder())
);
private static final int CHILD_HOPS = 4;
private static final ThreadLocal<TerrainBatchScratch> BATCH_SCRATCH = ThreadLocal.withInitial(TerrainBatchScratch::new);
private static final InferredType[] INFERRED_BIOME_PREPARATION_ORDER = {
InferredType.LAND,
@@ -277,6 +278,9 @@ public class IrisComplex implements DataProvider {
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient HydrologyShoreBiomes shoreBiomes;
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient BiomeLineages biomeLineages;
@Setter(AccessLevel.NONE)
private final transient SubterrainPlanner subterrainPlanner;
private transient IrisImageMapRuntime imageMapRuntime;
@@ -494,6 +498,7 @@ public class IrisComplex implements DataProvider {
Interpolated.of(value -> 0D, value -> null));
naturalTrueBiomeStream = new BakedStream<>(bakeCache, BakePlane.NATURAL_TRUE_BIOME, naturalTrueBiomeSource);
shoreBiomes = new HydrologyShoreBiomes(engine.getDimension(), data, engine.getSeedManager().getBodies());
biomeLineages = BiomeLineages.compile(focusedBiomes == null ? baseCapableBiomes(preparedRegions) : List.of(), this);
hydrologyRuntime = HydrologyRuntime.create(engine, this);
waterFluidStreams = hydrologyRuntime.enabled() ? createWaterFluidStreams(hydrologyRuntime.settings().fluids(), hydrologyRuntime.settings().seams().values()) : Map.of();
pondMaterials = hydrologyRuntime.enabled() ? hydrologyRuntime.settings().ponds().materials() : null;
@@ -1400,7 +1405,16 @@ public class IrisComplex implements DataProvider {
return HydrologyVegetation.Decorators.EMPTY;
}
HydrologyTier tier = chunkRasterAt(x, z).tier(x & 15, z & 15);
return waterVegetation.decorators(tier, baseBiomeStream.get(x, z), regionStream.get(x, z));
return waterVegetation.decorators(tier, baseBiomeLineage(x, z), regionStream.get(x, z));
}
public List<IrisBiome> baseBiomeLineage(int x, int z) {
IrisBiome biome = baseBiomeStream.get(x, z);
if (!biomeLineages.inherits(biome)
|| imageMapRuntime.has(IrisImageMapApplication.BIOME) && imageMapRuntime.sampleBiome(x, z) != null) {
return biomeLineages.root(biome);
}
return childLineage(biome, x, z);
}
private ChunkWaterRaster chunkRasterAt(int blockX, int blockZ) {
@@ -1810,7 +1824,7 @@ public class IrisComplex implements DataProvider {
|| seamWeight(blockX, blockZ) == 0D) {
return null;
}
IrisBiome shore = shoreBiomes.select(baseBiomeStream.get(x, z), regionStream.get(x, z), blockX, blockZ, distance);
IrisBiome shore = shoreBiomes.select(baseBiomeLineage(blockX, blockZ), regionStream.get(x, z), blockX, blockZ, distance);
return shore == null ? null : implode(shore, x, z);
}
@@ -2486,7 +2500,7 @@ public class IrisComplex implements DataProvider {
return b;
}
return implode(b, x, z, 3);
return implode(b, x, z, CHILD_HOPS - 1);
}
private IrisBiome implode(IrisBiome b, double x, double z, int max) {
@@ -2498,15 +2512,42 @@ public class IrisComplex implements DataProvider {
return b;
}
CNG childCell = b.getChildrenGenerator(childStyleSeed, b.getChildShrinkFactor());
ChildSelectionPlan childSelectionPlan = resolveChildSelectionPlan(b);
IrisBiome biome = childSelectionPlan.select(childCell, x, z).withInferredType(b.getInferredType());
IrisBiome biome = pickChild(b, x, z);
if (biome == b && hasFixedNoise(b.getChildStyle())) {
return biome;
}
return implode(biome, x, z, max - 1);
}
private IrisBiome pickChild(IrisBiome parent, double x, double z) {
CNG childCell = parent.getChildrenGenerator(childStyleSeed, parent.getChildShrinkFactor());
return resolveChildSelectionPlan(parent).select(childCell, x, z).withInferredType(parent.getInferredType());
}
private List<IrisBiome> childLineage(IrisBiome biome, int x, int z) {
IrisBiome[] rootFirst = new IrisBiome[CHILD_HOPS + 1];
IrisBiome current = inferredByType.get(bridgeStream.get(x, z)).get(x, z);
rootFirst[0] = current;
int size = 1;
for (int hop = 0; hop < CHILD_HOPS && !current.getChildren().isEmpty(); hop++) {
IrisBiome picked = pickChild(current, x, z);
if (picked == current) {
break;
}
rootFirst[size++] = picked;
current = picked;
}
if (current != biome) {
throw new IllegalStateException("The child chain at " + x + "," + z + " ends at biome " + current.getLoadKey()
+ ", but the base biome there is " + biome.getLoadKey());
}
IrisBiome[] leafFirst = new IrisBiome[size];
for (int index = 0; index < size; index++) {
leafFirst[index] = rootFirst[size - 1 - index];
}
return biomeLineages.chain(leafFirst);
}
static boolean hasFixedNaturalBiomeNoise(IrisDimension dimension, Iterable<IrisBiome> biomes) {
if (!hasFixedNoise(dimension.getRegionStyle()) || !hasFixedNoise(dimension.getContinentalStyle())
|| !hasFixedNoise(dimension.getLandBiomeStyle()) || !hasFixedNoise(dimension.getSeaBiomeStyle())) {
@@ -292,10 +292,13 @@ public final class RiverCompiler {
return new Field.Binary(Field.BinaryOp.MAX, first, second);
}
public record Area(IrisRegion region, IrisBiome biome) {
public record Area(IrisRegion region, List<IrisBiome> biomes) {
public Area {
Objects.requireNonNull(region, "region");
Objects.requireNonNull(biome, "biome");
biomes = List.copyOf(biomes);
if (biomes.isEmpty()) {
throw new IllegalArgumentException("A river area in region " + region.getLoadKey() + " needs a biome");
}
}
}
@@ -1,5 +1,6 @@
package art.arcane.iris.pack.datapack.export.compile.terrain;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.block.IrisBlockData;
import art.arcane.iris.generation.decoration.IrisDecorator;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPermission;
@@ -165,9 +166,11 @@ final class RiverLimits {
}
private <T> Sourced<T> sourced(RiverCompiler.Area area, Function<IrisHydrologyPolicy, T> field) {
T biome = value(area.biome().getHydrologyPolicy(), field);
if (biome != null) {
return new Sourced<>(new Owner(Owner.BIOME, "biomes/" + area.biome().getLoadKey()), biome);
for (IrisBiome biome : area.biomes()) {
T value = value(biome.getHydrologyPolicy(), field);
if (value != null) {
return new Sourced<>(new Owner(Owner.BIOME, "biomes/" + biome.getLoadKey()), value);
}
}
T region = value(area.region().getHydrologyPolicy(), field);
if (region != null) {
@@ -7,11 +7,9 @@ import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
import art.arcane.iris.pack.datapack.export.ir.Field;
import art.arcane.iris.pack.loading.IrisData;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -20,6 +18,7 @@ import java.util.TreeMap;
public final class RiverStage implements CompileStage {
private static final String ESTIMATE_TAG = "estimate";
private static final int MAX_CHILD_HOPS = 4;
@Override
public String name() {
@@ -46,32 +45,51 @@ public final class RiverStage implements CompileStage {
regions.sort(Comparator.comparing(IrisRegion::getLoadKey));
List<RiverCompiler.Area> areas = new ArrayList<>();
for (IrisRegion region : regions) {
for (IrisBiome biome : surfaceBiomes(region, data, exported)) {
areas.add(new RiverCompiler.Area(region, biome));
for (List<IrisBiome> lineage : lineages(region, data, exported)) {
areas.add(new RiverCompiler.Area(region, lineage));
}
}
return areas;
}
private static Collection<IrisBiome> surfaceBiomes(IrisRegion region, IrisData data, Set<String> exported) {
Deque<String> pending = new ArrayDeque<>();
pending.addAll(region.getLandBiomes());
pending.addAll(region.getSeaBiomes());
pending.addAll(region.getShoreBiomes());
Set<String> visited = new HashSet<>();
SortedMap<String, IrisBiome> biomes = new TreeMap<>();
while (!pending.isEmpty()) {
String key = pending.removeFirst();
if (key == null || !visited.add(key)) {
continue;
private static Collection<List<IrisBiome>> lineages(IrisRegion region, IrisData data, Set<String> exported) {
List<String> roots = new ArrayList<>();
roots.addAll(region.getLandBiomes());
roots.addAll(region.getSeaBiomes());
roots.addAll(region.getShoreBiomes());
SortedMap<String, List<IrisBiome>> lineages = new TreeMap<>();
for (String key : roots) {
IrisBiome root = exportedBiome(key, data, exported);
if (root != null) {
addLineages(List.of(root), data, exported, lineages);
}
IrisBiome biome = data.getBiomeLoader().load(key);
if (biome == null || biome.isCompatExcluded() || !exported.contains(biome.getLoadKey())) {
continue;
}
biomes.put(biome.getLoadKey(), biome);
pending.addAll(biome.getChildren());
}
return biomes.values();
return lineages.values();
}
private static void addLineages(List<IrisBiome> leafFirst, IrisData data, Set<String> exported, SortedMap<String, List<IrisBiome>> lineages) {
StringBuilder key = new StringBuilder(leafFirst.getFirst().getLoadKey());
for (int index = 1; index < leafFirst.size(); index++) {
key.append('<').append(leafFirst.get(index).getLoadKey());
}
if (lineages.putIfAbsent(key.toString(), leafFirst) != null || leafFirst.size() > MAX_CHILD_HOPS) {
return;
}
IrisBiome leaf = leafFirst.getFirst();
for (String childKey : leaf.getChildren()) {
IrisBiome child = exportedBiome(childKey, data, exported);
if (child == null || child.getLoadKey().equals(leaf.getLoadKey())) {
continue;
}
List<IrisBiome> lineage = new ArrayList<>(leafFirst.size() + 1);
lineage.add(child);
lineage.addAll(leafFirst);
addLineages(List.copyOf(lineage), data, exported, lineages);
}
}
private static IrisBiome exportedBiome(String key, IrisData data, Set<String> exported) {
IrisBiome biome = key == null ? null : data.getBiomeLoader().load(key);
return biome == null || biome.isCompatExcluded() || !exported.contains(biome.getLoadKey()) ? null : biome;
}
}