mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Keep generating past failures
- REPLACE_SOURCE failures no longer stop the chunk: skip the piece or structure and warn once per structure and cause - Replace requirePlacementOutput with placementOutput and remove requireAppliedPieces - Key structure piece warnings on the structure, not the object - Register the VolmLib placement failure hook from IrisEngine, using the engine failure rule - Add HydrologyPlanException so a failed plan read inside a placement scope stops the chunk - Add modded containment tests, with source rules for the 26.2 and 1.21.1 test sources
This commit is contained in:
1 parent
d0923de181
commit
f4f7e92a4c
15 files changed
+689
-86
No files matched your search
+2
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PlacedStructurePiece> pieces, RNG rng) {
|
||||
IrisStructureStiltSettings stilt = placement.getStilt();
|
||||
PieceRun run = new PieceRun(structure, rng, stilt == null ? null : new Long2IntOpenHashMap(),
|
||||
stilt != null && stilt.isSupportNonOccluding(), placement.isAllowWater());
|
||||
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<PlacedStructurePiece> 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<PlacedStructurePiece> 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) {
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<PlacedStructurePiece> 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<PlacedStructurePiece> pieces, int worldMin, int worldMax,
|
||||
|
||||
+2
-1
@@ -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());
|
||||
}
|
||||
|
||||
+2
-34
@@ -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<PlacedStructurePiece> 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 + "'");
|
||||
}
|
||||
}
|
||||
+203
@@ -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<String> 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<PlacedStructurePiece> 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<StructurePlacementScope> scope = mockStatic(StructurePlacementScope.class);
|
||||
MockedStatic<IrisStructureLocator> 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<StructurePlacementScope> scope = mockStatic(StructurePlacementScope.class);
|
||||
MockedStatic<IrisStructureLocator> 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<PlacedStructurePiece> pieces(IrisObject object, int count) {
|
||||
KList<PlacedStructurePiece> 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;
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
+9
-9
@@ -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
|
||||
|
||||
Reference in new issue
Block a user