Keep reserved subterrain over transforms

- Let reserved subterrain cells without hydrology answer before a transformed column in every post-transform reader
- Move the transformed override into CarveOwnership.carved so the five readers share one order
- Read the natural opening and the cavern only when hydrology and subterrain leave the cell open
- Cover reserved passages and the reserved-solid transform case in the ownership tests
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 18:15:28 -05:00
1 parent b11ff94737
commit f6fbf9147f
5 files changed
+77 -68

No files matched your search

@@ -2,6 +2,10 @@ package art.arcane.iris.generation.mantle;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.subterrain.SubterrainCell;
import art.arcane.iris.generation.subterrain.SubterrainRasterizer;
import art.arcane.iris.generation.terrain.Terrain3DColumn;
import java.util.function.BooleanSupplier;
public final class CarveOwnership {
private CarveOwnership() {
@@ -17,12 +21,20 @@ public final class CarveOwnership {
return naturalOpening ? Owner.NATURAL_OPENING : Owner.CAVERN;
}
public static boolean carved(HydrologyCaveCell hydrology, SubterrainCell subterrain, boolean naturalOpening, boolean cavern) {
return switch (resolve(hydrology != null, subterrainClaims(subterrain), naturalOpening)) {
public static boolean carved(Terrain3DColumn transformed, int y, HydrologyCaveCell hydrology, SubterrainCell subterrain,
BooleanSupplier naturalOpening, BooleanSupplier cavern) {
if (transformed != null) {
if (hydrology == null && SubterrainRasterizer.protectsPlacement(subterrain)) {
return subterrain.carve();
}
return y >= 0 && y < transformed.topY() && !transformed.isSolid(y);
}
boolean claims = subterrainClaims(subterrain);
return switch (resolve(hydrology != null, claims, hydrology == null && !claims && naturalOpening.getAsBoolean())) {
case HYDROLOGY -> hydrology.carves();
case SUBTERRAIN -> subterrain.carve();
case NATURAL_OPENING -> true;
case CAVERN -> cavern;
case CAVERN -> cavern.getAsBoolean();
};
}
@@ -28,8 +28,6 @@ import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.EngineTarget;
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.generation.terrain.Terrain3DColumn;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveStorage;
import art.arcane.iris.pack.value.IrisPosition;
import art.arcane.iris.generation.block.BoundBlockState;
@@ -123,15 +121,13 @@ public interface EngineMantle extends MatterGenerator {
}
default boolean isCarved(int x, int h, int z) {
Terrain3DColumn transformed = getComplex().transformedColumn(x, z);
if (transformed != null) {
return h >= 0 && h < transformed.topY() && !transformed.isSolid(h);
}
return CarveOwnership.carved(
getComplex().transformedColumn(x, z),
h,
HydrologyCaveStorage.getIfPresent(getMantle(), x, h, z),
getEngine().getSubterrainCell(x, h, z),
getComplex().isTerrain3DOpening(x, h, z),
getMantle().get(x, h, z, MatterCavern.class) != null
() -> getComplex().isTerrain3DOpening(x, h, z),
() -> getMantle().get(x, h, z, MatterCavern.class) != null
);
}
@@ -54,6 +54,7 @@ import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import art.arcane.iris.generation.block.B;
import java.util.LinkedHashMap;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@@ -67,6 +68,8 @@ import static art.arcane.iris.generation.mantle.EngineMantle.AIR;
@Data
public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
private static final int OBJECT_COMPONENT_PRIORITY = 2;
private static final BooleanSupplier ALWAYS = () -> true;
private static final BooleanSupplier NEVER = () -> false;
private final EngineMantle engineMantle;
private final Mantle<Matter> mantle;
@@ -460,30 +463,25 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
}
public boolean isPrerequisiteCarved(int x, int y, int z) {
Terrain3DColumn transformed = engineMantle.getComplex().transformedColumn(x, z);
if (transformed != null) {
return y >= 0 && y < transformed.topY() && !transformed.isSolid(y);
}
return CarveOwnership.carved(
engineMantle.getComplex().transformedColumn(x, z),
y,
getPrerequisiteDataIfPresent(x, y, z, HydrologyCaveCell.class),
getEngine().getSubterrainCell(x, y, z),
engineMantle.getComplex().isTerrain3DOpening(x, y, z),
getPrerequisiteDataIfPresent(x, y, z, MatterCavern.class) != null
() -> engineMantle.getComplex().isTerrain3DOpening(x, y, z),
() -> getPrerequisiteDataIfPresent(x, y, z, MatterCavern.class) != null
);
}
public byte[] getPrerequisiteCarvedColumn(int x, int z, int height) {
int cappedHeight = Math.min(Math.max(height, 0), mantle.getWorldHeight());
Terrain3DColumn transformed = engineMantle.getComplex().transformedColumn(x, z);
if (transformed != null) {
return carvedColumn(transformed, cappedHeight);
}
byte[] carvedColumn = new byte[cappedHeight];
if (cappedHeight <= 0) {
return carvedColumn;
}
Terrain3DColumn terrainColumn = engineMantle.getComplex().terrainColumn(x, z);
Terrain3DColumn transformed = engineMantle.getComplex().transformedColumn(x, z);
Terrain3DColumn terrainColumn = transformed == null ? engineMantle.getComplex().terrainColumn(x, z) : null;
if (terrainColumn != null) {
int maximumY = Math.min(cappedHeight, terrainColumn.topY());
for (int y = Math.max(0, terrainColumn.minY()); y < maximumY; y++) {
@@ -498,7 +496,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
SubterrainCell[] subterrain = subterrainColumn(x, z, cappedHeight);
if (chunk == null) {
for (int y = 0; y < cappedHeight; y++) {
carvedColumn[y] = carvedByte(null, subterrain, y, carvedColumn[y] != 0, false);
carvedColumn[y] = carvedByte(transformed, y, null, subterrain, carvedColumn[y] != 0, false);
}
return carvedColumn;
}
@@ -526,7 +524,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
MatterCavern cavern = cell != null && cell.cavernCaptured()
? cell.cavern()
: cavernSlice == null ? null : cavernSlice.get(x & 15, localY, z & 15);
carvedColumn[y] = carvedByte(hydrology, subterrain, y, carvedColumn[y] != 0, cavern != null);
carvedColumn[y] = carvedByte(transformed, y, hydrology, subterrain, carvedColumn[y] != 0, cavern != null);
}
}
return carvedColumn;
@@ -808,31 +806,26 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
@Override
public boolean isCarved(int x, int y, int z) {
Terrain3DColumn transformed = engineMantle.getComplex().transformedColumn(x, z);
if (transformed != null) {
return y >= 0 && y < transformed.topY() && !transformed.isSolid(y);
}
return CarveOwnership.carved(
engineMantle.getComplex().transformedColumn(x, z),
y,
getDataIfPresent(x, y, z, HydrologyCaveCell.class),
getEngine().getSubterrainCell(x, y, z),
engineMantle.getComplex().isTerrain3DOpening(x, y, z),
getDataIfPresent(x, y, z, MatterCavern.class) != null
() -> engineMantle.getComplex().isTerrain3DOpening(x, y, z),
() -> getDataIfPresent(x, y, z, MatterCavern.class) != null
);
}
public byte[] getCarvedColumn(int x, int z, int height) {
int cappedHeight = Math.min(Math.max(height, 0), mantle.getWorldHeight());
Terrain3DColumn transformed = engineMantle.getComplex().transformedColumn(x, z);
if (transformed != null) {
return carvedColumn(transformed, cappedHeight);
}
byte[] carvedColumn = new byte[cappedHeight];
if (cappedHeight <= 0) {
return carvedColumn;
}
Terrain3DColumn terrainColumn = engineMantle.getComplex().terrainColumn(x, z);
Terrain3DColumn transformed = engineMantle.getComplex().transformedColumn(x, z);
Terrain3DColumn terrainColumn = transformed == null ? engineMantle.getComplex().terrainColumn(x, z) : null;
if (terrainColumn != null) {
int maximumY = Math.min(cappedHeight, terrainColumn.topY());
for (int y = terrainColumn.minY(); y < maximumY; y++) {
@@ -859,7 +852,7 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
}
HydrologyCaveCell hydrology = hydrologySlice == null ? null : hydrologySlice.get(localX, localY, localZ);
boolean cavern = cavernSlice != null && cavernSlice.get(localX, localY, localZ) != null;
carvedColumn[y] = carvedByte(hydrology, subterrain, y, carvedColumn[y] != 0, cavern);
carvedColumn[y] = carvedByte(transformed, y, hydrology, subterrain, carvedColumn[y] != 0, cavern);
}
return carvedColumn;
}
@@ -1009,21 +1002,10 @@ public class MantleWriter implements ObjectPassPlacer, AutoCloseable {
return cells;
}
private static byte carvedByte(HydrologyCaveCell hydrology, SubterrainCell[] subterrain, int y, boolean naturalOpening,
boolean cavern) {
return CarveOwnership.carved(hydrology, subterrain == null ? null : subterrain[y], naturalOpening, cavern)
? (byte) 1 : 0;
}
private static byte[] carvedColumn(Terrain3DColumn terrain, int height) {
byte[] result = new byte[height];
int maximumY = Math.min(height, terrain.topY());
for (int y = 0; y < maximumY; y++) {
if (!terrain.isSolid(y)) {
result[y] = 1;
}
}
return result;
private static byte carvedByte(Terrain3DColumn transformed, int y, HydrologyCaveCell hydrology, SubterrainCell[] subterrain,
boolean naturalOpening, boolean cavern) {
return CarveOwnership.carved(transformed, y, hydrology, subterrain == null ? null : subterrain[y],
naturalOpening ? ALWAYS : NEVER, cavern ? ALWAYS : NEVER) ? (byte) 1 : 0;
}
public final class ObjectPlacementCapture implements AutoCloseable {
@@ -37,12 +37,13 @@ public class CarveOwnershipTest {
private static final int Y = 2;
private static final int Z = 3;
private static final int HEIGHT = 64;
private static final SubterrainCell OPEN_ROOM = new SubterrainCell(SubterrainCell.Kind.AIR, "", room(false));
private static final SubterrainCell RESERVED_SOLID = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(true));
private static final SubterrainCell SHELL = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(false));
private static final SubterrainCell OPEN_ROOM = new SubterrainCell(SubterrainCell.Kind.AIR, "", room(false, false));
private static final SubterrainCell RESERVED_SOLID = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(false, true));
private static final SubterrainCell RESERVED_PASSAGE = new SubterrainCell(SubterrainCell.Kind.AIR, "", room(true, false));
private static final SubterrainCell SHELL = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(false, false));
private static final HydrologyCaveCell[] HYDROLOGY = {
null, HydrologyCaveCell.of(HydrologyCaveAction.DRY_AIR), HydrologyCaveCell.of(HydrologyCaveAction.SEAL_GUARD)};
private static final SubterrainCell[] SUBTERRAIN = {SubterrainCell.OUTSIDE, OPEN_ROOM, RESERVED_SOLID, SHELL};
private static final SubterrainCell[] SUBTERRAIN = {SubterrainCell.OUTSIDE, OPEN_ROOM, RESERVED_SOLID, RESERVED_PASSAGE, SHELL};
@Rule
public final PlatformBinding platform = PlatformBinding.mockPlatform();
@@ -64,8 +65,9 @@ public class CarveOwnershipTest {
assertFalse(CarveOwnership.subterrainClaims(null));
assertFalse(CarveOwnership.subterrainClaims(SubterrainCell.OUTSIDE));
assertTrue(CarveOwnership.subterrainClaims(OPEN_ROOM));
assertTrue(CarveOwnership.subterrainClaims(new SubterrainCell(SubterrainCell.Kind.WATER, "", room(false))));
assertTrue(CarveOwnership.subterrainClaims(new SubterrainCell(SubterrainCell.Kind.WATER, "", room(false, false))));
assertTrue(CarveOwnership.subterrainClaims(RESERVED_SOLID));
assertTrue(CarveOwnership.subterrainClaims(RESERVED_PASSAGE));
assertFalse(CarveOwnership.subterrainClaims(SHELL));
}
@@ -76,7 +78,8 @@ public class CarveOwnershipTest {
for (SubterrainCell subterrain : SUBTERRAIN) {
for (boolean naturalOpening : new boolean[]{false, true}) {
for (boolean cavern : new boolean[]{false, true}) {
boolean claims = subterrain == OPEN_ROOM || subterrain == RESERVED_SOLID;
boolean claims = subterrain == OPEN_ROOM || subterrain == RESERVED_SOLID
|| subterrain == RESERVED_PASSAGE;
boolean expected = switch (CarveOwnership.resolve(hydrology != null, claims, naturalOpening)) {
case HYDROLOGY -> hydrology.carves();
case SUBTERRAIN -> subterrain.carve();
@@ -96,17 +99,19 @@ public class CarveOwnershipTest {
}
@Test
public void transformedColumnsOverrideEveryPostTransformReader() {
public void transformedColumnsYieldOnlyToReservedSubterrainOutsideHydrology() {
List<String> disagreements = new ArrayList<>();
for (boolean transformedOpen : new boolean[]{false, true}) {
for (HydrologyCaveCell hydrology : HYDROLOGY) {
for (SubterrainCell subterrain : SUBTERRAIN) {
for (boolean cavern : new boolean[]{false, true}) {
boolean reserved = subterrain == RESERVED_SOLID || subterrain == RESERVED_PASSAGE;
boolean expected = hydrology == null && reserved ? subterrain.carve() : transformedOpen;
Sources sources = Sources.mocked(hydrology, subterrain, false, cavern, column(transformedOpen));
String state = "transformedOpen=" + transformedOpen
+ " hydrology=" + (hydrology == null ? "none" : hydrology.action())
+ " subterrain=" + describe(subterrain) + " cavern=" + cavern;
compare(disagreements, state, transformedOpen, readers(sources));
compare(disagreements, state, expected, readers(sources));
}
}
}
@@ -120,6 +125,15 @@ public class CarveOwnershipTest {
disagreements.add(state + ": " + reader.getKey() + " gives " + reader.getValue() + ", the rule gives " + expected);
}
}
agree(disagreements, state, readers, "MantleWriter.isCarved", "MantleWriter.getCarvedColumn");
agree(disagreements, state, readers, "MantleWriter.isPrerequisiteCarved", "MantleWriter.getPrerequisiteCarvedColumn");
}
private static void agree(List<String> disagreements, String state, Map<String, Boolean> readers, String point, String column) {
if (!readers.get(point).equals(readers.get(column))) {
disagreements.add(state + ": " + point + " gives " + readers.get(point) + " but " + column + " gives "
+ readers.get(column));
}
}
private static Map<String, Boolean> readers(Sources sources) {
@@ -140,12 +154,15 @@ public class CarveOwnershipTest {
if (subterrain == RESERVED_SOLID) {
return "reserved-solid";
}
if (subterrain == RESERVED_PASSAGE) {
return "reserved-passage";
}
return subterrain == SHELL ? "shell" : "outside";
}
private static SubterrainRoom room(boolean reservedSolid) {
private static SubterrainRoom room(boolean reservedPassage, boolean reservedSolid) {
return new SubterrainRoom("room", "", IrisSubterrainFamily.CENOTE,
0, 0, 0, 0, 0, 0, -10, 10, 1D, 0, false, reservedSolid, SubterrainCell.Kind.AIR);
0, 0, 0, 0, 0, 0, -10, 10, 1D, 0, reservedPassage, reservedSolid, SubterrainCell.Kind.AIR);
}
private static Terrain3DColumn column(boolean openAtY) {
@@ -20,25 +20,27 @@ public class IrisCarveModifierOwnershipTest {
@Test
public void carveOwnerAgreesOnTheNaturalLayer() {
SubterrainCell openRoom = new SubterrainCell(SubterrainCell.Kind.AIR, "", room(false));
SubterrainCell reservedSolid = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(true));
SubterrainCell shell = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(false));
SubterrainCell openRoom = new SubterrainCell(SubterrainCell.Kind.AIR, "", room(false, false));
SubterrainCell reservedSolid = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(false, true));
SubterrainCell reservedPassage = new SubterrainCell(SubterrainCell.Kind.AIR, "", room(true, false));
SubterrainCell shell = new SubterrainCell(SubterrainCell.Kind.SOLID, "", room(false, false));
Terrain3DColumn openTerrain = column(true);
HydrologyCaveCell[] hydrologyCells = {
null, HydrologyCaveCell.of(HydrologyCaveAction.DRY_AIR), HydrologyCaveCell.of(HydrologyCaveAction.SEAL_GUARD)};
SubterrainCell[] subterrainCells = {SubterrainCell.OUTSIDE, openRoom, reservedSolid, shell};
SubterrainCell[] subterrainCells = {SubterrainCell.OUTSIDE, openRoom, reservedSolid, reservedPassage, shell};
Terrain3DColumn[] terrainColumns = {null, column(false), openTerrain};
List<String> disagreements = new ArrayList<>();
for (HydrologyCaveCell hydrology : hydrologyCells) {
for (SubterrainCell subterrain : subterrainCells) {
for (Terrain3DColumn terrain : terrainColumns) {
boolean claims = subterrain == openRoom || subterrain == reservedSolid;
boolean claims = subterrain == openRoom || subterrain == reservedSolid || subterrain == reservedPassage;
CarveOwnership.Owner expected = CarveOwnership.resolve(hydrology != null, claims, terrain == openTerrain);
CarveOwnership.Owner actual = IrisCarveModifier.carveOwner(hydrology, subterrain, terrain, Y);
if (actual != expected) {
disagreements.add("hydrology=" + (hydrology == null ? "none" : hydrology.action())
+ " subterrain=" + subterrain.kind() + " reservedSolid="
+ (subterrain.room() != null && subterrain.room().reservedSolid())
+ " reservedPassage=" + (subterrain.room() != null && subterrain.room().reservedPassage())
+ " terrain=" + (terrain == null ? "none" : terrain == openTerrain ? "open" : "solid")
+ ": carveOwner gives " + actual + ", the rule gives " + expected);
}
@@ -48,9 +50,9 @@ public class IrisCarveModifierOwnershipTest {
assertTrue(String.join("\n", disagreements), disagreements.isEmpty());
}
private static SubterrainRoom room(boolean reservedSolid) {
private static SubterrainRoom room(boolean reservedPassage, boolean reservedSolid) {
return new SubterrainRoom("room", "", IrisSubterrainFamily.CENOTE,
0, 0, 0, 0, 0, 0, -10, 10, 1D, 0, false, reservedSolid, SubterrainCell.Kind.AIR);
0, 0, 0, 0, 0, 0, -10, 10, 1D, 0, reservedPassage, reservedSolid, SubterrainCell.Kind.AIR);
}
private static Terrain3DColumn column(boolean openAtY) {