Fix structure river findings

- End object placements in a finally at all four MantleObjectComponent sites
- Split recordObjectPlacement for accepted ranges from endObjectPlacement for the water flag
- Place forced single-piece structures after admission and let the MantleWriter veto protect the water
- Drop the allowWater parameter from piecePlacement
- Validate allowWater as a boolean and add it to anonymous grid identity when true
- Add placement exit, forced piece, REPLACE_SOURCE, world Y -1 and placePieces failure tests
- Add modded stage river start and policy water tests
- Rename the misleading planner river test
This commit is contained in:
Brian Fopiano committed 2026-11-02 17:29:25 -05:00
1 parent 2130c1984d
commit fcc2157d17
18 files changed
+922 -64

No files matched your search

@@ -0,0 +1,107 @@
package art.arcane.iris.modded;
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedStructureStage;
import art.arcane.volmlib.nativelib.terrain.structure.StructureOwnershipRecordView;
import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy;
import art.arcane.volmlib.nativelib.terrain.structure.StructureStartPlan;
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
import net.minecraft.SharedConstants;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.server.Bootstrap;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructurePiece;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ModdedNativeStructureRiverStartTest {
private static final String KEY = "minecraft:village_plains";
@BeforeClass
public static void bootstrap() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
}
@Test
public void plannedStartsWhosePiecesReachARiverBeyondTheStartChunkAreInvalidated() {
Fixture fixture = new Fixture(35);
fixture.adjust(fixture.plan(false));
verify(fixture.chunk).setStartForStructure(fixture.structure, StructureStart.INVALID_START);
verify(fixture.structures).discard(KEY, 0, 0);
}
@Test
public void plannedStartsWithinTheLimitOrAllowingWaterKeepTheirStart() {
Fixture within = new Fixture(36);
within.adjust(within.plan(false));
verify(within.chunk, never()).setStartForStructure(any(), any());
Fixture flooded = new Fixture(35);
flooded.adjust(flooded.plan(true));
verify(flooded.chunk, never()).setStartForStructure(any(), any());
}
@SuppressWarnings("unchecked")
private static final class Fixture {
private final NativeModdedStructureStage.Policy<Object, StructureStartPlan, Ownership> policy = mock(NativeModdedStructureStage.Policy.class);
private final StructureReferencePolicy<StructureStartPlan, Ownership> structures = mock(StructureReferencePolicy.class);
private final RegistryAccess registries = mock(RegistryAccess.class);
private final ChunkAccess chunk = mock(ChunkAccess.class);
private final Structure structure = mock(Structure.class);
private final NativeModdedStructureStage<Object, StructureStartPlan, Ownership> stage;
private Fixture(int riverEdgeX) {
Registry<Structure> registry = mock(Registry.class);
StructureStart start = mock(StructureStart.class);
StructurePiece home = mock(StructurePiece.class);
StructurePiece road = mock(StructurePiece.class);
when(registries.lookupOrThrow(Registries.STRUCTURE)).thenReturn(registry);
when(registry.getKey(structure)).thenReturn(Identifier.parse(KEY));
when(chunk.getPos()).thenReturn(new ChunkPos(0, 0));
when(chunk.getAllStarts()).thenReturn(Map.of(structure, start));
when(start.isValid()).thenReturn(true);
when(start.getChunkPos()).thenReturn(new ChunkPos(0, 0));
when(start.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 0, 39, 70, 15));
when(home.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 0, 15, 70, 15));
when(road.getBoundingBox()).thenReturn(new BoundingBox(16, 64, 0, 39, 65, 15));
when(start.getPieces()).thenReturn(List.of(home, road));
when(policy.allowsFootprint(any(), any())).thenReturn(true);
when(policy.structurePolicy(any())).thenReturn(structures);
when(policy.water(any())).thenReturn((x, z) -> x >= riverEdgeX
? new StructureWaterColumn(true, true, 58, 62) : StructureWaterColumn.DRY);
stage = new NativeModdedStructureStage<>(new NativeModdedStructureStage.Options<>(null, null, policy));
}
private StructureStartPlan plan(boolean allowWater) {
StructureStartPlan plan = mock(StructureStartPlan.class);
when(plan.structureKey()).thenReturn(KEY);
when(plan.allowWater()).thenReturn(allowWater);
return plan;
}
private void adjust(StructureStartPlan plan) {
stage.adjustGeneratedStructures(registries, chunk, Map.of(), Map.of(structure, plan), null, null);
}
}
private interface Ownership extends StructureOwnershipRecordView<Ownership> {
}
}
@@ -1,6 +1,11 @@
package art.arcane.iris.modded;
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.volmlib.nativelib.terrain.structure.StructureWater;
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
import art.arcane.volmlib.util.stream.ProceduralStream;
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedNativeStructureWorldgenAccess;
@@ -63,6 +68,9 @@ 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.Mockito.mock;
import static org.mockito.Mockito.when;
public class ModdedNativeStructureWorldgenAccessTest {
private static final int GENERATION_CENTER_X = 60;
@@ -76,6 +84,33 @@ public class ModdedNativeStructureWorldgenAccessTest {
Bootstrap.bootStrap();
}
@Test
@SuppressWarnings("unchecked")
public void policyGivesTheStageRealWaterInWorldHeights() {
Engine engine = mock(Engine.class);
IrisComplex complex = mock(IrisComplex.class);
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
ProceduralStream<Integer> floors = mock(ProceduralStream.class);
ProceduralStream<Double> heads = mock(ProceduralStream.class);
when(engine.getComplex()).thenReturn(complex);
when(engine.getMinHeight()).thenReturn(-64);
when(complex.getWaterRoleStream()).thenReturn(roles);
when(complex.getRoundedHeighteightStream()).thenReturn(floors);
when(complex.getWaterHeadStream()).thenReturn(heads);
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> {
int x = (int) Math.floor(call.<Number>getArgument(0).doubleValue());
return x == 5 ? WaterRole.CHANNEL : x == 6 ? WaterRole.MOUTH : WaterRole.NONE;
});
when(floors.get(anyDouble(), anyDouble())).thenReturn(120);
when(heads.getDouble(anyDouble(), anyDouble())).thenReturn(126D);
StructureWater water = new ModdedNativeStructurePolicy(mock(IrisModdedChunkGenerator.class)).water(engine);
assertEquals(new StructureWaterColumn(true, true, 56, 62), water.column(5, 0));
assertEquals(new StructureWaterColumn(true, false, 56, 62), water.column(6, 0));
assertEquals(StructureWaterColumn.DRY, water.column(7, 0));
}
@Test
public void ordinaryWorldFlattenPreparationHandlesReferencedVillagePiecesBeyondEightChunks() {
int farX = (GENERATION_CENTER_X - 9) << 4;