mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Added 1.21.1 mod targets
- Build Fabric, Forge and NeoForge per target listed in gradle/mod-targets.json (1.21.1, 26.3) - Add 1.21.1 adapter source overlays under adapters/*/src/versions/1.21.1 - Add verifyModdedMatrix and per-target Java runtime verification of loader jars - Re-inject persistent dimensions from the levels-ready hook before the watchdog starts - Wait for queued chunks and the final save before pregen completes - Add the 1.21.1 data version and datapack supported_formats range - Cascade regions whose sea or shore pool loses every biome - Use Gson calls available on the 1.21.1 runtime
This commit is contained in:
1 parent
0ca33068f3
commit
62062c4a95
58 files changed
+3279
-133
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModdedStartupLifecycleTest {
|
||||
@After
|
||||
public void resetStartup() {
|
||||
ModdedStartup.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoresAfterWorldsLoadWithoutRepeatingDuringServerTicks() {
|
||||
NativeModdedServer server = mock(NativeModdedServer.class);
|
||||
AtomicBoolean worldsRefreshed = new AtomicBoolean();
|
||||
when(server.refreshWorlds()).thenAnswer(invocation -> {
|
||||
worldsRefreshed.set(true);
|
||||
return Thread.currentThread();
|
||||
});
|
||||
when(server.hasPlayerList()).thenReturn(true);
|
||||
ModdedDimensionRegistryStore.PersistentDimension dimension =
|
||||
new ModdedDimensionRegistryStore.PersistentDimension("iris:moon", "overworld", "overworld", 1337L);
|
||||
|
||||
try (MockedStatic<ModdedStartup> startup = mockStatic(ModdedStartup.class, CALLS_REAL_METHODS);
|
||||
MockedStatic<ModdedDimensionRegistryStore> store = mockStatic(ModdedDimensionRegistryStore.class);
|
||||
MockedStatic<ModdedDimensionManager> manager = mockStatic(ModdedDimensionManager.class);
|
||||
MockedStatic<ModdedForcedDatapack> datapack = mockStatic(ModdedForcedDatapack.class);
|
||||
MockedStatic<ModdedMixinAudit> audit = mockStatic(ModdedMixinAudit.class);
|
||||
MockedStatic<ModdedIrisLog> log = mockStatic(ModdedIrisLog.class)) {
|
||||
startup.when(ModdedStartup::prepareForStartup).thenAnswer(invocation -> null);
|
||||
store.when(() -> ModdedDimensionRegistryStore.loadForStartup(server)).thenReturn(List.of(dimension));
|
||||
manager.when(() -> ModdedDimensionManager.restorePersistent(server, "iris:moon", "overworld", "overworld", 1337L))
|
||||
.thenAnswer(invocation -> {
|
||||
assertTrue(worldsRefreshed.get());
|
||||
return null;
|
||||
});
|
||||
|
||||
ModdedLifecycleCallbacks.create().levelsReady().accept(server);
|
||||
|
||||
manager.verify(() -> ModdedDimensionManager.restorePersistent(server, "iris:moon", "overworld", "overworld", 1337L));
|
||||
ModdedStartup.runOnce(server);
|
||||
ModdedStartup.runOnce(server);
|
||||
store.verify(() -> ModdedDimensionRegistryStore.loadForStartup(server), times(1));
|
||||
manager.verify(() -> ModdedDimensionManager.restorePersistent(server, "iris:moon", "overworld", "overworld", 1337L), times(1));
|
||||
datapack.verify(ModdedForcedDatapack::verifyInjected, times(1));
|
||||
audit.verify(ModdedMixinAudit::runOnce, times(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
+139
-1
@@ -3,14 +3,25 @@ package art.arcane.iris.modded.command;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.modded.ModdedGenPool;
|
||||
import art.arcane.iris.world.pregen.MantleHeapPressure;
|
||||
import art.arcane.iris.world.pregen.PregenListener;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativePregenRuntime;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativePregenRuntime.ChunkLoad;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -20,6 +31,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
@@ -31,6 +43,7 @@ import static org.mockito.Mockito.when;
|
||||
public class ModdedPregenMethodLifecycleTest {
|
||||
private MockedStatic<IrisSettings> settings;
|
||||
private NativePregenRuntime runtime;
|
||||
private Engine engine;
|
||||
private ModdedPregenMethod method;
|
||||
|
||||
@Before
|
||||
@@ -40,7 +53,7 @@ public class ModdedPregenMethodLifecycleTest {
|
||||
settings.when(IrisSettings::get).thenReturn(configured);
|
||||
runtime = mock(NativePregenRuntime.class);
|
||||
when(runtime.worldIdentity()).thenReturn("example:terrain");
|
||||
Engine engine = mock(Engine.class);
|
||||
engine = mock(Engine.class, RETURNS_DEEP_STUBS);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
method = new ModdedPregenMethod(new ModdedPregenMethod.Configuration(runtime, engine, true));
|
||||
}
|
||||
@@ -82,6 +95,131 @@ public class ModdedPregenMethodLifecycleTest {
|
||||
verify(runtime, never()).save();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void finalSaveWaitsForEveryCallbackBeyondFiveSeconds() throws Exception {
|
||||
CompletableFuture<ChunkLoad> load = new CompletableFuture<>();
|
||||
CompletableFuture<ChunkLoad> failedLoad = new CompletableFuture<>();
|
||||
PregenListener listener = mock(PregenListener.class);
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
when(runtime.isRunning()).thenReturn(true);
|
||||
when(runtime.loadChunk(2, 3)).thenReturn(load);
|
||||
when(runtime.loadChunk(4, 5)).thenReturn(failedLoad);
|
||||
doAnswer(call -> {
|
||||
call.getArgument(0, Runnable.class).run();
|
||||
return null;
|
||||
}).when(runtime).execute(any());
|
||||
try (MockedStatic<MantleHeapPressure> pressure = mockStatic(MantleHeapPressure.class)) {
|
||||
pressure.when(MantleHeapPressure::memoryBudgetBytes).thenReturn(512L << 20);
|
||||
method = new ModdedPregenMethod(new ModdedPregenMethod.Configuration(runtime, engine, false));
|
||||
method.generateChunk(2, 3, listener);
|
||||
method.generateChunk(4, 5, listener);
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
Future<?> closing = executor.submit(() -> {
|
||||
started.countDown();
|
||||
method.close();
|
||||
});
|
||||
assertTrue(started.await(5, TimeUnit.SECONDS));
|
||||
assertThrows(TimeoutException.class, () -> closing.get(6, TimeUnit.SECONDS));
|
||||
verify(runtime, never()).save();
|
||||
verify(engine, never()).syncGenerationHistory();
|
||||
load.complete(new ChunkLoad(true, null));
|
||||
assertThrows(TimeoutException.class, () -> closing.get(100, TimeUnit.MILLISECONDS));
|
||||
verify(runtime, never()).save();
|
||||
failedLoad.completeExceptionally(new IllegalStateException("chunk failed"));
|
||||
closing.get(5, TimeUnit.SECONDS);
|
||||
verify(listener).onChunkGenerated(2, 3);
|
||||
verify(listener).onChunkFailed(4, 5);
|
||||
verify(engine).syncGenerationHistory();
|
||||
verify(runtime).save();
|
||||
} finally {
|
||||
load.complete(new ChunkLoad(true, null));
|
||||
failedLoad.complete(new ChunkLoad(false, "chunk failed"));
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void interruptedCloseDrainsPendingChunksAndWaitsForFinalSave() throws Exception {
|
||||
CompletableFuture<ChunkLoad> load = new CompletableFuture<>();
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
AtomicReference<Thread> closingThread = new AtomicReference<>();
|
||||
AtomicReference<Runnable> queuedSave = new AtomicReference<>();
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
CountDownLatch saveQueued = new CountDownLatch(1);
|
||||
when(runtime.isRunning()).thenReturn(true);
|
||||
when(runtime.loadChunk(2, 3)).thenReturn(load);
|
||||
doAnswer(call -> {
|
||||
queuedSave.set(call.getArgument(0, Runnable.class));
|
||||
saveQueued.countDown();
|
||||
return null;
|
||||
}).when(runtime).execute(any());
|
||||
try (MockedStatic<MantleHeapPressure> pressure = mockStatic(MantleHeapPressure.class)) {
|
||||
pressure.when(MantleHeapPressure::memoryBudgetBytes).thenReturn(256L << 20);
|
||||
method = new ModdedPregenMethod(new ModdedPregenMethod.Configuration(runtime, engine, false));
|
||||
method.generateChunk(2, 3, mock(PregenListener.class));
|
||||
Future<Boolean> closing = executor.submit(() -> {
|
||||
closingThread.set(Thread.currentThread());
|
||||
started.countDown();
|
||||
method.close();
|
||||
return Thread.currentThread().isInterrupted();
|
||||
});
|
||||
assertTrue(started.await(5, TimeUnit.SECONDS));
|
||||
closingThread.get().interrupt();
|
||||
assertThrows(TimeoutException.class, () -> closing.get(100, TimeUnit.MILLISECONDS));
|
||||
verify(runtime, never()).save();
|
||||
verify(engine, never()).syncGenerationHistory();
|
||||
load.complete(new ChunkLoad(true, null));
|
||||
assertTrue(saveQueued.await(5, TimeUnit.SECONDS));
|
||||
assertThrows(TimeoutException.class, () -> closing.get(100, TimeUnit.MILLISECONDS));
|
||||
verify(runtime, never()).save();
|
||||
closingThread.get().interrupt();
|
||||
assertThrows(TimeoutException.class, () -> closing.get(100, TimeUnit.MILLISECONDS));
|
||||
queuedSave.get().run();
|
||||
assertTrue(closing.get(5, TimeUnit.SECONDS));
|
||||
verify(engine).syncGenerationHistory();
|
||||
verify(runtime).save();
|
||||
} finally {
|
||||
load.complete(new ChunkLoad(true, null));
|
||||
saveQueued.await(5, TimeUnit.SECONDS);
|
||||
Runnable pendingSave = queuedSave.get();
|
||||
if (pendingSave != null) {
|
||||
pendingSave.run();
|
||||
}
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverShutdownClaimsFinalSaveWithoutWaitingForPendingChunks() throws Exception {
|
||||
CompletableFuture<ChunkLoad> load = new CompletableFuture<>();
|
||||
PregenListener listener = mock(PregenListener.class);
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Thread serverThread = Thread.currentThread();
|
||||
when(runtime.isServerThread()).thenAnswer(call -> Thread.currentThread() == serverThread);
|
||||
when(runtime.isRunning()).thenReturn(true);
|
||||
when(runtime.loadChunk(2, 3)).thenReturn(load);
|
||||
try (MockedStatic<MantleHeapPressure> pressure = mockStatic(MantleHeapPressure.class)) {
|
||||
pressure.when(MantleHeapPressure::memoryBudgetBytes).thenReturn(256L << 20);
|
||||
method = new ModdedPregenMethod(new ModdedPregenMethod.Configuration(runtime, engine, false));
|
||||
method.generateChunk(2, 3, listener);
|
||||
Future<?> closing = executor.submit(method::close);
|
||||
assertThrows(TimeoutException.class, () -> closing.get(100, TimeUnit.MILLISECONDS));
|
||||
assertTrue(method.deferFinalSaveToServerThread());
|
||||
closing.get(5, TimeUnit.SECONDS);
|
||||
verify(runtime, never()).save();
|
||||
assertTrue(method.hasPendingFinalSave());
|
||||
method.completeDeferredFinalSave();
|
||||
verify(runtime).save();
|
||||
verify(runtime, never()).execute(any());
|
||||
} finally {
|
||||
load.complete(new ChunkLoad(true, null));
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedFinalSaveStillRestoresTheEmptyServerPauseSetting() {
|
||||
AtomicInteger pause = new AtomicInteger(60);
|
||||
|
||||
+23
@@ -8,6 +8,7 @@ import art.arcane.volmlib.nativelib.terrain.NativeWorld;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import org.junit.Test;
|
||||
@@ -66,4 +67,26 @@ public class NativeGeneratorOwnershipTest {
|
||||
assertNull(NativeWorldGenerators.find(world, IrisModdedChunkGenerator.class));
|
||||
assertFalse(nativeGenerator.represents(world));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void protocolLookupTracksInstalledGeneratorAndPolicyOwner() {
|
||||
IrisModdedChunkGenerator owner = new IrisModdedChunkGenerator(
|
||||
new NativeGeneratorContext(mock(BiomeSource.class), "example:surface"));
|
||||
NativeModdedChunkGenerator<?, ?, ?> nativeGenerator = (NativeModdedChunkGenerator<?, ?, ?>) owner.nativeGenerator();
|
||||
ServerLevel level = mock(ServerLevel.class);
|
||||
ServerChunkCache chunks = mock(ServerChunkCache.class);
|
||||
when(level.dimension()).thenReturn(Level.OVERWORLD);
|
||||
when(level.getChunkSource()).thenReturn(chunks);
|
||||
when(chunks.getGenerator()).thenReturn(nativeGenerator);
|
||||
NativeProtocolWorld world = new NativeProtocolWorld(level);
|
||||
|
||||
assertSame(owner, world.generator(IrisModdedChunkGenerator.class));
|
||||
assertSame(nativeGenerator, world.generator(ChunkGenerator.class));
|
||||
assertNull(world.generator(String.class));
|
||||
|
||||
ChunkGenerator replacement = mock(ChunkGenerator.class);
|
||||
when(chunks.getGenerator()).thenReturn(replacement);
|
||||
assertNull(world.generator(IrisModdedChunkGenerator.class));
|
||||
assertSame(replacement, world.generator(ChunkGenerator.class));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user