Narrow force place scope

- Stop treating underground ORGANIC_STILT and CEILING_HANG pieces as forced, so they keep the veto and submerged check
- Return null for broken references on a submerged start, as before force place
- State force placement in the placeMode, underwater and allowWater descriptions and recapture the schema digest
- Pin static objects writing every block over planned river and pond water
- Add tests for forced pieces on open sea, unforced multi-piece starts on sea columns and underground pieces in water
This commit is contained in:
Brian Fopiano committed 2026-11-02 19:51:52 -05:00
1 parent b2255d6bf9
commit bad795f9a7
8 files changed
+239 -39

No files matched your search

@@ -166,14 +166,13 @@ public class IrisStructureComponent extends IrisMantleComponent {
stilt != null && stilt.isSupportNonOccluding());
ObjectPlaceMode mode = placement.pieceMode(structure, pieces.size());
boolean forced = placement.forcesPieces(structure, pieces.size());
boolean sampledHeight = forced && !placement.isAnchoredUnderground();
ObjectWaterRule rule = forced ? ObjectWaterRule.FORCED
: placement.isAllowWater() ? ObjectWaterRule.ENTERS_WATER : ObjectWaterRule.KEEP_OUT;
int failedPieces = 0;
writer.beginObjectPlacement(rule);
try {
for (PlacedStructurePiece p : pieces) {
if (placeObject(writer, run, p, mode, sampledHeight) == -1) {
if (placeObject(writer, run, p, mode, forced) == -1) {
failedPieces++;
}
}
@@ -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)
@@ -41,6 +41,8 @@ import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.structure.nativegen.IrisNativeStructure;
import art.arcane.iris.pack.value.IrisPosition;
import art.arcane.iris.generation.terrain.IrisRegion;
import art.arcane.iris.generation.runtime.GenerationFailures;
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
import art.arcane.iris.structure.nativegen.NativeStructureSuppression;
import art.arcane.iris.structure.object.ObjectPlaceMode;
import art.arcane.iris.structure.object.IrisObjectVacuum;
@@ -523,12 +525,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 + "'");
}
@@ -536,20 +546,19 @@ public final class IrisStructureLocator {
// Gated out on this Minecraft version; the pack report already says why.
return null;
}
boolean submerged = !placement.resolvedAnchor().isCave() && !placement.isUnderwater()
&& NativeStructurePlacementPlanner.isSubmerged(engine, originX, originZ);
if (submerged && !placement.forcesPieces(structure, 1)) {
return null;
}
StructureGraphCompilation compilation = StructureGraphCatalog.compile(engine.getData(), structure);
if (!compilation.isAssemblyViable()) {
throw new IllegalStateException("Iris structure '" + selectedKey
+ "' has no runtime-viable assembly graph");
StructureAssemblyResult assembly;
try {
assembly = assemble(engine, structure, selectedKey, new IrisPosition(originX, baseY, originZ), rng);
} catch (IllegalStateException failure) {
GenerationFailures.rethrowEngineFailure(failure);
if (!submerged || failure instanceof ProvisionalAnswerException) {
throw failure;
}
return null;
}
StructureAssembler assembler = StructureAssembler.forData(
engine.getData(), structure, new IrisPosition(originX, baseY, originZ));
StructureAssemblyResult assembly = assembler.assemble(rng);
if (submerged && !placement.forcesPieces(structure, assembly.pieces().size())) {
return null;
}
@@ -611,6 +620,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());
@@ -128,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() {
@@ -163,7 +163,7 @@ public class IrisStructurePlacement {
}
public boolean forcesPieces(IrisStructure structure, int pieces) {
return pieceMode(structure, pieces) != ObjectPlaceMode.STRUCTURE_PIECE;
return !isAnchoredUnderground() && pieceMode(structure, pieces) != ObjectPlaceMode.STRUCTURE_PIECE;
}
public boolean isAnchoredUnderground() {
@@ -219,6 +219,25 @@ public class IrisStructureComponentWaterTest {
assertTrue("allowWater fills the water", writes.stream().anyMatch(write -> write.y() == head));
}
@Test
public void undergroundPiecesKeepTheVeto() {
world.water(WaterRole.CHANNEL, 9, 13);
IrisObject object = HydrologyWaterFixture.raft();
int head = world.headAt(X, Z);
PlacedStructurePiece explicit = new PlacedStructurePiece(null, object, X, head + 1, Z, IrisObjectRotation.of(0, 0, 0),
X - 1, head, Z - 1, X + 1, head + 2, Z + 1);
for (ObjectPlaceMode mode : List.of(ObjectPlaceMode.ORGANIC_STILT, ObjectPlaceMode.CEILING_HANG)) {
writes.clear();
IrisStructure structure = new IrisStructure().setPlaceMode(mode);
IrisStructurePlacement placement = new IrisStructurePlacement().setUnderground(true);
assertEquals(mode.name(), 0, component.placePieces(writer, placement, structure, new KList<>(explicit), new RNG(7L)));
assertFalse(mode.name(), writes.isEmpty());
assertNoWaterOverwritten();
}
}
@Test
public void unforcedObjectsStayOffRiverWater() {
world.water(WaterRole.CHANNEL, 9, 13);
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "7eaf3ddcf305811c453a61368a9ae886cedb1ce47d4ca6dc53953ab8f26f5a77";
private static final String EXPECTED_SCHEMA_DIGEST = "4a9903e9c810bf297530a347175cd4a7ce24f181f4f623db9704727204c9573a";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -1,6 +1,9 @@
package art.arcane.iris.structure.object;
import art.arcane.iris.generation.block.TileData;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.iris.generation.mantle.ObjectContinuationBundle;
import art.arcane.iris.integration.Identifier;
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
@@ -32,6 +35,7 @@ import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.IrisMatter;
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
import art.arcane.volmlib.util.matter.MatterSlice;
import art.arcane.volmlib.util.stream.ProceduralStream;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -50,6 +54,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
@@ -206,6 +211,56 @@ public class IrisStaticObjectLayerTest {
verify(tiles).set(15, 0, 15, null);
}
@Test
@SuppressWarnings("unchecked")
public void staticObjectOverPlannedRiverOrPondWaterWritesEveryBlock() {
for (WaterRole role : List.of(WaterRole.CHANNEL, WaterRole.POND)) {
IrisObject object = object("through-water", 3, 3, 1);
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
object.getBlocks().put(new IrisBlockVector(x, y, 0), state("minecraft:stone"));
}
}
IrisStaticObjectLayer layer = compile(entry("through-water", 8, 0, 8));
Engine engine = mock(Engine.class);
IrisComplex complex = mock(IrisComplex.class);
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
ProceduralStream<Double> heads = mock(ProceduralStream.class);
ProceduralStream<Integer> floors = mock(ProceduralStream.class);
when(engine.getComplex()).thenReturn(complex);
when(complex.getHydrologyRuntime()).thenReturn(runtime);
when(complex.getWaterRoleStream()).thenReturn(roles);
when(complex.getWaterHeadStream()).thenReturn(heads);
when(complex.getRoundedHeighteightStream()).thenReturn(floors);
when(runtime.enabled()).thenReturn(true);
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
when(raster.role(anyInt(), anyInt())).thenReturn(role);
when(raster.waterHead(anyInt(), anyInt())).thenReturn(70);
when(raster.terrainHeight(anyInt(), anyInt())).thenReturn(60);
when(roles.get(anyDouble(), anyDouble())).thenReturn(role);
when(heads.getDouble(anyDouble(), anyDouble())).thenReturn(70D);
when(floors.get(anyDouble(), anyDouble())).thenReturn(60);
EngineMantle engineMantle = mock(EngineMantle.class);
Mantle<Matter> mantle = mock(Mantle.class);
MantleChunk<Matter> chunk = mock(MantleChunk.class);
when(engine.getMantle()).thenReturn(engineMantle);
when(engineMantle.getMantle()).thenReturn(mantle);
when(mantle.useChunk(anyInt(), anyInt())).thenReturn(chunk);
when(chunk.getOrCreate(anyInt())).thenReturn(mock(Matter.class));
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 384, 16);
layer.apply(engine, 0, 0, output);
for (int x = 7; x <= 9; x++) {
for (int y = 63; y <= 65; y++) {
assertSame(role + " " + x + "," + y, state("minecraft:stone"), output.get(x, y, 8));
}
}
}
}
@Test
public void transitionRejectsWholeRotatedPlacementBeforeChunkWrites() {
IrisObject object = object("rotated", 1, 1, 5);
@@ -47,6 +47,7 @@ import art.arcane.volmlib.util.stream.ProceduralStream;
import org.junit.Test;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
@@ -54,6 +55,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -502,28 +504,7 @@ public class IrisStructureLocatorContractTest {
@Test
public void forcedSinglePiecesPlaceInTheMiddleOfARiver() {
Engine engine = densityEngine(1.0, false, -64, 384, -2032, 2032);
IrisObject object = engine.getData().load(IrisObject.class, "test:density/object", false);
when(object.getW()).thenReturn(10);
when(object.getD()).thenReturn(10);
IrisComplex complex = mock(IrisComplex.class);
when(engine.getComplex()).thenReturn(complex);
when(complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(true);
@SuppressWarnings("unchecked")
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
when(complex.getWaterHeadStream()).thenReturn(waterHead);
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(124D);
when(waterHead.getDouble(anyDouble(), anyDouble())).thenReturn(124D);
@SuppressWarnings("unchecked")
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
when(complex.getWaterRoleStream()).thenReturn(roles);
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.CHANNEL);
@SuppressWarnings("unchecked")
ProceduralStream<Integer> beds = mock(ProceduralStream.class);
when(beds.get(anyDouble(), anyDouble())).thenReturn(120);
when(complex.getRoundedHeighteightStream()).thenReturn(beds);
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(120);
when(engine.getDimension().getFluidHeight()).thenReturn(63);
Engine engine = submergedEngine(WaterRole.CHANNEL, false, -2032, 2032);
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
IrisStructure structure = engine.getData().load(IrisStructure.class, "test:density", false);
@@ -540,6 +521,135 @@ public class IrisStructureLocatorContractTest {
IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
}
@Test
public void forcedSurfacePiecesPlaceOnOpenSea() {
Engine engine = submergedEngine(WaterRole.NONE, false, -2032, 2032);
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
IrisStructure structure = engine.getData().load(IrisStructure.class, "test:density", false);
assertFalse(placement.isUnderwater());
assertNull("an unforced structure stays off the sea",
IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
structure.setPlaceMode(ObjectPlaceMode.CENTER_HEIGHT);
assertNotNull(IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
}
@Test
public void unforcedMultiPieceStartsStayOffSeaColumns() {
Engine engine = submergedEngine(WaterRole.NONE, false, -2032, 2032);
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
IrisStructure structure = engine.getData().load(IrisStructure.class, "test:density", false);
structure.setPlaceMode(ObjectPlaceMode.CENTER_HEIGHT);
registerTwoPieceGraph(engine.getData(), structure, "test:density");
placement.setUnderwater(true);
IrisStructureLocator.ResolvedPlacement allowed = IrisStructureLocator.resolvePlacement(engine, placement, 3, 4);
assertNotNull(allowed);
assertEquals(2, allowed.pieces().size());
placement.setUnderwater(false);
assertNull(IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
}
@Test
public void undergroundPiecesKeepTheSubmergedCheck() {
for (ObjectPlaceMode mode : List.of(ObjectPlaceMode.ORGANIC_STILT, ObjectPlaceMode.CEILING_HANG)) {
Engine engine = submergedEngine(WaterRole.CHANNEL, true, -40, -20);
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
IrisStructure structure = engine.getData().load(IrisStructure.class, "test:density", false);
structure.setPlaceMode(mode);
assertFalse(placement.forcesPieces(structure, 1));
assertNull(mode.name(), IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
}
}
@Test
public void brokenReferencesOnASubmergedStartReturnNull() {
Engine engine = submergedEngine(WaterRole.NONE, false, -2032, 2032);
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
IrisStructure structure = engine.getData().load(IrisStructure.class, "test:density", false);
structure.setPlaceMode(ObjectPlaceMode.CENTER_HEIGHT);
structure.setStartPool("test:missing-pool");
assertNull("a graph that cannot assemble", IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
placement.getStructures().clear();
placement.getStructures().add("test:missing-structure");
assertNull("a missing structure", IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
}
@Test
public void brokenReferencesOnADryStartStillThrow() {
Engine engine = submergedEngine(WaterRole.NONE, false, -2032, 2032);
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(180);
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
IrisStructure structure = engine.getData().load(IrisStructure.class, "test:density", false);
structure.setStartPool("test:missing-pool");
assertThrows(IllegalStateException.class, () -> IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
placement.getStructures().clear();
placement.getStructures().add("test:missing-structure");
assertThrows(IllegalStateException.class, () -> IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
}
private Engine submergedEngine(WaterRole role, boolean underground, int placementMin, int placementMax) {
Engine engine = densityEngine(1.0, underground, -64, 384, placementMin, placementMax);
IrisObject object = engine.getData().load(IrisObject.class, "test:density/object", false);
when(object.getW()).thenReturn(10);
when(object.getD()).thenReturn(10);
IrisComplex complex = mock(IrisComplex.class);
when(engine.getComplex()).thenReturn(complex);
when(complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(true);
@SuppressWarnings("unchecked")
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
when(complex.getWaterHeadStream()).thenReturn(waterHead);
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(124D);
when(waterHead.getDouble(anyDouble(), anyDouble())).thenReturn(124D);
@SuppressWarnings("unchecked")
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
when(complex.getWaterRoleStream()).thenReturn(roles);
when(roles.get(anyDouble(), anyDouble())).thenReturn(role);
@SuppressWarnings("unchecked")
ProceduralStream<Integer> beds = mock(ProceduralStream.class);
when(beds.get(anyDouble(), anyDouble())).thenReturn(120);
when(complex.getRoundedHeighteightStream()).thenReturn(beds);
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(120);
when(engine.getDimension().getFluidHeight()).thenReturn(63);
return engine;
}
private void registerTwoPieceGraph(IrisData data, IrisStructure structure, String prefix) {
registerSinglePieceGraph(data, structure, prefix);
String targetPool = prefix + "/target";
String targetPiece = prefix + "/target-piece";
IrisJigsawPiece start = data.load(IrisJigsawPiece.class, prefix + "/piece", false);
start.setRotatable(false);
start.getConnectors().add(new IrisJigsawConnector()
.setPosition(new IrisPosition(0, 0, 0))
.setDirection(IrisDirection.EAST_POSITIVE_X)
.setPool(targetPool)
.setName("source")
.setTargetName("door"));
IrisJigsawPiece target = new IrisJigsawPiece().setObject(prefix + "/object").setRotatable(false);
target.getConnectors().add(new IrisJigsawConnector()
.setPosition(new IrisPosition(0, 0, 0))
.setDirection(IrisDirection.WEST_NEGATIVE_X)
.setPool(targetPool)
.setName("door")
.setTargetName("unused"));
IrisJigsawPool pool = new IrisJigsawPool();
pool.getPieces().add(new IrisJigsawPieceEntry(targetPiece, 1));
when(data.load(IrisJigsawPool.class, targetPool, false)).thenReturn(pool);
when(data.load(IrisJigsawPiece.class, targetPiece, false)).thenReturn(target);
structure.setMaxDepth(1);
}
@Test
public void undergroundIrisStructuresIgnoreRiversAbove() {
Engine engine = densityEngine(1.0, true, -64, 384, -40, -20);