Merge lane B

- Land force place, unknown hydrology key warnings and the river fluid warning
- Rename dryDrawdown, minHeadKeep and waterfallMinDrop across new code
- Drop minCliffHeight with the old sea inlet passages
- Keep per-placement failure containment on forced and replaced pieces
- Repin the schema digest
This commit is contained in:
Brian Fopiano committed 2026-11-04 10:50:16 -05:00
commit 335b02f276
67 files changed
+2088 -340

No files matched your search

@@ -28,7 +28,7 @@ public class IrisHydrologyDrainage {
@MinNumber(0)
@MaxNumber(1)
@Description("Smallest share of stream heads kept in the driest areas when wetness thinning is on.")
private double minimumHeadKeep = 0.25D;
private double minHeadKeep = 0.25D;
@MinNumber(0)
@MaxNumber(64)
@@ -9,7 +9,7 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
@NoArgsConstructor
@Description("Large lakes that fill the biggest hollows in the terrain. Each lake has one water level across its whole surface. A hollow becomes a lake only when it is at least ponds.natural.minDepth deep and no more than 2048 blocks across. Lakes take their freeboard, climateDrawdown, shore roundness, materials, decorators and fluid from ponds.")
@Description("Large lakes that fill the biggest hollows in the terrain. Each lake has one water level across its whole surface. A hollow becomes a lake only when it is at least ponds.natural.minDepth deep and no more than 2048 blocks across. Lakes take their freeboard, dryDrawdown, shore roundness, materials, decorators and fluid from ponds.")
@Data
public class IrisHydrologyLakes {
@Description("Turns large hollows into lakes.")
@@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
@NoArgsConstructor
@Description("Standing water above sea level. Ponds fill natural hollows, seeded cups and optional dams, each with its own level, so ponds sit at many heights and streams link them into chains. Lakes take their freeboard, climateDrawdown, shore roundness, materials, decorators and fluid from here as well.")
@Description("Standing water above sea level. Ponds fill natural hollows, seeded cups and optional dams, each with its own level, so ponds sit at many heights and streams link them into chains. Lakes take their freeboard, dryDrawdown, shore roundness, materials, decorators and fluid from here as well.")
@Data
public class IrisHydrologyPonds {
@Description("Ponds that fill hollows already present in the terrain.")
@@ -32,7 +32,7 @@ public class IrisHydrologyPonds {
@MinNumber(0)
@MaxNumber(32)
@Description("Most extra blocks a pond or lake surface drops below its freeboard, in the driest areas. The drop is this value times the dryness at the floor, rounded: one minus the zone wetness, after the area's wetness bounds, where the dimension's wet and dry zones apply, and one minus the area's rainfall elsewhere, so water at a wetness or rainfall of 1 or more stays full.")
private int climateDrawdown = 6;
private int dryDrawdown = 6;
@Description("Shape of pond shores and floors. Lakes take only its roundness.")
private IrisPondShore shore = new IrisPondShore();
@@ -44,13 +44,13 @@ public class IrisHydrologyTier {
@Description("Blocks the water surface sits below the ground it flows through.")
private int inset = 1;
@Description("Groups the drops of a run into step-pools: the drops within 2.5 to 5 channel widths, from 6 to 32 blocks, join into one step. A step that starts with a cascade is at most waterfallMinimumDrop plus 2 blocks, and that limit ends the group early on steep ground. A step that starts with a waterfall is that waterfall plus the small drops it gathers below it. When false, drops are spread into a gentler slope where the terrain allows, including the step where a channel joins lower water; drops that cannot be spread, such as a junction right below a pond outlet, stay as small cascades below the waterfall minimum.")
@Description("Groups the drops of a run into step-pools: the drops within 2.5 to 5 channel widths, from 6 to 32 blocks, join into one step. A step that starts with a cascade is at most waterfallMinDrop plus 2 blocks, and that limit ends the group early on steep ground. A step that starts with a waterfall is that waterfall plus the small drops it gathers below it. When false, drops are spread into a gentler slope where the terrain allows, including the step where a channel joins lower water; drops that cannot be spread, such as a junction right below a pond outlet, stay as small cascades below the waterfall minimum.")
private boolean cascades = true;
@MinNumber(2)
@MaxNumber(64)
@Description("Smallest drop in blocks that becomes a waterfall.")
private int waterfallMinimumDrop = 6;
private int waterfallMinDrop = 6;
@MinNumber(1)
@MaxNumber(2)
@@ -9,16 +9,16 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
@NoArgsConstructor
@Description("Bounds on how wet the dimension's wet and dry zones make this area. The zone wetness runs from the climate's dryRainfall in dry zones to 1 in wet zones and is held between min and max here. The bounded wetness scales rainfall and pond density, and a pond or lake whose floor lies here drops ponds.climateDrawdown times one minus it, rounded, below its freeboard.")
@Description("Bounds on how wet the dimension's wet and dry zones make this area. The zone wetness runs from the climate's dryRainfall in dry zones to 1 in wet zones and is held between min and max here. The bounded wetness scales rainfall and pond density, and a pond or lake whose floor lies here drops ponds.dryDrawdown times one minus it, rounded, below its freeboard.")
@Data
public class IrisHydrologyWetness {
@MinNumber(0)
@MaxNumber(1)
@Description("Lowest wetness this area falls to, even inside a dry zone. 0.7 keeps 70% of the rainfall and pond density in dry zones and lowers ponds and lakes by at most 30% of ponds.climateDrawdown. Left out, it is 0.")
@Description("Lowest wetness this area falls to, even inside a dry zone. 0.7 keeps 70% of the rainfall and pond density in dry zones and lowers ponds and lakes by at most 30% of ponds.dryDrawdown. Left out, it is 0.")
private double min = 0D;
@MinNumber(0)
@MaxNumber(1)
@Description("Highest wetness this area reaches, even inside a wet zone. 0.35 keeps at most 35% of the rainfall and pond density and lowers ponds and lakes by at least 65% of ponds.climateDrawdown. Must not be below min. Left out, it is 1.")
@Description("Highest wetness this area reaches, even inside a wet zone. 0.35 keeps at most 35% of the rainfall and pond density and lowers ponds and lakes by at least 65% of ponds.dryDrawdown. Must not be below min. Left out, it is 1.")
private double max = 1D;
}
@@ -235,7 +235,7 @@ public final class HydrologySettings {
private static HydrologyTier tidalTier(HydrologyTier base, SeaInlets inlets) {
return new HydrologyTier(TIDAL_TIER_NAME, base.minCatchment(), inlets.meanderWidth(), inlets.meanderWidth(), 0f, base.depthRatio(), 0, false,
base.waterfallMinimumDrop(), base.stepHeight(), inlets.bankBand(), inlets.bankStyle(), new HydrologyTier.Estuary(0, 1f),
base.waterfallMinDrop(), base.stepHeight(), inlets.bankBand(), inlets.bankStyle(), new HydrologyTier.Estuary(0, 1f),
new HydrologyTier.Delta(0, 0f, 0), base.materials(), base.fluid(), base.decorators());
}
@@ -257,7 +257,7 @@ public final class HydrologySettings {
private static Drainage drainage(IrisHydrologyDrainage config) {
return new Drainage((float) config.getFillEpsilon(), config.getBreachDepth(), config.isWetnessThinning(),
(float) config.getMinimumHeadKeep(), (float) config.getHeadRelief(), (float) config.getSaturationCatchment());
(float) config.getMinHeadKeep(), (float) config.getHeadRelief(), (float) config.getSaturationCatchment());
}
private static List<HydrologyTier> tiers(List<IrisHydrologyTier> configs) {
@@ -308,7 +308,7 @@ public final class HydrologySettings {
}
return new HydrologyTier(config.getName(), (float) config.getMinCatchment(), halfWidth.min(), halfWidth.max(),
(float) config.getWidthFactor(), (float) config.getDepthRatio(), config.getInset(), config.isCascades(),
config.getWaterfallMinimumDrop(), config.getStepHeight(), config.getBankBand(), config.getBankStyle(),
config.getWaterfallMinDrop(), config.getStepHeight(), config.getBankBand(), config.getBankStyle(),
estuary(config.getEstuary(), field + ".estuary"), delta(config, halfWidth.max(), field + ".delta"),
materials(config.getMaterials(), field + ".materials"), config.getFluid(), decorators(config.getDecorators(), field + ".decorators"));
}
@@ -360,7 +360,7 @@ public final class HydrologySettings {
return new Ponds(naturalPonds(config.getNatural()), seededPonds(config.getSeeded()),
new PondDams(dams.isEnabled(), dams.getMaxRaise()),
intRange(config.getFreeboard(), "ponds.freeboard", RangeFloor.NON_NEGATIVE),
config.getClimateDrawdown(), pondShore(config.getShore()), materials(config.getMaterials(), "ponds.materials"), config.getFluid(),
config.getDryDrawdown(), pondShore(config.getShore()), materials(config.getMaterials(), "ponds.materials"), config.getFluid(),
decorators(config.getDecorators(), "ponds.decorators"));
}
@@ -675,7 +675,7 @@ public final class HydrologySettings {
private static void requireTierBounds(IrisHydrologyTier config, String field) {
requireNonNegative(config.getWidthFactor(), field + ".widthFactor");
requireNonNegative(config.getDepthRatio(), field + ".depthRatio");
requireAtLeast(config.getWaterfallMinimumDrop(), MIN_WATERFALL_DROP, field + ".waterfallMinimumDrop");
requireAtLeast(config.getWaterfallMinDrop(), MIN_WATERFALL_DROP, field + ".waterfallMinDrop");
requireWithin(config.getStepHeight(), 1, WaterHeads.STANDING_STEP, field + ".stepHeight");
requireShoreDepth(config.getMaterials(), field + ".materials");
}
@@ -782,7 +782,7 @@ public final class HydrologySettings {
private void addDrainage(Fingerprint hash) {
hash.add(drainage.fillEpsilon()).add(drainage.breachDepth()).add(drainage.wetnessThinning())
.add(drainage.minimumHeadKeep()).add(drainage.headRelief()).add(drainage.saturationCatchment());
.add(drainage.minHeadKeep()).add(drainage.headRelief()).add(drainage.saturationCatchment());
}
private void addTiers(Fingerprint hash) {
@@ -790,7 +790,7 @@ public final class HydrologySettings {
for (HydrologyTier tier : tiers) {
hash.add(tier.name()).add(tier.minCatchment()).add(tier.minHalfWidth()).add(tier.maxHalfWidth())
.add(tier.widthFactor()).add(tier.depthRatio()).add(tier.inset()).add(tier.cascades())
.add(tier.waterfallMinimumDrop()).add(tier.stepHeight()).add(tier.bankBand()).add(tier.bankStyle())
.add(tier.waterfallMinDrop()).add(tier.stepHeight()).add(tier.bankBand()).add(tier.bankStyle())
.add(tier.estuary().length()).add(tier.estuary().flare())
.add(tier.delta().channels()).add(tier.delta().spreadDegrees()).add(tier.delta().length())
.add(tier.materials()).add(tier.fluid());
@@ -806,7 +806,7 @@ public final class HydrologySettings {
.add(seeded.enabled()).add(seeded.density()).add(seeded.radius()).add(seeded.depth())
.add(seeded.maxSlope()).add(seeded.alongChannels()).add(seeded.channelSpacing())
.add(ponds.dams().enabled()).add(ponds.dams().maxRaise())
.add(ponds.freeboard()).add(ponds.climateDrawdown())
.add(ponds.freeboard()).add(ponds.dryDrawdown())
.add(shore.roundness()).add(shore.shelf()).add(shore.taper()).add(shore.maxDepth())
.add(ponds.materials()).add(ponds.fluid());
}
@@ -863,7 +863,7 @@ public final class HydrologySettings {
}
}
public record Drainage(float fillEpsilon, int breachDepth, boolean wetnessThinning, float minimumHeadKeep, float headRelief,
public record Drainage(float fillEpsilon, int breachDepth, boolean wetnessThinning, float minHeadKeep, float headRelief,
float saturationCatchment) {
}
@@ -881,7 +881,7 @@ public final class HydrologySettings {
}
public record Ponds(NaturalPonds natural, SeededPonds seeded, PondDams dams, IntRange freeboard,
int climateDrawdown, PondShore shore, IrisHydrologyMaterials materials, String fluid,
int dryDrawdown, PondShore shore, IrisHydrologyMaterials materials, String fluid,
List<IrisDecorator> decorators) {
}
@@ -294,7 +294,7 @@ public final class WindowPlanner {
private boolean keepHead(DemGrid surface, int cell, float rainfall) {
HydrologySettings.Drainage drainage = settings.drainage();
float keep = drainage.wetnessThinning() ? Math.clamp(Math.max(drainage.minimumHeadKeep(), rainfall), 0f, 1f) : 1f;
float keep = drainage.wetnessThinning() ? Math.clamp(Math.max(drainage.minHeadKeep(), rainfall), 0f, 1f) : 1f;
keep *= settings.density();
return CellHash.unit(CellHash.mix(settings.seed(), SALT_HEAD, surface.blockX(cell), surface.blockZ(cell))) < keep;
}
@@ -60,13 +60,13 @@ public final class LinkBlend {
int[] grade = feeder.grade();
int level = junction.level();
boolean[] fixed = fixed(feeder, lips, junction.fed() && grade[0] - level > ConfluenceGrader.MAX_START_LOWERING);
int waterfallMinimumDrop = feeder.tier().waterfallMinimumDrop();
int[] settled = ConfluenceGrader.settle(footprint(feeder), grade, fixed, receiving, level, waterfallMinimumDrop);
int waterfallMinDrop = feeder.tier().waterfallMinDrop();
int[] settled = ConfluenceGrader.settle(footprint(feeder), grade, fixed, receiving, level, waterfallMinDrop);
if (settled == grade) {
return feeder;
}
if (!feeder.tier().cascades()) {
ConfluenceGrader.spreadJunction(settled, grade, fixed, waterfallMinimumDrop, Integer.MIN_VALUE);
ConfluenceGrader.spreadJunction(settled, grade, fixed, waterfallMinDrop, Integer.MIN_VALUE);
}
return regraded(feeder, settled, feeder.halfWidth(), feeder.depth(), seaLevel);
}
@@ -101,19 +101,19 @@ public final class LinkBlend {
}
private static Reach regraded(Reach reach, int[] grade, float[] halfWidth, float[] depth, int seaLevel) {
ReachStyle[] style = grade == reach.grade() ? reach.style() : restyled(reach.style(), grade, reach.tier().waterfallMinimumDrop(), seaLevel, reach.tier().stepHeight());
ReachStyle[] style = grade == reach.grade() ? reach.style() : restyled(reach.style(), grade, reach.tier().waterfallMinDrop(), seaLevel, reach.tier().stepHeight());
return new Reach(reach.id(), reach.tier(), reach.downstreamId(), reach.xs(), reach.zs(), grade, halfWidth, depth, style,
reach.catchment());
}
private static ReachStyle[] restyled(ReachStyle[] style, int[] grade, int waterfallMinimumDrop, int seaLevel, int stepHeight) {
private static ReachStyle[] restyled(ReachStyle[] style, int[] grade, int waterfallMinDrop, int seaLevel, int stepHeight) {
boolean[] mouth = new boolean[style.length];
boolean[] outlet = new boolean[style.length];
for (int point = 0; point < style.length; point++) {
mouth[point] = style[point] == ReachStyle.MOUTH;
outlet[point] = style[point] == ReachStyle.POND_OUTLET;
}
return ReachShaper.styles(grade, mouth, outlet, waterfallMinimumDrop, seaLevel, stepHeight);
return ReachShaper.styles(grade, mouth, outlet, waterfallMinDrop, seaLevel, stepHeight);
}
private static int lowestEnd(List<Reach> feeders) {
@@ -322,7 +322,7 @@ final class RasterComposer {
continue;
}
int drop = 0;
int waterfallMinimumDrop = Integer.MAX_VALUE;
int waterfallMinDrop = Integer.MAX_VALUE;
for (int side : SIDES) {
int upper = cell + side;
if (!role[upper].flowing() || feature[upper] == feature[cell]) {
@@ -331,11 +331,11 @@ final class RasterComposer {
int step = head[upper] - head[cell];
if (step >= 2 && step > drop) {
drop = step;
waterfallMinimumDrop = tier[upper].waterfallMinimumDrop();
waterfallMinDrop = tier[upper].waterfallMinDrop();
}
}
if (drop > 0) {
role[cell] = drop >= waterfallMinimumDrop ? WaterRole.WATERFALL : WaterRole.CASCADE;
role[cell] = drop >= waterfallMinDrop ? WaterRole.WATERFALL : WaterRole.CASCADE;
}
}
}
@@ -18,7 +18,7 @@ public final class ConfluenceGrader {
public record Footprint(float[] xs, float[] zs, float[] halfWidth) {
}
public static int[] settle(Footprint feeder, int[] grade, boolean[] fixed, List<Footprint> receiving, int level, int waterfallMinimumDrop) {
public static int[] settle(Footprint feeder, int[] grade, boolean[] fixed, List<Footprint> receiving, int level, int waterfallMinDrop) {
int last = grade.length - 1;
double[] arc = arcFromEnd(feeder);
int[] settled = lower(grade, grade, last, level);
@@ -27,20 +27,20 @@ public final class ConfluenceGrader {
settled = lower(settled, grade, point, level);
edge = point;
}
int meet = approach(grade, fixed, arc, edge, level, waterfallMinimumDrop);
int meet = approach(grade, fixed, arc, edge, level, waterfallMinDrop);
for (int point = edge - 1; point > meet; point--) {
settled = lower(settled, grade, point, envelope(arc, edge, point, level));
}
return settled;
}
public static void spreadJunction(int[] settled, int[] grade, boolean[] fixed, int waterfallMinimumDrop, int startLimit) {
public static void spreadJunction(int[] settled, int[] grade, boolean[] fixed, int waterfallMinDrop, int startLimit) {
int lowered = 0;
while (settled[lowered] == grade[lowered]) {
lowered++;
}
for (int point = settled.length - 2; point >= 0; point--) {
if (!ReachGrader.spreadPoint(settled, point, waterfallMinimumDrop, startLimit, fixed) && point < lowered) {
if (!ReachGrader.spreadPoint(settled, point, waterfallMinDrop, startLimit, fixed) && point < lowered) {
return;
}
}
@@ -55,14 +55,14 @@ public final class ConfluenceGrader {
requireJunction(window, draft, downstream);
boolean[] fixed = draft.fixed();
fixed[0] |= draft.incoming.length > 0 && draft.grade[0] - downstream.grade[0] > MAX_START_LOWERING;
int waterfallMinimumDrop = draft.tier.waterfallMinimumDrop();
int waterfallMinDrop = draft.tier.waterfallMinDrop();
int[] settled = settle(footprint(draft), draft.grade, fixed, receiving(drafts, downstream, feeder), downstream.grade[0],
waterfallMinimumDrop);
waterfallMinDrop);
if (settled == draft.grade) {
continue;
}
if (!draft.tier.cascades()) {
spreadJunction(settled, draft.grade, fixed, waterfallMinimumDrop, ReachGrader.startLimit(drafts, draft));
spreadJunction(settled, draft.grade, fixed, waterfallMinDrop, ReachGrader.startLimit(drafts, draft));
}
draft.grade = settled;
touched[feeder] = true;
@@ -116,8 +116,8 @@ public final class ConfluenceGrader {
return beside && lowering <= MARGIN_LOWERING;
}
private static int approach(int[] grade, boolean[] fixed, double[] arc, int edge, int level, int waterfallMinimumDrop) {
double window = (waterfallMinimumDrop - 1) / (double) APPROACH_SLOPE;
private static int approach(int[] grade, boolean[] fixed, double[] arc, int edge, int level, int waterfallMinDrop) {
double window = (waterfallMinDrop - 1) / (double) APPROACH_SLOPE;
for (int point = edge - 1; point >= 0 && arc[point] - arc[edge] <= window; point--) {
if (grade[point] <= envelope(arc, edge, point, level)) {
return point;
@@ -15,7 +15,7 @@ public record HydrologyTier(
float depthRatio,
int inset,
boolean cascades,
int waterfallMinimumDrop,
int waterfallMinDrop,
int stepHeight,
int bankBand,
IrisBankStyle bankStyle,
@@ -776,7 +776,7 @@ public final class PondPlanner {
}
private int drawdown(float dryness) {
return Math.round(settings.ponds().climateDrawdown() * dryness);
return Math.round(settings.ponds().dryDrawdown() * dryness);
}
private static int radius(DemGrid raw, Basin basin) {
@@ -297,7 +297,7 @@ final class ReachFitter {
Tangents tangents = tangents(fitted.xs(), fitted.zs());
float[] ahead = lowestColumnsAhead(fitted);
float[] edgesAhead = lowestEdgesAhead(fitted, tangents, tier);
float drop = tier.waterfallMinimumDrop();
float drop = tier.waterfallMinDrop();
for (int point = 0; point < points; point++) {
float lowest = Float.POSITIVE_INFINITY;
float lowestLand = Float.POSITIVE_INFINITY;
@@ -83,7 +83,7 @@ final class ReachGrader {
for (int position = upstreamFirst.length - 1; position >= 0; position--) {
ReachDraft draft = drafts.get(upstreamFirst[position]);
if (!draft.tier.cascades()) {
spread(draft.grade, draft.tier.waterfallMinimumDrop(), startLimit(drafts, draft), draft.held);
spread(draft.grade, draft.tier.waterfallMinDrop(), startLimit(drafts, draft), draft.held);
}
lowerIncomingEnds(drafts, draft);
}
@@ -185,16 +185,16 @@ final class ReachGrader {
int limit = Integer.MIN_VALUE;
for (int upstream : draft.incoming) {
ReachDraft feeder = drafts.get(upstream);
limit = Math.max(limit, carryLimit(feeder.grade, feeder.grade.length - 1, feeder.tier.waterfallMinimumDrop()));
limit = Math.max(limit, carryLimit(feeder.grade, feeder.grade.length - 1, feeder.tier.waterfallMinDrop()));
}
return limit;
}
private static int carryLimit(int[] grade, int point, int waterfallMinimumDrop) {
if (point == 0 || grade[point - 1] - grade[point] >= waterfallMinimumDrop) {
private static int carryLimit(int[] grade, int point, int waterfallMinDrop) {
if (point == 0 || grade[point - 1] - grade[point] >= waterfallMinDrop) {
return Integer.MIN_VALUE;
}
return grade[point - 1] - (waterfallMinimumDrop - 1);
return grade[point - 1] - (waterfallMinDrop - 1);
}
private static int[] profile(List<ReachDraft> drafts, ReachDraft draft) {
@@ -237,18 +237,18 @@ final class ReachGrader {
return sorted[Math.max(0, (int) Math.ceil(POOL_QUANTILE * sorted.length) - 1)];
}
private static void spread(int[] grade, int waterfallMinimumDrop, int startLimit, boolean[] held) {
private static void spread(int[] grade, int waterfallMinDrop, int startLimit, boolean[] held) {
for (int point = grade.length - 2; point >= 0; point--) {
spreadPoint(grade, point, waterfallMinimumDrop, startLimit, held);
spreadPoint(grade, point, waterfallMinDrop, startLimit, held);
}
}
static boolean spreadPoint(int[] grade, int point, int waterfallMinimumDrop, int startLimit, boolean[] held) {
static boolean spreadPoint(int[] grade, int point, int waterfallMinDrop, int startLimit, boolean[] held) {
int drop = grade[point] - grade[point + 1];
if (drop < 2 || drop >= waterfallMinimumDrop || held != null && held[point]) {
if (drop < 2 || drop >= waterfallMinDrop || held != null && held[point]) {
return false;
}
int limit = point == 0 ? startLimit : carryLimit(grade, point, waterfallMinimumDrop);
int limit = point == 0 ? startLimit : carryLimit(grade, point, waterfallMinDrop);
int spread = Math.min(grade[point], Math.max(grade[point + 1] + 1, limit));
boolean lowered = spread < grade[point];
grade[point] = spread;
@@ -390,7 +390,7 @@ public final class ReachShaper {
}
private static void restyle(ReachDraft draft, int seaLevel) {
draft.style = styles(draft.grade, draft.ocean, draft.fixed(), draft.tier.waterfallMinimumDrop(), seaLevel, draft.tier.stepHeight());
draft.style = styles(draft.grade, draft.ocean, draft.fixed(), draft.tier.waterfallMinDrop(), seaLevel, draft.tier.stepHeight());
}
private static void chaikin(ReachDraft draft) {
@@ -505,7 +505,7 @@ public final class ReachShaper {
Opening estuary = draft.chain.end() == ReachTracer.End.OCEAN ? estuaryOpening(draft.tier.estuary(), draft.ocean, distance)
: Opening.closed(count);
float widening = (draft.tier.estuary().flare() - 1f) * estuary.share();
float[] plunge = plungeFlare(draft.grade, draft.style, draft.ocean, distance, ReachGrader.protectedStart(draft), draft.tier.waterfallMinimumDrop());
float[] plunge = plungeFlare(draft.grade, draft.style, draft.ocean, distance, ReachGrader.protectedStart(draft), draft.tier.waterfallMinDrop());
float running = upstream;
draft.halfWidth = new float[count];
draft.depth = new float[count];
@@ -528,12 +528,12 @@ public final class ReachShaper {
draft.maxHalfWidth = running;
}
static float[] plungeFlare(int[] grade, ReachStyle[] style, boolean[] ocean, float[] distance, float protectedLength, int waterfallMinimumDrop) {
static float[] plungeFlare(int[] grade, ReachStyle[] style, boolean[] ocean, float[] distance, float protectedLength, int waterfallMinDrop) {
int count = grade.length;
float[] flare = new float[count];
for (int foot = 1; foot < count - 1; foot++) {
int drop = grade[foot - 1] - grade[foot];
if (style[foot] != ReachStyle.WATERFALL || drop < waterfallMinimumDrop) {
if (style[foot] != ReachStyle.WATERFALL || drop < waterfallMinDrop) {
continue;
}
float length = StepPools.plungeLength(drop);
@@ -574,11 +574,11 @@ public final class ReachShaper {
return Math.clamp(1f - remaining / length, 0f, 1f);
}
public static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop, int seaLevel, int stepHeight) {
public static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinDrop, int seaLevel, int stepHeight) {
ReachStyle[] styles = new ReachStyle[grade.length];
for (int point = 0; point < grade.length; point++) {
int drop = point == 0 ? 0 : grade[point - 1] - grade[point];
styles[point] = style(drop, waterfallMinimumDrop, ocean[point], outletZone[point]);
styles[point] = style(drop, waterfallMinDrop, ocean[point], outletZone[point]);
if (drop == 1 && !ocean[point] && outletZone[point - 1]
&& WaterHeads.snap(grade[point - 1], seaLevel, stepHeight) - WaterHeads.snap(grade[point], seaLevel, stepHeight) >= 2) {
styles[point] = ReachStyle.CASCADE;
@@ -586,18 +586,18 @@ public final class ReachShaper {
}
for (int point = 1; point < grade.length; point++) {
if (styles[point] == ReachStyle.MOUTH && styles[point - 1] != ReachStyle.MOUTH
&& grade[point - 1] - grade[point] >= waterfallMinimumDrop) {
&& grade[point - 1] - grade[point] >= waterfallMinDrop) {
styles[point - 1] = ReachStyle.WATERFALL;
}
}
return styles;
}
private static ReachStyle style(int drop, int waterfallMinimumDrop, boolean mouth, boolean outlet) {
private static ReachStyle style(int drop, int waterfallMinDrop, boolean mouth, boolean outlet) {
if (mouth) {
return ReachStyle.MOUTH;
}
if (drop >= waterfallMinimumDrop) {
if (drop >= waterfallMinDrop) {
return ReachStyle.WATERFALL;
}
if (drop >= 2) {
@@ -167,7 +167,7 @@ public final class SeaApproach {
if (reach.style()[point] == ReachStyle.POND_OUTLET || besidePond(reach, point)) {
return true;
}
if (level - below < reach.tier().waterfallMinimumDrop()) {
if (level - below < reach.tier().waterfallMinDrop()) {
return false;
}
return along > COAST_REACH || level - seaLevel >= CLIFF_HEIGHT;
@@ -204,7 +204,7 @@ public final class SeaApproach {
ocean[point] = reach.style()[point] == ReachStyle.MOUTH;
outlet[point] = reach.style()[point] == ReachStyle.POND_OUTLET;
}
ReachStyle[] styled = ReachShaper.styles(grade, ocean, outlet, reach.tier().waterfallMinimumDrop(), seaLevel, reach.tier().stepHeight());
ReachStyle[] styled = ReachShaper.styles(grade, ocean, outlet, reach.tier().waterfallMinDrop(), seaLevel, reach.tier().stepHeight());
ReachStyle[] style = reach.style().clone();
for (int point = 0; point < count; point++) {
boolean touched = grade[point] != reach.grade()[point] || point > 0 && grade[point - 1] != reach.grade()[point - 1]
@@ -23,7 +23,7 @@ final class StepPools {
}
static int stepMaxDrop(HydrologyTier tier) {
return tier.waterfallMinimumDrop() + STEP_EXTRA;
return tier.waterfallMinDrop() + STEP_EXTRA;
}
static float plungeLength(int drop) {
@@ -45,7 +45,7 @@ final class StepPools {
}
int top = grade[point - 1];
int first = top - grade[point];
boolean cliff = first >= tier.waterfallMinimumDrop();
boolean cliff = first >= tier.waterfallMinDrop();
float width = 2f * (tier.halfWidth(catchments[point]) + 1f);
float span = cliff ? plungeLength(first)
: Math.clamp(width * poolWidths(seed, xs[point], zs[point]), POOL_MIN, POOL_MAX);
@@ -56,14 +56,14 @@ final class StepPools {
if (grade[next] >= grade[end]) {
continue;
}
int limit = cliff ? grade[point] - tier.waterfallMinimumDrop() : top - stepMaxDrop(tier) - 1;
int limit = cliff ? grade[point] - tier.waterfallMinDrop() : top - stepMaxDrop(tier) - 1;
if (grade[next] <= limit || highestFloor > grade[next]) {
break;
}
end = next;
}
Arrays.fill(grade, point, end, grade[end]);
if (cliff && first >= 2 * tier.waterfallMinimumDrop()) {
if (cliff && first >= 2 * tier.waterfallMinDrop()) {
rollover(grade, floors, along, point, width, start);
}
point = end + 1;
@@ -23,6 +23,7 @@ import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.structure.object.IObjectPlacer;
import art.arcane.iris.generation.block.TileData;
import art.arcane.iris.structure.object.ObjectWaterRule;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import art.arcane.volmlib.util.math.BlockPosition;
import art.arcane.iris.generation.block.B;
@@ -44,18 +45,18 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
private final ObjectContinuationBundle.PlacementKey placementKey;
private final KList<BufferedMutation> mutations;
private final Map<PositionKey, NativeBlockState> bufferedBlocks;
private final boolean entersWater;
private final ObjectWaterRule waterRule;
private ObjectHydrologyVeto waterVeto;
private int blockWrites;
private BlockPosition canopyPosition;
FloatingObjectPlacementTransaction(IObjectPlacer delegate, ObjectContinuationBundle.PlacementKey placementKey,
boolean entersWater) {
ObjectWaterRule waterRule) {
this.delegate = Objects.requireNonNull(delegate);
this.placementKey = Objects.requireNonNull(placementKey);
this.mutations = new KList<>();
this.bufferedBlocks = new HashMap<>();
this.entersWater = entersWater;
this.waterRule = waterRule;
}
CommitResult commit() {
@@ -161,7 +162,7 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
@Override
public void set(int x, int y, int z, NativeBlockState state) {
if (state == null || waterVeto().keepsBlock(x, y, z, state, entersWater)) {
if (state == null || waterVeto().keepsBlock(x, y, z, state, waterRule)) {
return;
}
mutations.add(new BlockMutation(x, y, z, state, isCanopy(x, y, z)));
@@ -251,9 +252,9 @@ final class FloatingObjectPlacementTransaction implements IObjectPlacer {
private boolean keepsWater(int x, int y, int z, Object data) {
if (data instanceof NativeBlockState state) {
return waterVeto().keepsBlock(x, y, z, state, entersWater);
return waterVeto().keepsBlock(x, y, z, state, waterRule);
}
return data instanceof MatterCavern && waterVeto().keeps(x, y, z, false, entersWater);
return data instanceof MatterCavern && waterVeto().keeps(x, y, z, false, waterRule);
}
private ObjectHydrologyVeto waterVeto() {
@@ -18,6 +18,7 @@
package art.arcane.iris.generation.mantle;
import art.arcane.iris.structure.object.ObjectWaterRule;
import art.arcane.volmlib.util.structure.StructureCarvingFootprint;
import art.arcane.volmlib.util.structure.StructureCarveEnvelope;
@@ -167,36 +168,24 @@ public class IrisStructureComponent extends IrisMantleComponent {
KList<PlacedStructurePiece> pieces, RNG rng) {
IrisStructureStiltSettings stilt = placement.getStilt();
PieceRun run = new PieceRun(structure, rng, stilt == null ? null : new Long2IntOpenHashMap(),
stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater(),
placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE);
ObjectPlaceMode mode = structure.getPlaceMode();
stilt != null && stilt.isSupportNonOccluding(), placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE);
ObjectPlaceMode mode = placement.pieceMode(structure, pieces.size());
boolean forced = placement.forcesPieces(structure, pieces.size());
ObjectWaterRule rule = forced ? ObjectWaterRule.FORCED
: placement.isAllowWater() ? ObjectWaterRule.ENTERS_WATER : ObjectWaterRule.KEEP_OUT;
int failedPieces = 0;
int water = writer.beginObjectPlacement(run.allowWater());
writer.beginObjectPlacement(rule);
try {
if (placement.isAnchoredUnderground()) {
ObjectPlaceMode undergroundMode = (mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG)
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, run, p, undergroundMode, false) == -1) {
failedPieces++;
}
}
} else if (pieces.size() == 1 && mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
if (placeObject(writer, run, pieces.getFirst(), mode, true) == -1) {
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, run, p, mode, forced) == -1) {
failedPieces++;
}
} else {
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, run, p, ObjectPlaceMode.STRUCTURE_PIECE, false) == -1) {
failedPieces++;
}
}
}
if (failedPieces == 0 && stilt != null) {
placeFoundation(writer, run.foundationColumns(), stilt, rng, !placement.isAnchoredUnderground());
}
} finally {
writer.endObjectPlacement(water);
writer.endObjectPlacement();
}
return failedPieces;
}
@@ -567,7 +556,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
boolean sampledHeight) {
IrisObject object = p.getObject();
String objectKey = object.getLoadKey();
IrisObjectPlacement config = piecePlacement(run.structure(), p, mode, run.allowWater());
IrisObjectPlacement config = piecePlacement(run.structure(), p, mode);
String marker = structurePlacementMarker(run.structure(), p, objectKey);
BiConsumer<BlockPosition, NativeBlockState> listener = (position, state) -> {
StructureFoundationPlanner.recordBaseCell(
@@ -591,8 +580,7 @@ public class IrisStructureComponent extends IrisMantleComponent {
}
}
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode,
boolean allowWater) {
static IrisObjectPlacement piecePlacement(IrisStructure structure, PlacedStructurePiece piece, ObjectPlaceMode mode) {
IrisObjectPlacement config = structure.createLootPlacement(piece.getObject().getLoadKey());
config.setMode(mode);
config.setRotation(piece.getRotation());
@@ -601,7 +589,6 @@ public class IrisStructureComponent extends IrisMantleComponent {
}
if (mode != ObjectPlaceMode.STRUCTURE_PIECE && mode != ObjectPlaceMode.FLOATING) {
config.setForcePlace(true);
config.setForcedByStructure(!allowWater);
}
return config;
}
@@ -728,6 +715,6 @@ public class IrisStructureComponent extends IrisMantleComponent {
}
private record PieceRun(IrisStructure structure, RNG rng, Long2IntOpenHashMap foundationColumns,
boolean supportNonOccluding, boolean allowWater, boolean replacesSource) {
boolean supportNonOccluding, boolean replacesSource) {
}
}
@@ -217,7 +217,7 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
int id = rng.i(0, Integer.MAX_VALUE);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
writer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
writer, placements.next(minX >> 4, minZ >> 4), placement.waterRule());
try {
int resultY = obj.place(xx, zz, transaction, floatingPlacement, rng, (b, bd) -> {
String marker = placementMarker(obj, id);
@@ -311,7 +311,7 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
IslandObjectPlacer islandPlacer = IslandObjectPlacer.top(writer, sampleProvider, entry, pickTopY);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.waterRule());
int id = rng.i(0, Integer.MAX_VALUE);
try {
@@ -424,7 +424,7 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
IslandObjectPlacer islandPlacer = IslandObjectPlacer.bottom(writer, sampleProvider, entry, pickBottomY);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.entersWater());
islandPlacer, placements.next(minX >> 4, minZ >> 4), placement.waterRule());
int id = rng.i(0, Integer.MAX_VALUE);
try {
@@ -735,7 +735,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
try {
int placeResult = -1;
CaveObjectPlacementTransaction.CommitResult commitResult = CaveObjectPlacementTransaction.CommitResult.EMPTY;
int continuation = writer.beginObjectPlacement(placement.entersWater());
int continuation = writer.beginObjectPlacement(placement.waterRule());
if (carving) {
int caveFloorY = caveAnchor.y();
if (golden) {
@@ -778,7 +778,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
}, null, getData());
}
if (placeResult >= 0 && (!carving || commitResult == CaveObjectPlacementTransaction.CommitResult.COMMITTED)) {
writer.endObjectPlacement(continuation);
writer.recordObjectPlacement(continuation);
}
if (golden) {
IrisLogging.debug("Goldendebug procedural result: chunk=" + x + "," + z
@@ -791,6 +791,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
}
} catch (Throwable e) {
GenerationFailures.skipPlacement(e, "procedural object", p.getName(), x << 4, -1, z << 4, scope);
} finally {
writer.endObjectPlacement();
}
}
}
@@ -995,7 +997,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
}
try {
String marker = placementMarker(v, id, "surface");
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
int continuation = writer.beginObjectPlacement(effectivePlacement.waterRule());
int result = v.place(xx, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
if (marker != null) {
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
@@ -1009,7 +1011,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
}, null, getData());
if (result >= 0) {
writer.endObjectPlacement(continuation);
writer.recordObjectPlacement(continuation);
placed++;
} else {
rejected++;
@@ -1037,6 +1039,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
} catch (Throwable e) {
GenerationFailures.skipPlacement(e, "object", v.getLoadKey(), chunkX << 4, -1, chunkZ << 4, scope);
errors++;
} finally {
writer.endObjectPlacement();
}
}
@@ -1173,7 +1177,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
IrisObjectPlacement effectivePlacement = resolveCavePlacement(objectPlacement, object, caveProfile);
try {
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
int continuation = writer.beginObjectPlacement(effectivePlacement.waterRule());
ContainedPlacementResult contained = placeContainedCaveObject(
writer,
object,
@@ -1191,7 +1195,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
int result = contained.resultY();
boolean wroteBlocks = contained.commitResult() == CaveObjectPlacementTransaction.CommitResult.COMMITTED;
if (wroteBlocks) {
writer.endObjectPlacement(continuation);
writer.recordObjectPlacement(continuation);
placed++;
} else {
rejected++;
@@ -1252,6 +1256,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
y,
e
);
} finally {
writer.endObjectPlacement();
}
}
@@ -1356,21 +1362,25 @@ public class MantleObjectComponent extends IrisMantleComponent {
}
boolean treePlacement = isTreePlacement(v, objectPlacement);
String marker = placementMarker(v, id, "upper");
int continuation = writer.beginObjectPlacement(placement.entersWater());
int result = v.place(xx, anchorY, zz, writer, placement, rng, (b, data) -> {
if (marker != null) {
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
int continuation = writer.beginObjectPlacement(placement.waterRule());
int result;
try {
result = v.place(xx, anchorY, zz, writer, placement, rng, (b, data) -> {
if (marker != null) {
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
}
if (treePlacement && marker != null) {
writeTreeMaterial(writer, b.getX(), b.getY(), b.getZ(), data);
}
if (placement.isDolphinTarget() && placement.isUnderwater() && B.isStorageChest(data)) {
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
}
}, null, getData());
if (result >= 0) {
writer.recordObjectPlacement(continuation);
}
if (treePlacement && marker != null) {
writeTreeMaterial(writer, b.getX(), b.getY(), b.getZ(), data);
}
if (placement.isDolphinTarget() && placement.isUnderwater() && B.isStorageChest(data)) {
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
}
}, null, getData());
if (result >= 0) {
writer.endObjectPlacement(continuation);
} finally {
writer.endObjectPlacement();
}
if (traceRegen) {
IrisLogging.debug("Upper object placement: chunk=" + chunkX + "," + chunkZ
@@ -20,6 +20,7 @@ package art.arcane.iris.generation.mantle;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.structure.object.ObjectWaterRule;
import art.arcane.iris.world.storage.matter.TileWrapper;
import art.arcane.iris.world.storage.matter.PreObjectMatterCell;
import art.arcane.iris.configuration.IrisSettings;
@@ -221,13 +222,13 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
}
@Override
public int beginObjectPlacement(boolean entersWater) {
objectWater.set(new ObjectWater(ObjectHydrologyVeto.of(getEngine()), entersWater));
public int beginObjectPlacement(ObjectWaterRule rule) {
objectWater.set(new ObjectWater(ObjectHydrologyVeto.of(getEngine()), rule));
return -1;
}
@Override
public void endObjectPlacement(int checkpoint) {
public void endObjectPlacement() {
objectWater.remove();
}
@@ -237,9 +238,9 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
return false;
}
if (value instanceof NativeBlockState state) {
return water.veto().keepsBlock(x, y, z, state, water.entersWater());
return water.veto().keepsBlock(x, y, z, state, water.rule());
}
return value instanceof MatterCavern && water.veto().keeps(x, y, z, false, water.entersWater());
return value instanceof MatterCavern && water.veto().keeps(x, y, z, false, water.rule());
}
private void recordObjectValue(int x, int y, int z, Class<?> type, Object value) {
@@ -1034,7 +1035,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
naturalOpening ? ALWAYS : NEVER, cavern ? ALWAYS : NEVER) ? (byte) 1 : 0;
}
private record ObjectWater(ObjectHydrologyVeto veto, boolean entersWater) {
private record ObjectWater(ObjectHydrologyVeto veto, ObjectWaterRule rule) {
}
public final class ObjectPlacementCapture implements AutoCloseable {
@@ -1,5 +1,6 @@
package art.arcane.iris.generation.mantle;
import art.arcane.iris.structure.object.ObjectWaterRule;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import java.util.Arrays;
@@ -10,6 +11,7 @@ final class MutationLog {
private static final byte CUSTOM = 1;
private static final byte CANOPY = 2;
private static final byte ENTERS_WATER = 4;
private static final byte FORCED = 8;
private int size;
private int[] x = new int[32];
@@ -30,16 +32,16 @@ final class MutationLog {
throw new IllegalArgumentException("Object mutation type " + key.type().getName()
+ " does not match its value " + value.getClass().getName());
}
log.add(key.x(), key.y(), key.z(), value, false, set.canopy(), false);
log.add(key.x(), key.y(), key.z(), value, false, set.canopy(), ObjectWaterRule.KEEP_OUT);
}
case ObjectDestinationTransaction.CustomBlockMutation block -> log.add(key.x(), key.y(), key.z(),
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy(), false);
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy(), ObjectWaterRule.KEEP_OUT);
}
}
return log;
}
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy, boolean entersWater) {
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy, ObjectWaterRule rule) {
if (size == values.length) {
int capacity = size * 2;
x = Arrays.copyOf(x, capacity);
@@ -52,7 +54,7 @@ final class MutationLog {
y[size] = blockY;
z[size] = blockZ;
values[size] = value;
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0) | (entersWater ? ENTERS_WATER : 0));
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0) | (rule == ObjectWaterRule.ENTERS_WATER ? ENTERS_WATER : 0) | (rule == ObjectWaterRule.FORCED ? FORCED : 0));
size++;
}
@@ -84,8 +86,11 @@ final class MutationLog {
return (flags[index] & CANOPY) != 0;
}
boolean entersWater(int index) {
return (flags[index] & ENTERS_WATER) != 0;
ObjectWaterRule waterRule(int index) {
if ((flags[index] & FORCED) != 0) {
return ObjectWaterRule.FORCED;
}
return (flags[index] & ENTERS_WATER) != 0 ? ObjectWaterRule.ENTERS_WATER : ObjectWaterRule.KEEP_OUT;
}
Class<?> type(int index) {
@@ -7,6 +7,7 @@ import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
import art.arcane.iris.generation.block.TileData;
import art.arcane.iris.structure.object.ObjectWaterRule;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import art.arcane.volmlib.util.math.BlockPosition;
import art.arcane.iris.generation.block.B;
@@ -41,7 +42,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
private int subterrainZ;
private boolean subterrainProtects;
private ObjectHydrologyVeto waterVeto;
private boolean waterPlacement;
private ObjectWaterRule waterRule = ObjectWaterRule.KEEP_OUT;
ObjectDestinationTransaction(MantleWriter writer, int destinationChunkX, int destinationChunkZ) {
this.writer = writer;
@@ -73,19 +74,23 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
}
@Override
public int beginObjectPlacement(boolean entersWater) {
waterPlacement = entersWater;
public int beginObjectPlacement(ObjectWaterRule rule) {
waterRule = rule;
return log.size();
}
@Override
public void endObjectPlacement(int checkpoint) {
waterPlacement = false;
public void recordObjectPlacement(int checkpoint) {
if (checkpoint >= 0 && checkpoint < log.size()) {
placements.add(new PlacementRange(checkpoint, log.size()));
}
}
@Override
public void endObjectPlacement() {
waterRule = ObjectWaterRule.KEEP_OUT;
}
void apply(ObjectSourcePlan plan) {
int slot = plan.destinationSlot(destinationChunkX, destinationChunkZ);
if (slot < 0) {
@@ -103,7 +108,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
Object value = plan.valueAt(index);
boolean custom = ObjectSourcePlan.isCustom(cell);
boolean canopy = ObjectSourcePlan.isCanopy(cell);
boolean entersWater = ObjectSourcePlan.entersWater(cell);
ObjectWaterRule rule = ObjectSourcePlan.waterRule(cell);
if (custom || value instanceof NativeBlockState) {
NativeBlockState existing = canopy ? get(x, y, z) : null;
skipCanopy = existing != null && existing.isSolid();
@@ -112,9 +117,9 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
continue;
}
if (custom) {
set(x, y, z, (NativeBlockState) value, canopy, entersWater);
set(x, y, z, (NativeBlockState) value, canopy, rule);
} else {
setData(x, y, z, value, canopy, entersWater);
setData(x, y, z, value, canopy, rule);
}
}
}
@@ -179,17 +184,17 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
@Override
public void set(int x, int y, int z, NativeBlockState state) {
set(x, y, z, state, isCanopy(x, y, z), waterPlacement);
set(x, y, z, state, isCanopy(x, y, z), waterRule);
}
private void set(int x, int y, int z, NativeBlockState state, boolean canopy, boolean entersWater) {
private void set(int x, int y, int z, NativeBlockState state, boolean canopy, ObjectWaterRule rule) {
if (state == null) {
return;
}
String placementKey = state.deferredPlacementKey();
NativeBlockState baseState = state.placementBaseState();
if (state.isCustom() && placementKey != null && baseState != null) {
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid(), entersWater)) {
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid(), rule)) {
return;
}
Identifier identifier = Identifier.fromString(placementKey);
@@ -197,10 +202,10 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
cell.block = baseState;
cell.tile = CLEARED;
cell.identifier = identifier;
log.add(x, y, z, state, true, canopy, entersWater);
log.add(x, y, z, state, true, canopy, rule);
return;
}
setData(x, y, z, state, canopy, entersWater);
setData(x, y, z, state, canopy, rule);
}
@Override
@@ -291,18 +296,18 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
@Override
public <T> void setData(int x, int y, int z, T data) {
setData(x, y, z, data, isCanopy(x, y, z), waterPlacement);
setData(x, y, z, data, isCanopy(x, y, z), waterRule);
}
private void setData(int x, int y, int z, Object data, boolean canopy, boolean entersWater) {
private void setData(int x, int y, int z, Object data, boolean canopy, ObjectWaterRule rule) {
if (data == null || y < 0 || y >= worldHeight
|| protectsSubterrain(x, y, z)) {
return;
}
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid(), entersWater))) {
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid(), rule))) {
return;
}
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false, entersWater))) {
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false, rule))) {
return;
}
Class<?> type = data instanceof NativeBlockState ? NativeBlockState.class : data.getClass();
@@ -314,7 +319,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
} else {
cell.put(type, data);
}
log.add(x, y, z, data, false, canopy, entersWater);
log.add(x, y, z, data, false, canopy, rule);
}
@Override
@@ -411,11 +416,11 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
&& !protectsSubterrain(x, y, z);
}
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, boolean entersWater) {
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, ObjectWaterRule rule) {
if (waterVeto == null) {
waterVeto = ObjectHydrologyVeto.of(getEngine());
}
return waterVeto.keeps(x, y, z, solid, entersWater);
return waterVeto.keeps(x, y, z, solid, rule);
}
private boolean protectsSubterrain(int x, int y, int z) {
@@ -5,6 +5,7 @@ import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.structure.object.ObjectWaterRule;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
final class ObjectHydrologyVeto {
@@ -25,13 +26,13 @@ final class ObjectHydrologyVeto {
return runtime != null && runtime.enabled() ? new ObjectHydrologyVeto(complex, runtime) : NONE;
}
boolean keepsBlock(int x, int y, int z, NativeBlockState state, boolean entersWater) {
boolean keepsBlock(int x, int y, int z, NativeBlockState state, ObjectWaterRule rule) {
NativeBlockState base = state.isCustom() && state.placementBaseState() != null ? state.placementBaseState() : state;
return keeps(x, y, z, base.isSolid(), entersWater);
return keeps(x, y, z, base.isSolid(), rule);
}
boolean keeps(int x, int y, int z, boolean solid, boolean entersWater) {
if (runtime == null) {
boolean keeps(int x, int y, int z, boolean solid, ObjectWaterRule rule) {
if (runtime == null || rule == ObjectWaterRule.FORCED) {
return false;
}
ChunkWaterRaster raster = runtime.raster(x >> 4, z >> 4);
@@ -42,7 +43,7 @@ final class ObjectHydrologyVeto {
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= complex.naturalTrueHeight(x, z)) {
return true;
}
if (solid && !entersWater && fillsWater(x, y, z)) {
if (solid && rule != ObjectWaterRule.ENTERS_WATER && fillsWater(x, y, z)) {
return true;
}
if (role.wet()) {
@@ -1,6 +1,7 @@
package art.arcane.iris.generation.mantle;
import art.arcane.iris.structure.object.IObjectPlacer;
import art.arcane.iris.structure.object.ObjectWaterRule;
import org.jetbrains.annotations.Nullable;
public interface ObjectPassPlacer extends IObjectPlacer {
@@ -8,11 +9,14 @@ public interface ObjectPassPlacer extends IObjectPlacer {
byte[] getCarvedColumn(int x, int z, int height);
default int beginObjectPlacement(boolean entersWater) {
default int beginObjectPlacement(ObjectWaterRule rule) {
return -1;
}
default void endObjectPlacement(int checkpoint) {
default void recordObjectPlacement(int checkpoint) {
}
default void endObjectPlacement() {
}
@Override
@@ -3,6 +3,7 @@ package art.arcane.iris.generation.mantle;
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.integration.Identifier;
import art.arcane.iris.structure.object.ObjectWaterRule;
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
import art.arcane.iris.world.storage.matter.TileWrapper;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
@@ -33,7 +34,8 @@ final class ObjectSourcePlan {
private static final int CUSTOM_BIT = 1 << 8;
private static final int CANOPY_BIT = 1 << 9;
private static final int ENTERS_WATER_BIT = 1 << 10;
private static final int Y_SHIFT = 11;
private static final int FORCED_BIT = 1 << 11;
private static final int Y_SHIFT = 12;
private static final int MAXIMUM_Y = (1 << (31 - Y_SHIFT)) - 1;
private final long[] destinations;
@@ -91,7 +93,7 @@ final class ObjectSourcePlan {
throw new IllegalArgumentException("Object mutation height is outside the plan range: " + y);
}
cells[position] = (y << Y_SHIFT) | (log.custom(logged) ? CUSTOM_BIT : 0) | (log.canopy(logged) ? CANOPY_BIT : 0)
| (log.entersWater(logged) ? ENTERS_WATER_BIT : 0) | ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
| waterBits(log.waterRule(logged)) | ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
valueIndexes[position] = table.indexOf(log.value(logged));
}
values = table.values.toArray();
@@ -242,8 +244,19 @@ final class ObjectSourcePlan {
return (cell & CANOPY_BIT) != 0;
}
static boolean entersWater(int cell) {
return (cell & ENTERS_WATER_BIT) != 0;
static ObjectWaterRule waterRule(int cell) {
if ((cell & FORCED_BIT) != 0) {
return ObjectWaterRule.FORCED;
}
return (cell & ENTERS_WATER_BIT) != 0 ? ObjectWaterRule.ENTERS_WATER : ObjectWaterRule.KEEP_OUT;
}
private static int waterBits(ObjectWaterRule rule) {
return switch (rule) {
case KEEP_OUT -> 0;
case ENTERS_WATER -> ENTERS_WATER_BIT;
case FORCED -> FORCED_BIT;
};
}
ObjectDestinationTransaction.Mutation mutationAt(int chunkX, int chunkZ, int index) {
@@ -1,8 +1,10 @@
package art.arcane.iris.pack;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.block.IrisBlockData;
import art.arcane.iris.generation.decoration.HydrologyVegetation;
import art.arcane.iris.generation.decoration.IrisDecorator;
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
@@ -10,30 +12,45 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrologyWetness;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
import art.arcane.iris.generation.terrain.IrisRegion;
import art.arcane.iris.generation.terrain.ShoreBiomeLineages;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.pack.loading.IrisRegistrant;
import art.arcane.iris.pack.schema.annotation.Snippet;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.volmlib.util.json.JSONArray;
import art.arcane.volmlib.util.json.JSONObject;
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
final class PackHydrologyValidator {
private static final String CONFIG = "hydrology";
private static final String POLICY = "hydrologyPolicy";
private static final String DEFAULT_FLUID = "water";
private static final String SNIPPET_ROOT = "snippet/";
private static final List<RangeField> RANGES = List.of(
new RangeField("ponds.freeboard", Floor.NON_NEGATIVE, true),
new RangeField("ponds.seeded.radius", Floor.POSITIVE, true),
@@ -51,6 +68,7 @@ final class PackHydrologyValidator {
);
private static final List<String> FLUID_REFERENCES = List.of("ponds.fluid", "underground.cavePools.fluid");
private static final IrisHydrologyTier DEFAULT_TIER = new IrisHydrologyTier();
private static final Set<String> WATER_BLOCKS = Set.of("minecraft:water");
private static final String MANTLE_WATER = "the falling water at waterfalls and cascades and cave pools";
private PackHydrologyValidator() {
@@ -90,6 +108,7 @@ final class PackHydrologyValidator {
errors.add(path + " must be an object.");
return data;
}
warnUnknownKeys(path, hydrology, IrisHydrology.class, packFolder, findings.warnings());
if (!hydrology.optBoolean("enabled", false)) {
return data;
}
@@ -105,14 +124,107 @@ final class PackHydrologyValidator {
return loaded;
}
warnMantleOff("Dimension '" + dimensionKey + "'", loadedDimension, findings.warnings());
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), errors);
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), errors, findings.warnings());
warnShoreBiomesWithoutWidth(dimensionKey, loaded, loadedDimension, findings.warnings());
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
warnFluidsWithoutSeam(dimensionKey, loaded, loadedDimension, findings.warnings());
}
return loaded;
}
static void warnUnknownKeys(String field, Object value, Type type, File packFolder, List<String> warnings) {
warnUnknownKeys(field, value, type, new KeyScan(packFolder, warnings, new HashSet<>()));
}
private static void warnUnknownKeys(String field, Object value, Type type, KeyScan scan) {
Class<?> raw = TypeToken.get(type).getRawType();
if (value instanceof JSONArray array) {
Type element = elementType(type, raw);
for (int index = 0; index < array.length(); index++) {
warnUnknownKeys(field + "[" + index + "]", array.opt(index), element, scan);
}
} else if (value instanceof JSONObject object) {
if (Map.class.isAssignableFrom(raw)) {
Type entry = typeArgument(type, 1);
for (String key : new TreeSet<>(object.keySet())) {
warnUnknownKeys(field + "." + key, object.opt(key), entry, scan);
}
} else if (hasDeclaredKeys(raw)) {
warnUnknownFields(field, object, raw, scan);
}
} else if (value instanceof String reference && reference.startsWith(SNIPPET_ROOT) && raw.isAnnotationPresent(Snippet.class)) {
warnUnknownSnippetKeys(field, reference, raw, scan);
}
}
private static void warnUnknownFields(String field, JSONObject object, Class<?> type, KeyScan scan) {
Map<String, Type> declared = declaredKeys(type);
for (String key : new TreeSet<>(object.keySet())) {
String child = field + "." + key;
Type declaredType = declared.get(key);
if (declaredType == null) {
scan.warnings().add(child + " is not a known key, so its value is ignored. Known keys there: " + declared.keySet() + ".");
} else {
warnUnknownKeys(child, object.opt(key), declaredType, scan);
}
}
}
private static void warnUnknownSnippetKeys(String field, String reference, Class<?> type, KeyScan scan) {
String base = SNIPPET_ROOT + type.getDeclaredAnnotation(Snippet.class).value() + "/";
String snippet = reference.startsWith(base) ? reference : base + reference.substring(SNIPPET_ROOT.length());
if (!scan.activeSnippets().add(snippet)) {
return;
}
File file = new File(scan.packFolder(), snippet + ".json");
JSONObject object = file.isFile() ? PackValidationIo.readJson(file) : null;
if (object != null) {
warnUnknownFields(field + " (" + snippet + ")", object, type, scan);
}
scan.activeSnippets().remove(snippet);
}
private static Type elementType(Type type, Class<?> raw) {
if (raw.isArray()) {
return raw.getComponentType();
}
return Collection.class.isAssignableFrom(raw) ? typeArgument(type, 0) : Object.class;
}
private static Type typeArgument(Type type, int index) {
if (type instanceof ParameterizedType parameterized && index < parameterized.getActualTypeArguments().length) {
return parameterized.getActualTypeArguments()[index];
}
return Object.class;
}
private static boolean hasDeclaredKeys(Class<?> type) {
return !type.isPrimitive() && !type.isEnum() && !type.isArray() && !type.isInterface()
&& !Modifier.isAbstract(type.getModifiers()) && !Collection.class.isAssignableFrom(type)
&& !type.getPackageName().startsWith("java.");
}
private static Map<String, Type> declaredKeys(Class<?> type) {
Map<String, Type> keys = new TreeMap<>();
for (Class<?> current = type; current != null && current != Object.class; current = current.getSuperclass()) {
for (Field field : current.getDeclaredFields()) {
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || field.isSynthetic()) {
continue;
}
SerializedName serialized = field.getAnnotation(SerializedName.class);
keys.putIfAbsent(serialized == null ? field.getName() : serialized.value(), field.getGenericType());
if (serialized != null) {
for (String alternate : serialized.alternate()) {
keys.putIfAbsent(alternate, field.getGenericType());
}
}
}
}
return keys;
}
private static boolean validateCompile(String path, IrisDimension dimension, List<String> errors) {
try {
HydrologySettings settings = HydrologySettings.compile(dimension.getHydrology(), 0L, dimension.getFluidHeight(), 0,
@@ -278,12 +390,14 @@ final class PackHydrologyValidator {
}
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, PolicyFluids fluids,
List<String> errors) {
List<String> errors, List<String> warnings) {
warnUnknownPolicyKeys("Dimension '" + dimensionKey + "'." + POLICY, dimension, data, warnings);
validatePolicy("Dimension '" + dimensionKey + "'." + POLICY, dimension.getHydrologyPolicy(), data, fluids, path, errors);
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
regions.sort(Comparator.comparing(IrisRegion::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
for (IrisRegion region : regions) {
if (region != null) {
warnUnknownPolicyKeys("Region '" + region.getLoadKey() + "'." + POLICY, region, data, warnings);
validatePolicy("Region '" + region.getLoadKey() + "'." + POLICY, region.getHydrologyPolicy(), data, fluids, path, errors);
}
}
@@ -291,11 +405,20 @@ final class PackHydrologyValidator {
biomes.sort(Comparator.comparing(IrisBiome::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
for (IrisBiome biome : biomes) {
if (biome != null) {
warnUnknownPolicyKeys("Biome '" + biome.getLoadKey() + "'." + POLICY, biome, data, warnings);
validatePolicy("Biome '" + biome.getLoadKey() + "'." + POLICY, biome.getHydrologyPolicy(), data, fluids, path, errors);
}
}
}
private static void warnUnknownPolicyKeys(String field, IrisRegistrant owner, IrisData data, List<String> warnings) {
File file = owner.getLoadFile();
JSONObject json = file == null ? null : PackValidationIo.readJson(file);
if (json != null) {
warnUnknownKeys(field, json.opt(POLICY), IrisHydrologyPolicy.class, data.getDataFolder(), warnings);
}
}
private static void validatePolicy(String field, IrisHydrologyPolicy policy, IrisData data, PolicyFluids fluids, String configPath,
List<String> errors) {
if (policy == null) {
@@ -359,6 +482,90 @@ final class PackHydrologyValidator {
}
}
private static void warnFluidsWithoutSeam(String dimensionKey, IrisData data, IrisDimension dimension, List<String> warnings) {
String path = "Dimension '" + dimensionKey + "'." + CONFIG;
Map<String, IrisFluidProfile> profiles = new HashMap<>();
for (IrisFluidProfile profile : dimension.getHydrology().getFluids()) {
profiles.put(profile.getName(), profile);
}
Map<String, Set<String>> rivers = riverFluidSources(dimensionKey, data, dimension);
rivers.keySet().retainAll(profiles.keySet());
for (Map.Entry<String, Set<String>> river : rivers.entrySet()) {
IrisFluidProfile profile = profiles.get(river.getKey());
Set<String> blocks = blockIds(profile.getPalette());
if (hasSeam(profile) || blocks.equals(WATER_BLOCKS)) {
continue;
}
List<String> met = new ArrayList<>();
if (dimension.getFluidHeight() > 0 && !blocks.equals(blockIds(dimension.getFluidPalette()))) {
met.add("the sea");
}
for (String other : rivers.keySet()) {
IrisFluidProfile otherProfile = profiles.get(other);
if (!hasSeam(otherProfile) && !blocks.equals(blockIds(otherProfile.getPalette()))) {
met.add("fluid '" + other + "'");
}
}
if (!met.isEmpty()) {
warnings.add(path + ".fluids profile '" + river.getKey() + "' sets no seam, so where its rivers meet " + String.join(" or ", met)
+ " the fluids lie side by side. Set seam on the profile to line that edge. Its rivers come from "
+ String.join(", ", river.getValue()) + ".");
}
}
}
private static Map<String, Set<String>> riverFluidSources(String dimensionKey, IrisData data, IrisDimension dimension) {
Map<String, Set<String>> sources = new TreeMap<>();
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
ShoreBiomeLineages.visit(dimension, regions, () -> data, (lineage, region) -> {
String fluid = IrisHydrologyPolicy.inherited(lineage, region, dimension, IrisHydrologyPolicy::getFluid);
if (fluid == null) {
addTierSources(dimensionKey, dimension, sources);
} else {
sources.computeIfAbsent(fluid, name -> new TreeSet<>()).add(policyFluidOwner(dimensionKey, lineage, region));
}
});
if (sources.isEmpty()) {
addTierSources(dimensionKey, dimension, sources);
}
return sources;
}
private static void addTierSources(String dimensionKey, IrisDimension dimension, Map<String, Set<String>> sources) {
List<IrisHydrologyTier> tiers = dimension.getHydrology().getTiers();
for (int index = 0; index < tiers.size(); index++) {
sources.computeIfAbsent(tiers.get(index).getFluid(), name -> new TreeSet<>())
.add("Dimension '" + dimensionKey + "'." + CONFIG + ".tiers[" + index + "].fluid");
}
}
private static String policyFluidOwner(String dimensionKey, List<IrisBiome> lineage, IrisRegion region) {
for (IrisBiome biome : lineage) {
if (biome.getHydrologyPolicy() != null && biome.getHydrologyPolicy().getFluid() != null) {
return "Biome '" + biome.getLoadKey() + "'." + POLICY + ".fluid";
}
}
if (region != null && region.getHydrologyPolicy() != null && region.getHydrologyPolicy().getFluid() != null) {
return "Region '" + region.getLoadKey() + "'." + POLICY + ".fluid";
}
return "Dimension '" + dimensionKey + "'." + POLICY + ".fluid";
}
private static boolean hasSeam(IrisFluidProfile profile) {
return profile.getSeam() != null && !profile.getSeam().isBlank();
}
private static Set<String> blockIds(IrisMaterialPalette palette) {
Set<String> blocks = new TreeSet<>();
for (IrisBlockData block : palette.getPalette()) {
String id = block.getBlock().toLowerCase(Locale.ROOT);
int state = id.indexOf('[');
String name = state < 0 ? id : id.substring(0, state);
blocks.add(name.contains(":") ? name : "minecraft:" + name);
}
return blocks;
}
private static void requireMultiplier(String field, Double value, List<String> errors) {
if (value != null && !IrisHydrologyPolicy.validMultiplier(value)) {
errors.add(field + " must be a finite value from 0 to " + (int) IrisHydrologyPolicy.MAX_MULTIPLIER + ", got " + value + ".");
@@ -414,4 +621,7 @@ final class PackHydrologyValidator {
private record Findings(List<String> errors, List<String> warnings) {
}
private record KeyScan(File packFolder, List<String> warnings, Set<String> activeSnippets) {
}
}
@@ -223,6 +223,7 @@ final class PackStructurePlacementValidator {
path, placement, "maxHeight", Integer.MIN_VALUE, Integer.MAX_VALUE, blockingErrors);
PackJsonFieldChecks.validateOptionalBoolean(path, placement, "underground", blockingErrors);
PackJsonFieldChecks.validateOptionalBoolean(path, placement, "underwater", blockingErrors);
PackJsonFieldChecks.validateOptionalBoolean(path, placement, "allowWater", blockingErrors);
PackJsonFieldChecks.validateOptionalEnum(path, placement, "nativeSuppression",
Set.of("NONE", "REPLACE_SOURCE"), blockingErrors);
@@ -299,6 +300,9 @@ final class PackStructurePlacementValidator {
appendIdentity(identity, integerValue(placement, "maxHeight", 2032));
appendIdentity(identity, placement.opt("underground") instanceof Boolean underground && underground);
appendIdentity(identity, placement.opt("underwater") instanceof Boolean underwater && underwater);
if (placement.opt("allowWater") instanceof Boolean allowWater && allowWater) {
appendIdentity(identity, "allowWater");
}
JSONArray structures = placement.optJSONArray("structures");
JSONArray nativeStructures = placement.optJSONArray("nativeStructures");
if (structures != null && structures.length() > 0) {
@@ -201,7 +201,6 @@ public class IrisObjectPlacement {
@Description("Ignore any placement restrictions for this object")
@SerializedName(value = "forcePlace", alternate = {"force"})
private boolean forcePlace = false;
private transient boolean forcedByStructure = false;
private transient AtomicCache<TableCache> cache = new AtomicCache<>();
private transient AtomicCache<CompatStatus> compatCache = new AtomicCache<>();
@Getter(AccessLevel.NONE)
@@ -307,8 +306,11 @@ public class IrisObjectPlacement {
return place.size() == 1 ? place.getFirst() : place.toString(", ");
}
public boolean entersWater() {
return underwater || onwater || forcePlace && !forcedByStructure;
public ObjectWaterRule waterRule() {
if (forcePlace) {
return ObjectWaterRule.FORCED;
}
return underwater || onwater ? ObjectWaterRule.ENTERS_WATER : ObjectWaterRule.KEEP_OUT;
}
public IrisObjectPlacement toPlacement(String... place) {
@@ -354,7 +356,6 @@ public class IrisObjectPlacement {
p.setAllowedCollisions(allowedCollisions);
p.setForbiddenCollisions(forbiddenCollisions);
p.setForcePlace(forcePlace);
p.setForcedByStructure(forcedByStructure);
return p;
}
@@ -0,0 +1,7 @@
package art.arcane.iris.structure.object;
public enum ObjectWaterRule {
KEEP_OUT,
ENTERS_WATER,
FORCED
}
@@ -56,12 +56,12 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
private static String hydrologyRejection(PlacementContext context, PlacementState state) {
IrisObjectPlacement config = state.config;
if (!context.automatic || !config.getCarvingSupport().supportsSurface()
if (!context.automatic || config.isForcePlace() || !config.getCarvingSupport().supportsSurface()
|| config.getMode() == ObjectPlaceMode.FLOATING || config.getMode() == ObjectPlaceMode.STRUCTURE_PIECE) {
return null;
}
boolean painted = state.paintProjection != null;
if (config.entersWater()) {
if (config.waterRule() == ObjectWaterRule.ENTERS_WATER) {
return (painted
? IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
: IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, config.getTranslate(),
@@ -100,7 +100,7 @@ public class IrisStructure extends IrisRegistrant {
@Description("Whether every open connector must close with a real terminal piece through a mandatory direct fallback.")
private boolean requireCaps = false;
@Description("The place mode used when stamping each piece object into the world.")
@Description("The place mode used when stamping each piece object into the world. A surface structure with a mode other than STRUCTURE_PIECE or FLOATING that assembles to one piece is force placed: it ignores the river limit and the submerged start check and writes through river, pond and sea water.")
private ObjectPlaceMode placeMode = ObjectPlaceMode.STRUCTURE_PIECE;
@ArrayType(min = 1, type = IrisObjectReplace.class)
@@ -524,12 +524,20 @@ public final class IrisStructureLocator {
originZ = anchor.z();
int baseY = anchor.y();
boolean submerged = !placement.resolvedAnchor().isCave() && !placement.isUnderwater()
&& NativeStructurePlacementPlanner.isSubmerged(engine, originX, originZ);
String selectedKey = selectStructureKey(placement, rng);
if (selectedKey == null || selectedKey.isBlank()) {
if (submerged) {
return null;
}
throw new IllegalStateException("Iris structure placement selected a blank structure key");
}
IrisStructure structure = engine.getData().load(IrisStructure.class, selectedKey, false);
if (structure == null) {
if (submerged) {
return null;
}
throw new IllegalStateException("Iris structure placement references missing structure '"
+ selectedKey + "'");
}
@@ -537,15 +545,13 @@ public final class IrisStructureLocator {
// Gated out on this Minecraft version; the pack report already says why.
return null;
}
StructureGraphCompilation compilation = StructureGraphCatalog.compile(engine.getData(), structure);
if (!compilation.isAssemblyViable()) {
throw new IllegalStateException("Iris structure '" + selectedKey
+ "' has no runtime-viable assembly graph");
if (submerged && !placement.forcesPieces(structure, 1)) {
return null;
}
StructureAssemblyResult assembly = assemble(engine, structure, selectedKey, new IrisPosition(originX, baseY, originZ), rng);
if (submerged && !placement.forcesPieces(structure, assembly.pieces().size())) {
return null;
}
StructureAssembler assembler = StructureAssembler.forData(
engine.getData(), structure, new IrisPosition(originX, baseY, originZ));
StructureAssemblyResult assembly = assembler.assemble(rng);
if (!placementOutput(placement, selectedKey, cx, cz,
assembly.hasOutput(), "assembly " + assembly.status(), assembly.detail())) {
return null;
@@ -594,6 +600,7 @@ public final class IrisStructureLocator {
return null;
}
if (!placement.isAnchoredUnderground() && !placement.isAllowWater()
&& !placement.forcesPieces(structure, pieces.size())
&& !StructureWaterRules.admitsFootprint(IrisStructureWater.mantle(engine.getComplex()), pieceFootprints(pieces))) {
return null;
}
@@ -603,6 +610,14 @@ public final class IrisStructureLocator {
return new ResolvedPlacement(placement, selectedKey, structure, pieces, rng, originX, baseY, originZ, exactY);
}
private static StructureAssemblyResult assemble(Engine engine, IrisStructure structure, String key, IrisPosition origin, RNG rng) {
StructureGraphCompilation compilation = StructureGraphCatalog.compile(engine.getData(), structure);
if (!compilation.isAssemblyViable()) {
throw new IllegalStateException("Iris structure '" + key + "' has no runtime-viable assembly graph");
}
return StructureAssembler.forData(engine.getData(), structure, origin).assemble(rng);
}
public static boolean allowsResolvedFootprint(Engine engine, ResolvedPlacement resolved) {
Objects.requireNonNull(resolved, "resolved placement");
return allowsResolvedFootprint(engine, resolved.placement(), resolved.structure(), resolved.pieces());
@@ -682,10 +697,6 @@ public final class IrisStructureLocator {
if (worldMin > worldMax) {
return null;
}
if (!placement.isUnderwater()
&& NativeStructurePlacementPlanner.isSubmerged(engine, originX, originZ)) {
return null;
}
if (placement.resolvedAnchor() == IrisStructureAnchorMode.SURFACE) {
int surfaceY = Engine.hostHeight(engine, originX, originZ, true) + engine.getMinHeight();
return surfaceY < placement.getMinHeight() || surfaceY > placement.getMaxHeight() ? null : surfaceY;
@@ -18,6 +18,7 @@
package art.arcane.iris.structure.placement;
import art.arcane.iris.structure.object.ObjectPlaceMode;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.pack.validation.CompatPools;
import art.arcane.iris.structure.nativegen.IrisNativeStructure;
@@ -127,10 +128,10 @@ public class IrisStructurePlacement {
@Description("Optional foundation columns placed beneath the assembled structure's occupied bottom cells. Columns pass through air and fluids until they reach solid ground, up to maxDepth.")
private IrisStructureStiltSettings stilt = null;
@Description("If false, the placement is skipped when its selected surface or cave column is submerged.")
@Description("If false, the placement is skipped when its selected surface or cave column is submerged. A force placed surface structure, as described on the structure's placeMode, ignores this.")
private boolean underwater = false;
@Description("If true, a surface structure may cover river, stream, pond and lake water, and its pieces and stilts may fill it. If false, a surface placement is skipped when more than 10% of its footprint columns are channel, pond, cascade or waterfall water, and its pieces keep their solid blocks out of the water they touch.")
@Description("If true, a surface structure may cover river, stream, pond and lake water, and its pieces and stilts may fill it. If false, a surface placement is skipped when more than 10% of its footprint columns are channel, pond, cascade or waterfall water, and its pieces keep their solid blocks out of the water they touch. A force placed surface structure, as described on the structure's placeMode, ignores the limit and writes through the water whatever this is set to.")
private boolean allowWater = false;
public IrisStructureTerrain resolvedTerrain() {
@@ -152,6 +153,19 @@ public class IrisStructurePlacement {
return anchor;
}
public ObjectPlaceMode pieceMode(IrisStructure structure, int pieces) {
ObjectPlaceMode mode = structure.getPlaceMode();
if (isAnchoredUnderground()) {
return mode == ObjectPlaceMode.ORGANIC_STILT || mode == ObjectPlaceMode.CEILING_HANG
? mode : ObjectPlaceMode.STRUCTURE_PIECE;
}
return pieces == 1 && mode != ObjectPlaceMode.FLOATING ? mode : ObjectPlaceMode.STRUCTURE_PIECE;
}
public boolean forcesPieces(IrisStructure structure, int pieces) {
return !isAnchoredUnderground() && pieceMode(structure, pieces) != ObjectPlaceMode.STRUCTURE_PIECE;
}
public boolean isAnchoredUnderground() {
IrisStructureAnchorMode activeAnchor = resolvedAnchor();
return activeAnchor == IrisStructureAnchorMode.HEIGHT_BAND || activeAnchor.isCave();