mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +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
+1
-1
@@ -159,7 +159,7 @@ public final class BukkitEnginePlatformHooks implements EnginePlatformHooks {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBypassMantleStages(Engine engine) {
|
||||
public boolean shouldRefuseGeneration(Engine engine) {
|
||||
if (!J.isFolia() || !engine.getWorld().hasPlatformWorld()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -60,9 +60,6 @@ public final class CustomModule implements IrisModule {
|
||||
|
||||
private static void record(ChunkStageContext context) {
|
||||
IrisChunk chunk = context.extension(IrisChunk.class).orElseThrow();
|
||||
if (chunk.bypassesMantleStages()) {
|
||||
return;
|
||||
}
|
||||
chunk.state(CustomBlockRecording.class, CustomBlockRecording::new).record(chunk.originX(), chunk.originZ(), chunk.blocks(), chunk.multicore());
|
||||
}
|
||||
|
||||
|
||||
@@ -90,9 +90,4 @@ public final class IrisChunk {
|
||||
public <T> T state(Class<T> type, Function<Engine, T> create) {
|
||||
return engine.getGeneration().state(type, create);
|
||||
}
|
||||
|
||||
/** Whether stages backed by the mantle skip this chunk, as maintenance regeneration on Folia requires. */
|
||||
public boolean bypassesMantleStages() {
|
||||
return engine.getGeneration().bypassesMantleStages();
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,7 @@ import java.util.function.BooleanSupplier;
|
||||
* The blocks Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#blocks()}: what object
|
||||
* and structure placements wrote into the mantle's block slice, read as IrisApi block states over the chunks one
|
||||
* invocation may touch. Stages only read them. A dimension that keeps no mantle ({@code useMantle: false}) holds none,
|
||||
* even where an older mantle file still has some, as Iris never copied those into chunks; neither does a chunk that
|
||||
* generates without its mantle (maintenance regeneration on Folia, {@link art.arcane.iris.engine.framework.EngineGeneration#bypassesMantleStages()}).
|
||||
* even where an older mantle file still has some, as Iris never copied those into chunks.
|
||||
*/
|
||||
final class PlannedBlocks implements MantleLayer<BlockState> {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
@@ -64,7 +63,7 @@ final class PlannedBlocks implements MantleLayer<BlockState> {
|
||||
/** The planned blocks of {@code engine}'s mantle in {@code bounds}, converted with the invocation's {@code states}. */
|
||||
static PlannedBlocks of(Engine engine, BlockBox bounds, IrisModuleMantle.Chunks chunks, PlatformBlockStates states) {
|
||||
return new PlannedBlocks(bounds, chunks, states,
|
||||
() -> engine.getDimension().isUseMantle() && !engine.getGeneration().bypassesMantleStages());
|
||||
() -> engine.getDimension().isUseMantle());
|
||||
}
|
||||
|
||||
/** No planned blocks in {@code bounds}, as in a dimension that keeps no mantle. */
|
||||
|
||||
@@ -81,6 +81,8 @@ import java.util.function.Supplier;
|
||||
@Data
|
||||
public class IrisEngine implements Engine {
|
||||
static final long SESSION_DRAIN_TIMEOUT_MILLIS = 15000L;
|
||||
private static final long MAINTENANCE_REFUSAL_WARNING_MILLIS = 5000L;
|
||||
private static final AtomicLong lastMaintenanceRefusalWarning = new AtomicLong();
|
||||
|
||||
private final AtomicInteger bud;
|
||||
private final AtomicInteger buds;
|
||||
@@ -632,6 +634,9 @@ public class IrisEngine implements Engine {
|
||||
@Override
|
||||
public void generate(int x, int z, Hunk<PlatformBlockState> vblocks, Hunk<PlatformBiome> vbiomes, boolean multicore) throws WrongEngineBroException {
|
||||
awaitGenerationCacheWarm();
|
||||
if (platformHooks.shouldRefuseGeneration(this)) {
|
||||
refuseMaintenanceGeneration(x >> 4, z >> 4);
|
||||
}
|
||||
try (GenerationSessionLease lease = acquireGenerationLease("chunk_generate");
|
||||
IrisContext.Scope generationScope = IrisContext.open(this, lease.sessionId(), null)) {
|
||||
getEngineData().getStatistics().generatedChunk();
|
||||
@@ -649,10 +654,7 @@ public class IrisEngine implements Engine {
|
||||
getGeneration().generate(x, z, blocks, vbiomes, multicore, lease.sessionId());
|
||||
}
|
||||
|
||||
boolean skipRealFlag = platformHooks.shouldBypassMantleStages(this);
|
||||
if (!skipRealFlag) {
|
||||
getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.REAL, true);
|
||||
}
|
||||
getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.REAL, true);
|
||||
getMetrics().getTotal().put(p.getMilliseconds());
|
||||
generated.incrementAndGet();
|
||||
|
||||
@@ -671,6 +673,17 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
}
|
||||
|
||||
private void refuseMaintenanceGeneration(int chunkX, int chunkZ) throws GenerationSessionException {
|
||||
long now = System.currentTimeMillis();
|
||||
long last = lastMaintenanceRefusalWarning.get();
|
||||
if (now - last >= MAINTENANCE_REFUSAL_WARNING_MILLIS && lastMaintenanceRefusalWarning.compareAndSet(last, now)) {
|
||||
IrisLogging.warn("Iris refused chunk " + chunkX + "," + chunkZ + " in " + getWorld().name()
|
||||
+ ": world maintenance forbids mantle generation, the chunk stays ungenerated");
|
||||
}
|
||||
throw new GenerationSessionException("Iris refused chunk " + chunkX + "," + chunkZ + " in "
|
||||
+ getWorld().name() + " during world maintenance.", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationSessionManager getGenerationSessions() {
|
||||
return generationSessions;
|
||||
|
||||
@@ -21,7 +21,6 @@ package art.arcane.iris.engine.framework;
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.core.modules.ModuleChunkGeneration;
|
||||
import art.arcane.iris.core.modules.ModuleWorlds;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
@@ -29,7 +28,6 @@ import art.arcane.iris.util.project.context.IrisContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.documentation.BlockCoordinates;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -40,8 +38,6 @@ import java.util.function.Function;
|
||||
*/
|
||||
public final class EngineGeneration {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final long MAINTENANCE_LOG_INTERVAL_MILLIS = 5000L;
|
||||
private static final AtomicLong lastMaintenanceBypassLog = new AtomicLong(0L);
|
||||
|
||||
private final Engine engine;
|
||||
private final ModuleWorlds modules;
|
||||
@@ -91,18 +87,6 @@ public final class EngineGeneration {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether stages backed by the mantle skip this chunk: on Folia, maintenance regeneration runs without the
|
||||
* mantle to stay region-safe.
|
||||
*/
|
||||
public boolean bypassesMantleStages() {
|
||||
boolean bypass = engine.getPlatformHooks().shouldBypassMantleStages(engine);
|
||||
if (bypass) {
|
||||
logMaintenanceBypass();
|
||||
}
|
||||
return bypass;
|
||||
}
|
||||
|
||||
/** Writes what modules saved with the world, as the engine saves its data; see {@link com.volmit.world.RunningWorld#saved}. */
|
||||
public void saveModuleData() {
|
||||
modules.saveCurrentWorldState();
|
||||
@@ -118,17 +102,6 @@ public final class EngineGeneration {
|
||||
}
|
||||
|
||||
private void generateMantle(int x, int z, boolean multicore, ChunkContext context) {
|
||||
if (bypassesMantleStages()) {
|
||||
return;
|
||||
}
|
||||
engine.getMantle().generateMatter(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT, multicore || engine.isStudio(), context);
|
||||
}
|
||||
|
||||
private static void logMaintenanceBypass() {
|
||||
long now = System.currentTimeMillis();
|
||||
long last = lastMaintenanceBypassLog.get();
|
||||
if (now - last >= MAINTENANCE_LOG_INTERVAL_MILLIS && lastMaintenanceBypassLog.compareAndSet(last, now)) {
|
||||
IrisLogging.info("Maintenance regen bypass: skipping mantle-backed stages for Folia safety.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,11 @@ public interface EnginePlatformHooks {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean shouldBypassMantleStages(Engine engine) {
|
||||
/**
|
||||
* True while world maintenance forbids the mantle-backed stages. Generating without them would persist a
|
||||
* chunk with no objects, caves or deposits, so the engine refuses the chunk instead.
|
||||
*/
|
||||
default boolean shouldRefuseGeneration(Engine engine) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -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