mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Refuse chunk generation while world maintenance forbids mantle stages
Folia maintenance used to generate chunks with the mantle stages skipped and then persist them without objects, caves or deposits. The engine now refuses the chunk with an expected-teardown session exception and warns at most every 5 seconds, so the chunk stays ungenerated. The REAL flag is set unconditionally.
Upstream: ea516b4a5
This commit is contained in:
1 parent
a81a3abb9f
commit
fc5c6ce0ab
9 files changed
+88
-61
No files matched your search
@@ -20,7 +20,6 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
@@ -68,7 +67,7 @@ public class PlannedBlocksTest {
|
||||
public void placementsBlocksReadInWorldCoordinatesInVisitOrder() {
|
||||
plan(20, 10, 33, planks);
|
||||
plan(17, 40, 35, planks);
|
||||
PlannedBlocks blocks = planned(true, false);
|
||||
PlannedBlocks blocks = planned(true);
|
||||
List<String> visited = new ArrayList<>();
|
||||
|
||||
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(x + "," + y + "," + z + " " + block.key()));
|
||||
@@ -79,20 +78,20 @@ public class PlannedBlocksTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDimensionWithoutAMantleOrAChunkWithoutItPlansNothing() {
|
||||
public void aDimensionWithoutAMantlePlansNothing() {
|
||||
plan(20, 10, 33, planks);
|
||||
PlannedBlocks blocks = planned(false);
|
||||
List<BlockState> visited = new ArrayList<>();
|
||||
|
||||
for (PlannedBlocks blocks : List.of(planned(false, false), planned(true, true))) {
|
||||
List<BlockState> visited = new ArrayList<>();
|
||||
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(block));
|
||||
assertEquals(List.of(), visited);
|
||||
assertNull(blocks.get(20, 10, 33));
|
||||
}
|
||||
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(block));
|
||||
|
||||
assertEquals(List.of(), visited);
|
||||
assertNull(blocks.get(20, 10, 33));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stagesCannotPlanBlocks() {
|
||||
MantleLayer<BlockState> blocks = planned(true, false);
|
||||
MantleLayer<BlockState> blocks = planned(true);
|
||||
BlockState stone = BlockState.parse("minecraft:stone");
|
||||
|
||||
assertThrows(UnsupportedOperationException.class, () -> blocks.set(20, 10, 33, stone));
|
||||
@@ -106,7 +105,7 @@ public class PlannedBlocksTest {
|
||||
PlatformBlockState vanilla = UsableBlockPlatform.block("minecraft:note_block");
|
||||
plan(20, 10, 33, custom);
|
||||
PlatformBlockStates states = new PlatformBlockStates(key -> vanilla);
|
||||
PlannedBlocks blocks = PlannedBlocks.of(engine(true, false), CHUNK, mantle::chunk, states);
|
||||
PlannedBlocks blocks = PlannedBlocks.of(engine(true), CHUNK, mantle::chunk, states);
|
||||
Hunk<PlatformBlockState> chunk = Hunk.newArrayHunk(16, SECTIONS * 16, 16);
|
||||
BlockStateHunk hunk = new BlockStateHunk(chunk, states);
|
||||
|
||||
@@ -121,18 +120,15 @@ public class PlannedBlocksTest {
|
||||
mantle.chunk(x >> 4, z >> 4).getOrCreate(y >> 4).slice(PlatformBlockState.class).set(x & 15, y & 15, z & 15, block);
|
||||
}
|
||||
|
||||
private PlannedBlocks planned(boolean useMantle, boolean bypass) {
|
||||
return PlannedBlocks.of(engine(useMantle, bypass), CHUNK, mantle::chunk, new PlatformBlockStates(UsableBlockPlatform::block));
|
||||
private PlannedBlocks planned(boolean useMantle) {
|
||||
return PlannedBlocks.of(engine(useMantle), CHUNK, mantle::chunk, new PlatformBlockStates(UsableBlockPlatform::block));
|
||||
}
|
||||
|
||||
private static Engine engine(boolean useMantle, boolean bypass) {
|
||||
private static Engine engine(boolean useMantle) {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.isUseMantle()).thenReturn(useMantle);
|
||||
EngineGeneration generation = mock(EngineGeneration.class);
|
||||
when(generation.bypassesMantleStages()).thenReturn(bypass);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getGeneration()).thenReturn(generation);
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package art.arcane.iris.engine;
|
||||
|
||||
import art.arcane.iris.engine.framework.EnginePlatformHooks;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionException;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
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.doCallRealMethod;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisEngineMaintenanceRefusalTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void maintenanceThatCannotRunMantleStagesRefusesTheChunkInsteadOfGeneratingIt() throws Exception {
|
||||
IrisEngine engine = mock(IrisEngine.class);
|
||||
EnginePlatformHooks hooks = mock(EnginePlatformHooks.class);
|
||||
when(hooks.shouldRefuseGeneration(engine)).thenReturn(true);
|
||||
Field platformHooks = IrisEngine.class.getDeclaredField("platformHooks");
|
||||
platformHooks.setAccessible(true);
|
||||
platformHooks.set(engine, hooks);
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(world.name()).thenReturn("world");
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
doCallRealMethod().when(engine).generate(anyInt(), anyInt(), any(), any(), anyBoolean());
|
||||
Hunk<PlatformBlockState> blocks = mock(Hunk.class);
|
||||
Hunk<PlatformBiome> biomes = mock(Hunk.class);
|
||||
|
||||
GenerationSessionException refused = assertThrows(GenerationSessionException.class,
|
||||
() -> engine.generate(32, 48, blocks, biomes, false));
|
||||
|
||||
assertTrue(refused.isExpectedTeardown());
|
||||
verify(engine, never()).acquireGenerationLease(anyString());
|
||||
verifyNoInteractions(blocks, biomes);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user