diff --git a/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedPlacementContainmentTest.java b/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedPlacementContainmentTest.java new file mode 100644 index 000000000..b9bff9120 --- /dev/null +++ b/adapters/modded-common/src/test/java/art/arcane/iris/modded/ModdedPlacementContainmentTest.java @@ -0,0 +1,287 @@ +package art.arcane.iris.modded; + +import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeFeatureBiomeSource; +import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedImportedFeatures; +import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedStructureStage; +import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureGenerationException; +import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureOwnershipRecovery; +import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructurePostProcessor; +import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureSurfaceFitter; +import art.arcane.volmlib.nativelib.minecraft26_2.terrain.NativeStructureVegetationClearer; +import art.arcane.volmlib.nativelib.minecraft26_2.terrain.WorldgenTerrainHeightmaps; +import art.arcane.volmlib.nativelib.terrain.NativeBlockChangeSet; +import art.arcane.volmlib.nativelib.terrain.NativePlacementFailures; +import art.arcane.volmlib.nativelib.terrain.feature.NativeFeatureTable; +import art.arcane.volmlib.nativelib.terrain.feature.NativeImportedFeatureControl; +import art.arcane.volmlib.nativelib.terrain.feature.NativeImportedFeaturePolicy; +import art.arcane.volmlib.nativelib.terrain.structure.StructureOwnershipRecordView; +import art.arcane.volmlib.nativelib.terrain.structure.StructurePlacementDecision; +import art.arcane.volmlib.nativelib.terrain.structure.StructureReferencePolicy; +import art.arcane.volmlib.nativelib.terrain.structure.StructureSeaSurface; +import art.arcane.volmlib.nativelib.terrain.structure.StructureStartPlan; +import art.arcane.volmlib.nativelib.terrain.structure.StructureStrata; +import art.arcane.volmlib.nativelib.terrain.structure.StructureWater; +import net.minecraft.SharedConstants; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.Bootstrap; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.StructureManager; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.biome.BiomeManager; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.LevelChunkSection; +import net.minecraft.world.level.chunk.PalettedContainerRO; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.Structure; +import net.minecraft.world.level.levelgen.structure.StructureStart; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.MockedStatic; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ModdedPlacementContainmentTest { + private final IllegalStateException failure = new IllegalStateException("placement failed"); + private final List skipped = new ArrayList<>(); + private final AtomicInteger observedFailures = new AtomicInteger(); + private final AtomicInteger observedPasses = new AtomicInteger(); + + @BeforeClass + public static void bootstrapMinecraftRegistries() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + } + + @After + public void clearHandler() { + NativePlacementFailures.register(null); + } + + @Test + public void aThrowingImportedFeatureIsSkippedAndTheNextFeatureStillPlaces() { + NativePlacementFailures.register((error, kind, id, x, z) -> skipped.add(kind)); + AtomicBoolean nextPlaced = new AtomicBoolean(); + + runFeatures(nextPlaced); + + assertEquals(List.of("imported feature"), skipped); + assertTrue(nextPlaced.get()); + assertEquals(1, observedFailures.get()); + assertEquals(1, observedPasses.get()); + } + + @Test + public void anEngineFailureFromAnImportedFeatureStopsTheChunk() { + NativePlacementFailures.register((error, kind, id, x, z) -> { + throw (IllegalStateException) error; + }); + AtomicBoolean nextPlaced = new AtomicBoolean(); + + IllegalStateException stopped = assertThrows(IllegalStateException.class, () -> runFeatures(nextPlaced)); + + assertSame(failure, stopped.getCause()); + assertFalse(nextPlaced.get()); + assertEquals(0, observedPasses.get()); + } + + @Test + public void aThrowingStartIsSkippedAndTheNextStartStillPlaces() { + NativePlacementFailures.register((error, kind, id, x, z) -> skipped.add(kind)); + + assertEquals(2, placeStructures().get()); + + assertEquals(List.of("vanilla structure"), skipped); + } + + @Test + public void anEngineFailureFromAStartStopsTheChunk() { + NativePlacementFailures.register((error, kind, id, x, z) -> { + throw (IllegalStateException) error; + }); + + NativeStructureGenerationException stopped = assertThrows(NativeStructureGenerationException.class, + this::placeStructures); + + assertSame(failure, stopped.getCause()); + } + + @SuppressWarnings("unchecked") + private void runFeatures(AtomicBoolean nextPlaced) { + NativeImportedFeaturePolicy policy = mock(NativeImportedFeaturePolicy.class); + NativeImportedFeatureControl control = mock(NativeImportedFeatureControl.class); + NativeFeatureBiomeSource source = mock(NativeFeatureBiomeSource.class); + RegistryAccess registries = mock(RegistryAccess.class); + Registry featureRegistry = mock(Registry.class); + Biome biome = mock(Biome.class); + Holder.Reference biomeHolder = mock(Holder.Reference.class); + LevelChunkSection section = mock(LevelChunkSection.class); + PalettedContainerRO> biomes = mock(PalettedContainerRO.class); + WorldGenLevel level = mock(WorldGenLevel.class); + ChunkAccess chunk = mock(ChunkAccess.class); + PlacedFeature throwing = feature(world -> { + throw failure; + }); + PlacedFeature next = feature(world -> nextPlaced.set(true)); + when(policy.visibleBiomeKeys()).thenReturn(Set.of("minecraft:plains")); + when(policy.customBiomeDerivatives()).thenReturn(List.of()); + when(policy.placement()).thenReturn(new NativeImportedFeaturePolicy.Placement( + false, false, null, null, (x, y, z) -> false, null)); + when(policy.trackedBlockPositions(any())).thenReturn(NativeBlockChangeSet.disabled()); + when(control.shouldGenerateStepOrdinal(anyInt())).thenReturn(true); + when(source.orderedPossibleBiomes()).thenReturn(List.of(biomeHolder)); + when(biomeHolder.unwrapKey()).thenReturn(Optional.of( + ResourceKey.create(Registries.BIOME, Identifier.parse("minecraft:plains")))); + when(biomeHolder.value()).thenReturn(biome); + when(biome.getGenerationSettings()).thenReturn(new BiomeGenerationSettings.PlainBuilder() + .addFeature(0, Holder.direct(throwing)) + .addFeature(0, Holder.direct(next)).build()); + when(level.registryAccess()).thenReturn(registries); + when(registries.lookupOrThrow(Registries.PLACED_FEATURE)).thenReturn(featureRegistry); + when(level.getMinY()).thenReturn(-64); + when(level.getMinSectionY()).thenReturn(-4); + when(level.getHeight()).thenReturn(384); + when(level.getBiome(any())).thenReturn(biomeHolder); + when(level.getBiomeManager()).thenReturn(new BiomeManager((x, y, z) -> biomeHolder, 7L)); + when(level.getChunk(anyInt(), anyInt())).thenReturn(chunk); + when(chunk.getPos()).thenReturn(new ChunkPos(0, 0)); + when(chunk.getSections()).thenReturn(new LevelChunkSection[]{section}); + when(section.getBiomes()).thenReturn(biomes); + doAnswer(invocation -> { + Consumer> consumer = invocation.getArgument(0); + consumer.accept(biomeHolder); + return null; + }).when(biomes).getAll(any()); + NativeModdedImportedFeatures features = new NativeModdedImportedFeatures(source, new NativeModdedImportedFeatures.PlacementObserver() { + @Override + public void completed() { + observedPasses.incrementAndGet(); + } + + @Override + public void failed(int chunkX, int chunkZ, Throwable error) { + observedFailures.incrementAndGet(); + } + }); + NativeFeatureTable table = features.buildTable(policy, control, 1L); + + features.run(level, chunk, mock(ChunkGenerator.class), table); + + verify(level).setCurrentlyGenerating(null); + } + + @SuppressWarnings("unchecked") + private AtomicInteger placeStructures() { + WorldGenLevel world = mock(WorldGenLevel.class); + ChunkAccess chunk = mock(ChunkAccess.class); + StructureManager manager = mock(StructureManager.class); + NativeBlockChangeSet changes = NativeBlockChangeSet.create(new NativeBlockChangeSet.Bounds(-1, -1, 1, 1, -64, 384)); + NativeModdedStructureStage.Policy policy = mock(NativeModdedStructureStage.Policy.class); + StructureReferencePolicy structures = mock(StructureReferencePolicy.class); + RegistryAccess registries = mock(RegistryAccess.class); + Registry registry = mock(Registry.class); + Structure structure = mock(Structure.class); + StructureStart start = mock(StructureStart.class); + StructureStart nextStart = mock(StructureStart.class); + StructurePlacementDecision decision = mock(StructurePlacementDecision.class); + Holder biome = Holder.direct(mock(Biome.class)); + when(world.registryAccess()).thenReturn(registries); + when(world.getLevel()).thenReturn(mock(ServerLevel.class)); + when(registries.lookupOrThrow(Registries.STRUCTURE)).thenReturn(registry); + when(registry.iterator()).thenAnswer(invocation -> List.of(structure).iterator()); + when(registry.getKey(structure)).thenReturn(Identifier.parse("minecraft:village_plains")); + when(structure.step()).thenReturn(GenerationStep.Decoration.SURFACE_STRUCTURES); + when(manager.shouldGenerateStructures()).thenReturn(true); + when(manager.startsForStructure(anyInt(), anyInt(), any(Structure.class))).thenReturn(List.of(start, nextStart)); + when(start.getChunkPos()).thenReturn(new ChunkPos(0, 0)); + when(start.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 0, 15, 80, 15)); + when(nextStart.getChunkPos()).thenReturn(new ChunkPos(0, 1)); + when(nextStart.getBoundingBox()).thenReturn(new BoundingBox(0, 60, 16, 15, 80, 31)); + when(policy.allowsFootprint(any(), any())).thenReturn(true); + when(policy.strata(any())).thenReturn(mock(StructureStrata.class)); + when(policy.water(any())).thenReturn(mock(StructureWater.class)); + when(policy.seaSurface(any())).thenReturn(StructureSeaSurface.NONE); + when(policy.structurePolicy(any())).thenReturn(structures); + when(structures.resolve(anyString(), anyBoolean())).thenReturn(decision); + when(decision.generate()).thenReturn(true); + when(policy.protectedPositions(any())).thenReturn((x, y, z) -> false); + when(policy.worldgenHeight(any(), anyInt(), anyBoolean())).thenReturn((x, z) -> 64); + when(policy.trackBlockChanges(any(), any())).thenReturn(changes); + when(chunk.getPos()).thenReturn(new ChunkPos(0, 0)); + when(chunk.getMinY()).thenReturn(-64); + when(chunk.getHeight()).thenReturn(384); + when(chunk.getSections()).thenReturn(new LevelChunkSection[0]); + when(world.getMinY()).thenReturn(-64); + when(world.getHeight()).thenReturn(384); + when(world.getBiome(any())).thenReturn(biome); + when(world.getBiomeManager()).thenReturn(new BiomeManager((x, y, z) -> biome, 7L)); + NativeModdedStructureStage stage = new NativeModdedStructureStage<>( + new NativeModdedStructureStage.Options<>(mock(ChunkGenerator.class), () -> null, policy)); + AtomicInteger placed = new AtomicInteger(); + try (MockedStatic heights = mockStatic(WorldgenTerrainHeightmaps.class); + MockedStatic ownership = mockStatic(NativeStructureOwnershipRecovery.class); + MockedStatic vegetation = mockStatic(NativeStructureVegetationClearer.class); + MockedStatic surface = mockStatic(NativeStructureSurfaceFitter.class); + MockedStatic post = mockStatic(NativeStructurePostProcessor.class)) { + surface.when(() -> NativeStructureSurfaceFitter.prepareSurfaceStructures(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(new NativeStructureSurfaceFitter.SurfaceTerrainPlan(List.of(), Set.of(), Map.of(), Map.of())); + post.when(() -> NativeStructurePostProcessor.place(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())) + .thenAnswer(invocation -> { + if (placed.incrementAndGet() == 1) { + throw failure; + } + return null; + }); + stage.placeVanillaStructures(world, chunk, manager); + } + verify(policy).invalidateBlockChanges(null, changes); + return placed; + } + + @SuppressWarnings("unchecked") + private static PlacedFeature feature(Consumer placement) { + Feature feature = mock(Feature.class); + when(feature.place(any(), any(), any(), any())).thenAnswer(invocation -> { + placement.accept(invocation.getArgument(0)); + return true; + }); + return new PlacedFeature(Holder.direct(feature), List.of()); + } + + private interface Ownership extends StructureOwnershipRecordView { + } +} diff --git a/adapters/modded-common/src/versions/1.21.1/test/source-replacements.json b/adapters/modded-common/src/versions/1.21.1/test/source-replacements.json index e0b2e17a7..814fcca91 100644 --- a/adapters/modded-common/src/versions/1.21.1/test/source-replacements.json +++ b/adapters/modded-common/src/versions/1.21.1/test/source-replacements.json @@ -443,6 +443,48 @@ "pattern": "\"volmlib\\.entity\\.mixins\\.json/ServerLevelStructureBootstrapMixin\",", "replacement": "\"volmlib.entity.mixins.json/ServerLevelStructureBootstrapMixin\",\n \"volmlib.entity.mixins.json/WorldDimensionsBakeMixin\",\n \"volmlib.entity.mixins.json/WorldGenSettingsPersistenceMixin\"," } + ], + "art/arcane/iris/modded/ModdedPlacementContainmentTest.java": [ + { + "pattern": "manager\\.startsForStructure\\(anyInt\\(\\), anyInt\\(\\), any\\(Structure\\.class\\)\\)", + "replacement": "manager.startsForStructure(any(SectionPos.class), any(Structure.class))" + }, + { + "pattern": "import net\\.minecraft\\.core\\.Holder;", + "replacement": "import net.minecraft.core.Holder;\nimport net.minecraft.core.SectionPos;" + }, + { + "pattern": "import net\\.minecraft\\.world\\.level\\.levelgen\\.feature\\.Feature;", + "replacement": "import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;\nimport net.minecraft.world.level.levelgen.feature.Feature;\nimport net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;" + }, + { + "pattern": "Feature feature = mock\\(Feature\\.class\\);", + "replacement": "Feature feature = mock(Feature.class);" + }, + { + "pattern": "when\\(feature\\.place\\(any\\(\\), any\\(\\), any\\(\\), any\\(\\)\\)\\)", + "replacement": "when(feature.place(any(), any(), any(), any(), any()))" + }, + { + "pattern": "placement\\.accept\\(invocation\\.getArgument\\(0\\)\\);", + "replacement": "placement.accept(invocation.getArgument(1));" + }, + { + "pattern": "return new PlacedFeature\\(Holder\\.direct\\(feature\\), List\\.of\\(\\)\\);", + "replacement": "return new PlacedFeature(Holder.direct(new ConfiguredFeature<>(feature, NoneFeatureConfiguration.INSTANCE)), List.of());" + }, + { + "pattern": "\\.getMinY\\(\\)", + "replacement": ".getMinBuildHeight()" + }, + { + "pattern": "\\.getMinSectionY\\(\\)", + "replacement": ".getMinSection()" + }, + { + "pattern": "registries\\.lookupOrThrow\\(", + "replacement": "registries.registryOrThrow(" + } ] } } diff --git a/adapters/modded-common/src/versions/26.2/test/source-replacements.json b/adapters/modded-common/src/versions/26.2/test/source-replacements.json index d5882728b..2ec5aabd4 100644 --- a/adapters/modded-common/src/versions/26.2/test/source-replacements.json +++ b/adapters/modded-common/src/versions/26.2/test/source-replacements.json @@ -73,6 +73,36 @@ "pattern": "(?ms)^ BuiltInRegistries\\.BLOCK\\.prepareTagReload\\(new TagLoader\\.LoadResult<>.*?\\)\\)\\)\\)\\.apply\\(\\);\\n", "replacement": "" } + ], + "art/arcane/iris/modded/ModdedPlacementContainmentTest.java": [ + { + "pattern": "manager\\.startsForStructure\\(anyInt\\(\\), anyInt\\(\\), any\\(Structure\\.class\\)\\)", + "replacement": "manager.startsForStructure(any(SectionPos.class), any(Structure.class))" + }, + { + "pattern": "import net\\.minecraft\\.core\\.Holder;", + "replacement": "import net.minecraft.core.Holder;\nimport net.minecraft.core.SectionPos;" + }, + { + "pattern": "import net\\.minecraft\\.world\\.level\\.levelgen\\.feature\\.Feature;", + "replacement": "import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;\nimport net.minecraft.world.level.levelgen.feature.Feature;\nimport net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;" + }, + { + "pattern": "Feature feature = mock\\(Feature\\.class\\);", + "replacement": "Feature feature = mock(Feature.class);" + }, + { + "pattern": "when\\(feature\\.place\\(any\\(\\), any\\(\\), any\\(\\), any\\(\\)\\)\\)", + "replacement": "when(feature.place(any(), any(), any(), any(), any()))" + }, + { + "pattern": "placement\\.accept\\(invocation\\.getArgument\\(0\\)\\);", + "replacement": "placement.accept(invocation.getArgument(1));" + }, + { + "pattern": "return new PlacedFeature\\(Holder\\.direct\\(feature\\), List\\.of\\(\\)\\);", + "replacement": "return new PlacedFeature(Holder.direct(new ConfiguredFeature<>(feature, NoneFeatureConfiguration.INSTANCE)), List.of());" + } ] } } diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java index 80fc713cc..1d82cf6fa 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java @@ -1,5 +1,6 @@ package art.arcane.iris.generation.hydrology.engine; +import art.arcane.iris.generation.runtime.HydrologyPlanException; import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.iris.generation.concurrent.MultiBurst; import art.arcane.iris.generation.hydrology.config.IrisHydrology; @@ -630,7 +631,7 @@ public final class HydrologyRuntime { throw cancelled; } catch (RuntimeException failure) { failures.failed(chunk); - throw new IllegalStateException("Hydrology could not build the water raster for chunk " + chunkX + "," + chunkZ + ".", failure); + throw new HydrologyPlanException("Hydrology could not build the water raster for chunk " + chunkX + "," + chunkZ + ".", failure); } } diff --git a/core/src/main/java/art/arcane/iris/generation/mantle/IrisStructureComponent.java b/core/src/main/java/art/arcane/iris/generation/mantle/IrisStructureComponent.java index e0e6757ec..29a8bf953 100644 --- a/core/src/main/java/art/arcane/iris/generation/mantle/IrisStructureComponent.java +++ b/core/src/main/java/art/arcane/iris/generation/mantle/IrisStructureComponent.java @@ -98,9 +98,6 @@ public class IrisStructureComponent extends IrisMantleComponent { try { placeFromPlacement(writer, placement, x, z, placementOrdinal); } catch (Throwable e) { - if (placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE) { - throw e; - } GenerationFailures.skipPlacement(e, "structure", String.valueOf(placement.getStructures()), x << 4, -1, z << 4, "none"); } } @@ -160,7 +157,6 @@ public class IrisStructureComponent extends IrisMantleComponent { } int failedPieces = placePieces(writer, placement, structure, pieces, rng); - requireAppliedPieces(resolved, cx, cz, failedPieces); if (failedPieces == 0) { capture.commit(); } @@ -171,7 +167,8 @@ public class IrisStructureComponent extends IrisMantleComponent { KList pieces, RNG rng) { IrisStructureStiltSettings stilt = placement.getStilt(); PieceRun run = new PieceRun(structure, rng, stilt == null ? null : new Long2IntOpenHashMap(), - stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater()); + stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater(), + placement.getNativeSuppression() == NativeStructureSuppression.REPLACE_SOURCE); ObjectPlaceMode mode = structure.getPlaceMode(); int failedPieces = 0; int water = writer.beginObjectPlacement(run.allowWater()); @@ -266,22 +263,14 @@ public class IrisStructureComponent extends IrisMantleComponent { return null; } KList pieces = resolved.pieces(); - if (!IrisStructureLocator.requirePlacementOutput( + if (!IrisStructureLocator.placementOutput( resolved.placement(), resolved.structureKey(), chunkX, chunkZ, - pieces != null && !pieces.isEmpty(), "placement application received no assembled pieces")) { + pieces != null && !pieces.isEmpty(), "no assembled pieces", null)) { return null; } return pieces; } - static void requireAppliedPieces(IrisStructureLocator.ResolvedPlacement resolved, - int chunkX, int chunkZ, int failedPieces) { - IrisStructureLocator.requirePlacementOutput( - resolved.placement(), resolved.structureKey(), chunkX, chunkZ, failedPieces == 0, - "object placement rejected " + failedPieces + " of " + resolved.pieces().size() - + " assembled piece(s)"); - } - void boreStructure(MantleWriter writer, KList pieces, IrisStructureTerrain terrain) { int[] bounds = computePieceBounds(pieces); @@ -589,11 +578,15 @@ public class IrisStructureComponent extends IrisMantleComponent { } }; try { - return sampledHeight + int placed = sampledHeight ? object.place(p.getX(), p.getZ(), writer, config, run.rng(), listener, null, getData()) : object.place(p.getX(), p.getY() - getEngineMantle().getEngine().getMinHeight(), p.getZ(), writer, config, run.rng(), listener, null, getData()); + if (placed == -1 && run.replacesSource()) { + GenerationFailures.skipStructure(run.structure().getLoadKey(), "piece rejected", objectKey, p.getX() >> 4, p.getZ() >> 4); + } + return placed; } catch (Throwable e) { - GenerationFailures.skipPlacement(e, "structure piece", objectKey, p.getX(), p.getY(), p.getZ(), run.structure().getLoadKey()); + GenerationFailures.skipStructurePiece(e, run.structure().getLoadKey(), objectKey, p.getX(), p.getY(), p.getZ()); return -1; } } @@ -735,6 +728,6 @@ public class IrisStructureComponent extends IrisMantleComponent { } private record PieceRun(IrisStructure structure, RNG rng, Long2IntOpenHashMap foundationColumns, - boolean supportNonOccluding, boolean allowWater) { + boolean supportNonOccluding, boolean allowWater, boolean replacesSource) { } } diff --git a/core/src/main/java/art/arcane/iris/generation/runtime/GenerationFailures.java b/core/src/main/java/art/arcane/iris/generation/runtime/GenerationFailures.java index 115e8dd62..4f337793b 100644 --- a/core/src/main/java/art/arcane/iris/generation/runtime/GenerationFailures.java +++ b/core/src/main/java/art/arcane/iris/generation/runtime/GenerationFailures.java @@ -3,6 +3,7 @@ package art.arcane.iris.generation.runtime; import art.arcane.iris.generation.stream.ProvisionalAnswerException; import art.arcane.iris.spi.IrisLogging; import art.arcane.iris.world.history.SavedBiomeUnavailableException; +import art.arcane.volmlib.nativelib.terrain.NativePlacementFailures; import art.arcane.volmlib.util.mantle.MantleClosedException; import java.io.IOException; @@ -32,12 +33,18 @@ public final class GenerationFailures { private GenerationFailures() { } + public static void bindNativeFailures() { + NativePlacementFailures.register((Throwable failure, String kind, String id, int x, int z) -> + skipPlacement(failure, kind, id, x, -1, z, "none")); + } + public static boolean isEngineFailure(Throwable failure) { return isShutdownFailure(failure) || hasCause(failure, (Throwable cause) -> cause instanceof Error || cause instanceof WrongEngineBroException || cause instanceof ProvisionalAnswerException || cause instanceof SavedBiomeUnavailableException unavailable && unavailable.isLoading() || cause instanceof GenerationSessionException + || cause instanceof HydrologyPlanException || cause instanceof IOException || cause instanceof UncheckedIOException || cause instanceof TimeoutException); @@ -99,6 +106,41 @@ public final class GenerationFailures { } } + /** + * One failed piece of one structure. The warning counts per structure and failure, however many objects fail. + */ + public static void skipStructurePiece(Throwable failure, String structure, String piece, int x, int y, int z) { + rethrowEngineFailure(failure); + String key = "structure piece|" + structure + '|' + failure.getClass().getName(); + long suppressed = claimSkipWarning(key, System.nanoTime()); + if (suppressed >= 0L) { + IrisLogging.warn(skipWarning("structure piece", structure + ' ' + piece, x, y, z, "none", failure, suppressed)); + } + } + + /** + * One structure that gave no output without throwing. The cause must stay the same between chunks: it is the + * warning's key, and the detail is only printed. + */ + public static void skipStructure(String structure, String cause, String detail, int chunkX, int chunkZ) { + long suppressed = claimSkipWarning("structure|" + structure + '|' + cause, System.nanoTime()); + if (suppressed >= 0L) { + IrisLogging.warn(structureWarning(structure, cause, detail, chunkX, chunkZ, suppressed)); + } + } + + static String structureWarning(String structure, String cause, String detail, int chunkX, int chunkZ, long suppressed) { + StringBuilder line = new StringBuilder("Skipped structure ").append(structure) + .append(" in chunk ").append(chunkX).append(',').append(chunkZ).append(": ").append(cause); + if (detail != null && !detail.isBlank()) { + line.append(" (").append(detail.replaceAll("\\s+", " ")).append(')'); + } + if (suppressed > 0L) { + line.append(", ").append(suppressed).append(" more"); + } + return line.toString(); + } + static long claimSkipWarning(String key, long now) { SkipWarning warning = SKIP_WARNINGS.get(key); if (warning == null) { diff --git a/core/src/main/java/art/arcane/iris/generation/runtime/HydrologyPlanException.java b/core/src/main/java/art/arcane/iris/generation/runtime/HydrologyPlanException.java new file mode 100644 index 000000000..168e2cdf9 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/generation/runtime/HydrologyPlanException.java @@ -0,0 +1,10 @@ +package art.arcane.iris.generation.runtime; + +/** + * A hydrology plan could not be read. Water for the chunk can't be known, so no placement scope may skip this. + */ +public final class HydrologyPlanException extends IllegalStateException { + public HydrologyPlanException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/core/src/main/java/art/arcane/iris/generation/runtime/IrisEngine.java b/core/src/main/java/art/arcane/iris/generation/runtime/IrisEngine.java index c512b9a6d..4cbc2a06d 100644 --- a/core/src/main/java/art/arcane/iris/generation/runtime/IrisEngine.java +++ b/core/src/main/java/art/arcane/iris/generation/runtime/IrisEngine.java @@ -255,6 +255,7 @@ public class IrisEngine implements Engine { GenerationKernelRegistry.Version kernelVersion, TransitionGenerationPlan transitionPlan ) { + GenerationFailures.bindNativeFailures(); EngineTarget requiredTarget = Objects.requireNonNull(target, "engine target"); InitializationMode requiredMode = Objects.requireNonNull(initializationMode, "initialization mode"); this.initializationMode = requiredMode; diff --git a/core/src/main/java/art/arcane/iris/structure/placement/IrisStructureLocator.java b/core/src/main/java/art/arcane/iris/structure/placement/IrisStructureLocator.java index 4728e977d..c80db7b7b 100644 --- a/core/src/main/java/art/arcane/iris/structure/placement/IrisStructureLocator.java +++ b/core/src/main/java/art/arcane/iris/structure/placement/IrisStructureLocator.java @@ -28,6 +28,7 @@ import art.arcane.volmlib.util.structure.StructureTerrainMode; import art.arcane.volmlib.util.structure.StructureCarveShape; +import art.arcane.iris.generation.runtime.GenerationFailures; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.SeedManager; import art.arcane.iris.structure.nativegen.NativeStructurePlacementPlanner; @@ -545,15 +546,15 @@ public final class IrisStructureLocator { StructureAssembler assembler = StructureAssembler.forData( engine.getData(), structure, new IrisPosition(originX, baseY, originZ)); StructureAssemblyResult assembly = assembler.assemble(rng); - if (!requirePlacementOutput(placement, selectedKey, cx, cz, - assembly.hasOutput(), "runtime assembly produced " + assembly.status() + ": " + assembly.detail())) { + if (!placementOutput(placement, selectedKey, cx, cz, + assembly.hasOutput(), "assembly " + assembly.status(), assembly.detail())) { return null; } KList pieces = new KList<>(assembly.pieces()); pieces = alignCavePieces(pieces, placement, baseY); pieces = alignSurfacePieces(pieces, placement, structure, baseY); - if (!requirePlacementOutput(placement, selectedKey, cx, cz, - pieces != null && !pieces.isEmpty(), "surface alignment produced no pieces")) { + if (!placementOutput(placement, selectedKey, cx, cz, + pieces != null && !pieces.isEmpty(), "surface alignment left no pieces", null)) { return null; } boolean exactY = hasExactY(placement, structure, pieces); @@ -562,8 +563,8 @@ public final class IrisStructureLocator { int worldMax = engine.getMinHeight() + engine.getHeight() - 1; if (exactY) { Integer verticalShift = resolveVerticalShift(pieces, placement, baseY, worldMin, worldMax); - if (!requirePlacementOutput(placement, selectedKey, cx, cz, verticalShift != null, - "assembled pieces cannot fit the configured vertical and world bounds")) { + if (!placementOutput(placement, selectedKey, cx, cz, verticalShift != null, + "pieces do not fit the vertical bounds", null)) { return null; } if (verticalShift != 0) { @@ -574,8 +575,8 @@ public final class IrisStructureLocator { if (placement.isAnchoredUnderground() && !placement.resolvedAnchor().isCave()) { Integer burialShift = resolveUndergroundBurialShift( engine, pieces, placement, baseY, worldMin, worldMax); - if (!requirePlacementOutput(placement, selectedKey, cx, cz, burialShift != null, - "assembled pieces and carving envelope cannot remain fully buried beneath terrain")) { + if (!placementOutput(placement, selectedKey, cx, cz, burialShift != null, + "pieces cannot stay buried", null)) { return null; } if (burialShift != 0) { @@ -588,8 +589,8 @@ public final class IrisStructureLocator { int structureRadius = (int) Math.min(Integer.MAX_VALUE, configuredRadius); boolean withinBounds = fitsHorizontalBounds(pieces, originX, originZ, structureRadius) && (!exactY || fitsVerticalBounds(pieces, worldMin, worldMax)); - if (!requirePlacementOutput(placement, selectedKey, cx, cz, withinBounds, - "assembled pieces exceed the configured structure or world bounds")) { + if (!placementOutput(placement, selectedKey, cx, cz, withinBounds, + "pieces exceed the structure or world bounds", null)) { return null; } if (!placement.isAnchoredUnderground() && !placement.isAllowWater() @@ -607,23 +608,17 @@ public final class IrisStructureLocator { return allowsResolvedFootprint(engine, resolved.placement(), resolved.structure(), resolved.pieces()); } - public static boolean requirePlacementOutput(IrisStructurePlacement placement, String structureKey, - int chunkX, int chunkZ, boolean outputPresent, - String failureReason) { + public static boolean placementOutput(IrisStructurePlacement placement, String structureKey, int chunkX, int chunkZ, + boolean outputPresent, String cause, String detail) { if (outputPresent) { return true; } - if (placement == null - || NativeStructureSuppression.REPLACE_SOURCE != placement.getNativeSuppression()) { - return false; + if (placement != null && NativeStructureSuppression.REPLACE_SOURCE == placement.getNativeSuppression()) { + String key = structureKey == null || structureKey.isBlank() + ? String.valueOf(placement.getStructures()) : structureKey; + GenerationFailures.skipStructure(key, cause, detail, chunkX, chunkZ); } - String key = structureKey == null || structureKey.isBlank() - ? String.valueOf(placement.getStructures()) : structureKey; - String reason = failureReason == null || failureReason.isBlank() - ? "placement produced no output" : failureReason; - throw new IllegalStateException("REPLACE_SOURCE placement for Iris structure '" + key - + "' failed in chunk " + chunkX + "," + chunkZ + ": " + reason - + ". Native generation is suppressed and will not be used as a fallback"); + return false; } static boolean fitsWorldBounds(KList pieces, int worldMin, int worldMax, diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java index 86d9c34f7..633f3429b 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java @@ -1,6 +1,7 @@ package art.arcane.iris.generation.hydrology.engine; import art.arcane.iris.generation.biome.IrisBiome; +import art.arcane.iris.generation.runtime.HydrologyPlanException; import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction; import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell; import art.arcane.iris.generation.hydrology.config.IrisHydrology; @@ -265,7 +266,7 @@ public class HydrologyRuntimeTest { pool.submit(() -> { }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); long planned = runtime.previewRevision(); - assertThrows(IllegalStateException.class, () -> runtime.raster(0, 0)); + assertThrows(HydrologyPlanException.class, () -> runtime.raster(0, 0)); assertEquals(planned, runtime.previewRevision()); } diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/IrisStructureComponentMarkerTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/IrisStructureComponentMarkerTest.java index ae78e8959..54c190845 100644 --- a/core/src/test/java/art/arcane/iris/generation/mantle/IrisStructureComponentMarkerTest.java +++ b/core/src/test/java/art/arcane/iris/generation/mantle/IrisStructureComponentMarkerTest.java @@ -59,36 +59,14 @@ public class IrisStructureComponentMarkerTest { NativeStructureSuppression.NONE, new KList<>()); assertNull(IrisStructureComponent.resolvedPiecesOrNull(resolved, 4, -3)); - IrisStructureComponent.requireAppliedPieces(resolvedWithOnePiece(NativeStructureSuppression.NONE), - 4, -3, 1); } @Test - public void emptyResolvedPiecesFailForReplacement() { + public void emptyResolvedPiecesAreSkippedForReplacement() { IrisStructureLocator.ResolvedPlacement resolved = resolvedPlacement( NativeStructureSuppression.REPLACE_SOURCE, new KList<>()); - assertReplacementFailure( - () -> IrisStructureComponent.resolvedPiecesOrNull(resolved, 4, -3), - "placement application received no assembled pieces"); - } - - @Test - public void rejectedAppliedPieceFailsForReplacement() { - IrisStructureLocator.ResolvedPlacement resolved = resolvedWithOnePiece( - NativeStructureSuppression.REPLACE_SOURCE); - - assertReplacementFailure( - () -> IrisStructureComponent.requireAppliedPieces(resolved, 4, -3, 1), - "object placement rejected 1 of 1 assembled piece(s)"); - } - - private IrisStructureLocator.ResolvedPlacement resolvedWithOnePiece( - NativeStructureSuppression suppression - ) { - KList pieces = new KList<>(); - pieces.add(mock(PlacedStructurePiece.class)); - return resolvedPlacement(suppression, pieces); + assertNull(IrisStructureComponent.resolvedPiecesOrNull(resolved, 4, -3)); } private IrisStructureLocator.ResolvedPlacement resolvedPlacement( @@ -102,14 +80,4 @@ public class IrisStructureComponentMarkerTest { return new IrisStructureLocator.ResolvedPlacement( placement, "test:city", structure, pieces, new RNG(1L), 0, 64, 0, false); } - - private void assertReplacementFailure(Runnable operation, String expectedMessage) { - try { - operation.run(); - } catch (IllegalStateException e) { - assertTrue(e.getMessage(), e.getMessage().contains(expectedMessage)); - return; - } - throw new AssertionError("Expected strict native replacement failure containing '" + expectedMessage + "'"); - } } diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/IrisStructureReplacementFailureTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/IrisStructureReplacementFailureTest.java new file mode 100644 index 000000000..d74594242 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/generation/mantle/IrisStructureReplacementFailureTest.java @@ -0,0 +1,203 @@ +package art.arcane.iris.generation.mantle; + +import art.arcane.iris.configuration.IrisSettings; +import art.arcane.iris.generation.context.ChunkContext; +import art.arcane.iris.generation.runtime.Engine; +import art.arcane.iris.generation.runtime.GenerationClosedException; +import art.arcane.iris.generation.runtime.IrisComplex; +import art.arcane.iris.pack.loading.IrisData; +import art.arcane.iris.spi.IrisPlatform; +import art.arcane.iris.spi.IrisPlatforms; +import art.arcane.iris.spi.LogLevel; +import art.arcane.iris.structure.nativegen.NativeStructureSuppression; +import art.arcane.iris.structure.object.IrisObject; +import art.arcane.iris.structure.object.IrisObjectRotation; +import art.arcane.iris.structure.object.ObjectPlaceMode; +import art.arcane.iris.structure.placement.IrisStructure; +import art.arcane.iris.structure.placement.IrisStructureLocator; +import art.arcane.iris.structure.placement.IrisStructurePlacement; +import art.arcane.iris.structure.placement.PlacedStructurePiece; +import art.arcane.iris.structure.placement.StructurePlacementScope; +import art.arcane.iris.testsupport.PlatformLeakGuard; +import art.arcane.volmlib.util.collection.KList; +import art.arcane.volmlib.util.math.RNG; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.mockito.MockedStatic; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class IrisStructureReplacementFailureTest { + @ClassRule + public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean(); + + private final List warnings = new ArrayList<>(); + private IrisSettings previousSettings; + private IrisStructureComponent component; + private Engine engine; + private MantleWriter writer; + private ChunkContext context; + + @Before + public void setUp() { + previousSettings = IrisSettings.settings; + IrisSettings.settings = new IrisSettings(); + IrisPlatforms.unbind(); + IrisPlatform platform = mock(IrisPlatform.class); + doAnswer(invocation -> { + if (invocation.getArgument(0) == LogLevel.WARN) { + warnings.add(invocation.getArgument(1)); + } + return null; + }).when(platform).log(any(LogLevel.class), any(String.class)); + IrisPlatforms.bind(platform); + EngineMantle engineMantle = mock(EngineMantle.class); + engine = mock(Engine.class); + IrisComplex complex = mock(IrisComplex.class); + when(complex.allowsNewGenerationChunk(anyInt(), anyInt())).thenReturn(true); + when(engineMantle.getEngine()).thenReturn(engine); + when(engineMantle.getComplex()).thenReturn(complex); + when(engineMantle.getData()).thenReturn(mock(IrisData.class)); + when(engine.getComplex()).thenReturn(complex); + when(engine.getMinHeight()).thenReturn(-64); + when(engine.getHeight()).thenReturn(384); + component = new IrisStructureComponent(engineMantle); + writer = mock(MantleWriter.class); + context = mock(ChunkContext.class); + when(context.getComplex()).thenReturn(complex); + } + + @After + public void tearDown() { + IrisSettings.settings = previousSettings; + IrisPlatforms.unbind(); + } + + @Test + public void rejectedPiecesWarnOnceAcrossPiecesAndChunks() { + IrisObject rejected = object("objects/rejected"); + when(rejected.place(anyInt(), anyInt(), anyInt(), any(), any(), any(), any(), any(), any())).thenReturn(-1); + IrisStructure structure = structure("test:rejected-city"); + + assertEquals(3, component.placePieces(writer, replacement(), structure, pieces(rejected, 3), new RNG(1L))); + assertEquals(3, component.placePieces(writer, replacement(), structure, pieces(rejected, 3), new RNG(2L))); + + assertEquals(warnings.toString(), 1, warnings.size()); + assertTrue(warnings.getFirst(), warnings.getFirst().contains("test:rejected-city")); + } + + @Test + public void rejectedPieceOfANonReplacementStaysSilent() { + IrisObject rejected = object("objects/rejected"); + when(rejected.place(anyInt(), anyInt(), anyInt(), any(), any(), any(), any(), any(), any())).thenReturn(-1); + + assertEquals(1, component.placePieces(writer, new IrisStructurePlacement(), structure("test:quiet-city"), + pieces(rejected, 1), new RNG(1L))); + + assertEquals(List.of(), warnings); + } + + @Test + public void throwingPiecesWarnOnceAndTheOtherPiecesStillPlace() { + IrisObject broken = object("objects/broken"); + IrisObject sound = object("objects/sound"); + when(broken.place(anyInt(), anyInt(), anyInt(), any(), any(), any(), any(), any(), any())) + .thenThrow(new IllegalArgumentException("bad block")); + IrisObject alsoBroken = object("objects/also-broken"); + when(alsoBroken.place(anyInt(), anyInt(), anyInt(), any(), any(), any(), any(), any(), any())) + .thenThrow(new IllegalArgumentException("bad block")); + KList pieces = pieces(broken, 1); + pieces.addAll(pieces(alsoBroken, 1)); + pieces.addAll(pieces(sound, 1)); + + assertEquals(2, component.placePieces(writer, replacement(), structure("test:broken-city"), pieces, new RNG(1L))); + + assertEquals(warnings.toString(), 1, warnings.size()); + verify(sound, times(1)).place(anyInt(), anyInt(), anyInt(), any(), any(), any(), any(), any(), any()); + } + + @Test + public void engineFailureFromAPieceEscapes() { + IrisObject broken = object("objects/closed"); + GenerationClosedException closed = new GenerationClosedException("router closed"); + when(broken.place(anyInt(), anyInt(), anyInt(), any(), any(), any(), any(), any(), any())).thenThrow(closed); + + assertSame(closed, assertThrows(GenerationClosedException.class, () -> component.placePieces(writer, replacement(), + structure("test:closed-city"), pieces(broken, 1), new RNG(1L)))); + } + + @Test + public void aThrowingReplacementLeavesTheChunkGeneratingWithOneWarning() { + IrisStructurePlacement placement = replacement(); + placement.getStructures().add("test:failing-city"); + try (MockedStatic scope = mockStatic(StructurePlacementScope.class); + MockedStatic locator = mockStatic(IrisStructureLocator.class)) { + scope.when(() -> StructurePlacementScope.placementsAt(any(), anyInt(), anyInt())) + .thenReturn(new KList<>(placement)); + locator.when(() -> IrisStructureLocator.resolvePlacement(any(), any(), anyInt(), anyInt())) + .thenThrow(new IllegalStateException("no viable graph")); + + component.generateLayer(writer, 4, -3, context); + component.generateLayer(writer, 5, -3, context); + } + + assertEquals(warnings.toString(), 1, warnings.size()); + } + + @Test + public void anEngineFailureFromAReplacementEscapes() { + IrisStructurePlacement placement = replacement(); + placement.getStructures().add("test:closed-city"); + GenerationClosedException closed = new GenerationClosedException("router closed"); + try (MockedStatic scope = mockStatic(StructurePlacementScope.class); + MockedStatic locator = mockStatic(IrisStructureLocator.class)) { + scope.when(() -> StructurePlacementScope.placementsAt(any(), anyInt(), anyInt())) + .thenReturn(new KList<>(placement)); + locator.when(() -> IrisStructureLocator.resolvePlacement(any(), any(), anyInt(), anyInt())).thenThrow(closed); + + assertSame(closed, assertThrows(GenerationClosedException.class, + () -> component.generateLayer(writer, 4, -3, context))); + } + } + + private static IrisStructurePlacement replacement() { + return new IrisStructurePlacement().setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE); + } + + private static IrisStructure structure(String key) { + IrisStructure structure = new IrisStructure().setPlaceMode(ObjectPlaceMode.STRUCTURE_PIECE); + structure.setLoadKey(key); + return structure; + } + + private static IrisObject object(String key) { + IrisObject object = mock(IrisObject.class); + when(object.getLoadKey()).thenReturn(key); + return object; + } + + private static KList pieces(IrisObject object, int count) { + KList pieces = new KList<>(); + for (int index = 0; index < count; index++) { + pieces.add(new PlacedStructurePiece(null, object, index * 16, 64, 0, IrisObjectRotation.of(0, 0, 0), + index * 16, 64, 0, index * 16 + 8, 70, 8)); + } + return pieces; + } +} diff --git a/core/src/test/java/art/arcane/iris/generation/runtime/GenerationFailuresTest.java b/core/src/test/java/art/arcane/iris/generation/runtime/GenerationFailuresTest.java index 6bdb9879f..1334b02b4 100644 --- a/core/src/test/java/art/arcane/iris/generation/runtime/GenerationFailuresTest.java +++ b/core/src/test/java/art/arcane/iris/generation/runtime/GenerationFailuresTest.java @@ -2,6 +2,7 @@ package art.arcane.iris.generation.runtime; import art.arcane.iris.generation.stream.ProvisionalAnswerException; import art.arcane.iris.world.history.SavedBiomeUnavailableException; +import art.arcane.volmlib.nativelib.terrain.NativePlacementFailures; import art.arcane.volmlib.util.mantle.MantleClosedException; import org.junit.Test; @@ -49,6 +50,28 @@ public class GenerationFailuresTest { "decoration", "minecraft:vine", 1, 2, 3, "test/biome"))); } + @Test + public void hydrologyPlanFailuresAreEngineFailuresEvenInsideAPlacementScope() { + HydrologyPlanException plan = new HydrologyPlanException("plan broke", new IllegalStateException("reach 7")); + assertTrue(GenerationFailures.isEngineFailure(plan)); + assertTrue(GenerationFailures.isEngineFailure(new IllegalStateException("decorator failed", plan))); + assertSame(plan, assertThrows(HydrologyPlanException.class, () -> GenerationFailures.skipPlacement(plan, + "decoration", "minecraft:vine", 1, 2, 3, "test/biome"))); + } + + @Test + public void nativePlacementFailuresFollowTheSameRule() { + GenerationFailures.bindNativeFailures(); + try { + NativePlacementFailures.skip(new IllegalArgumentException("bad feature"), "imported feature", "test:feature", 16, 32); + GenerationClosedException closed = new GenerationClosedException("router closed"); + assertSame(closed, assertThrows(GenerationClosedException.class, () -> NativePlacementFailures.skip(closed, + "imported feature", "test:feature", 16, 32))); + } finally { + NativePlacementFailures.register(null); + } + } + @Test public void skipWarningNamesBlockPositionBiomeAndFailureOnOneLine() { String line = GenerationFailures.skipWarning("decoration", "minecraft:vine", 1, 2, 3, "test/biome", diff --git a/core/src/test/java/art/arcane/iris/structure/placement/IrisStructureLocatorContractTest.java b/core/src/test/java/art/arcane/iris/structure/placement/IrisStructureLocatorContractTest.java index d7442b875..2edc14319 100644 --- a/core/src/test/java/art/arcane/iris/structure/placement/IrisStructureLocatorContractTest.java +++ b/core/src/test/java/art/arcane/iris/structure/placement/IrisStructureLocatorContractTest.java @@ -349,15 +349,15 @@ public class IrisStructureLocatorContractTest { } @Test - public void replacementOutputFailureIncludesStructureAndChunkContext() { + public void replacementOutputAbsenceIsSkippedInsteadOfStoppingTheChunk() { IrisStructurePlacement placement = new IrisStructurePlacement() .setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE); placement.getStructures().add("test:city"); - assertReplacementFailure( - () -> IrisStructureLocator.requirePlacementOutput( - placement, "test:city", 12, -7, false, "runtime assembly produced no pieces"), - "structure 'test:city' failed in chunk 12,-7: runtime assembly produced no pieces"); + assertFalse(IrisStructureLocator.placementOutput( + placement, "test:city", 12, -7, false, "no pieces", null)); + assertTrue(IrisStructureLocator.placementOutput( + placement, "test:city", 12, -7, true, "no pieces", null)); } @Test @@ -365,10 +365,10 @@ public class IrisStructureLocatorContractTest { IrisStructurePlacement placement = new IrisStructurePlacement(); placement.getStructures().add("test:city"); - assertFalse(IrisStructureLocator.requirePlacementOutput( - placement, "test:city", 12, -7, false, "runtime assembly produced no pieces")); - assertTrue(IrisStructureLocator.requirePlacementOutput( - placement, "test:city", 12, -7, true, "runtime assembly produced no pieces")); + assertFalse(IrisStructureLocator.placementOutput( + placement, "test:city", 12, -7, false, "no pieces", null)); + assertTrue(IrisStructureLocator.placementOutput( + placement, "test:city", 12, -7, true, "no pieces", null)); } @Test diff --git a/probe/src/test/java/art/arcane/iris/probe/ObjectContinuationProbeTest.java b/probe/src/test/java/art/arcane/iris/probe/ObjectContinuationProbeTest.java index 59defd749..cd3f6e450 100644 --- a/probe/src/test/java/art/arcane/iris/probe/ObjectContinuationProbeTest.java +++ b/probe/src/test/java/art/arcane/iris/probe/ObjectContinuationProbeTest.java @@ -3,6 +3,7 @@ package art.arcane.iris.probe; import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.EngineTarget; +import art.arcane.iris.generation.runtime.GenerationClosedException; import art.arcane.iris.generation.runtime.IrisEngine; import art.arcane.iris.generation.terrain.IrisDimension; import art.arcane.iris.pack.loading.IrisData; @@ -19,6 +20,7 @@ import art.arcane.iris.world.history.IrisBoundarySignatureSampler; import art.arcane.iris.world.history.NativeTerrainReceipt; import art.arcane.iris.world.history.SavedTerrainChunk; import art.arcane.volmlib.nativelib.terrain.NativeBlockState; +import art.arcane.volmlib.nativelib.terrain.NativePlacementFailures; import art.arcane.volmlib.util.mantle.runtime.MantleChunk; import art.arcane.volmlib.util.matter.Matter; import org.junit.AfterClass; @@ -43,6 +45,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; public final class ObjectContinuationProbeTest { @@ -179,11 +182,15 @@ public final class ObjectContinuationProbeTest { data.bindGenerationRegistryContract(reopened.activeEpoch().registryContract()); IrisDimension dimension = data.getDimensionLoader().load("transition"); assertNotNull(dimension); + NativePlacementFailures.register(null); IrisEngine engine = new IrisEngine(new EngineTarget(world, dimension, data), IrisEngine.InitializationMode.RUNTIME, reopened.paths().activationMantleRoot(reopened.activeActivation().activationId()), reopened.activeEpoch().kernelVersion(), reopened.transitionPlan(reopened.activeActivation().activationId())); try { + NativePlacementFailures.skip(new IllegalArgumentException("content"), "imported feature", "probe", 0, 0); + assertThrows(GenerationClosedException.class, () -> NativePlacementFailures.skip( + new GenerationClosedException("closed"), "imported feature", "probe", 0, 0)); GenerationHistoryRuntimeRouter router = GenerationHistoryRuntimeRouter.attach( engine, reopened, IrisBoundarySignatureSampler.INSTANCE); router.preloadActiveRuntimes();