mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +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,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