mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Improve generation and lifecycle safety
- Reduce terrain, noise, hydrology, and decorator sampling overhead. - Reduce object transaction allocations while preserving rollback behavior. - Optimize structure placement and cave anchor sampling. - Parallelize Studio cache warmup and protect world entry and hotload recovery. - Validate pack fingerprints and publish pack replacements atomically. - Notify modded operators about outdated packs without synchronizing pack data. - Harden world creation, loading, evacuation, and teleport failure recovery. - Coalesce queued region flushes while preserving chunk save ordering. - Remove obsolete mantle, pack, and cave planning code. - Add regression tests and reusable gameplay fixtures.
This commit is contained in:
1 parent
a2bcd7a302
commit
7f5ce70f49
197 files changed
+7560
-4420
No files matched your search
+31
@@ -39,6 +39,37 @@ public class ModdedClientPackageIsolationTest {
|
||||
"art/arcane/iris/nativegen");
|
||||
private static final int MINIMUM_SCANNED = 50;
|
||||
|
||||
@Test
|
||||
public void clientPresentationCannotAccessPackOrWorldPersistence() throws IOException, URISyntaxException {
|
||||
Path root = classesRoot();
|
||||
Path directory = root.resolve(CLIENT_IRIS);
|
||||
List<String> forbidden = List.of(
|
||||
"art/arcane/iris/pack/",
|
||||
"art/arcane/iris/world/storage/",
|
||||
"art/arcane/iris/world/history/",
|
||||
"art/arcane/iris/generation/runtime/",
|
||||
"art/arcane/iris/configuration/",
|
||||
"java/nio/file/",
|
||||
"java/nio/channels/FileChannel",
|
||||
"java/io/File",
|
||||
"java/io/RandomAccessFile");
|
||||
List<String> violations = new ArrayList<>();
|
||||
int scanned = 0;
|
||||
try (Stream<Path> walk = Files.walk(directory)) {
|
||||
for (Path classFile : walk.filter(ModdedClientPackageIsolationTest::isClassFile).toList()) {
|
||||
scanned++;
|
||||
String bytecode = readAsLatin1(classFile);
|
||||
for (String dependency : forbidden) {
|
||||
if (bytecode.contains(dependency)) {
|
||||
violations.add(root.relativize(classFile) + " -> " + dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("client presentation classes were not scanned", scanned >= 20);
|
||||
assertEquals("client presentation can access persistent generation data: " + violations, List.of(), violations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverSidePackagesNeverReferenceClientOnlyTypes() throws IOException, URISyntaxException {
|
||||
Path root = classesRoot();
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeBlockFaces;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.hunk.Hunk;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModdedDecoratorHooksTest {
|
||||
@Test
|
||||
public void faceFixingExcludesTheUpperBoundaryWhileKeepingTheLastRowAccessible() {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
NativeBlockState lastRow = mock(NativeBlockState.class);
|
||||
Hunk<NativeBlockState> hunk = mock(Hunk.class);
|
||||
when(hunk.getHeight()).thenReturn(4);
|
||||
when(hunk.get(1, 3, 2)).thenReturn(lastRow);
|
||||
when(hunk.get(1, 4, 2)).thenThrow(new IndexOutOfBoundsException("upper boundary"));
|
||||
try (MockedStatic<NativeBlockFaces> faces = mockStatic(NativeBlockFaces.class)) {
|
||||
faces.when(() -> NativeBlockFaces.fixFaces(eq(state), any(NativeBlockFaces.Neighbors.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
NativeBlockFaces.Neighbors neighbors = invocation.getArgument(1);
|
||||
assertNull(neighbors.secondary(0, 1, 0));
|
||||
assertSame(lastRow, neighbors.secondary(0, 0, 0));
|
||||
return state;
|
||||
});
|
||||
|
||||
assertSame(state, new ModdedDecoratorHooks().fixFaces(state, hunk, 1, 2, 99, 3, 108, null));
|
||||
|
||||
faces.verify(() -> NativeBlockFaces.fixFaces(eq(state), any(NativeBlockFaces.Neighbors.class)));
|
||||
}
|
||||
verify(hunk, never()).get(1, 4, 2);
|
||||
verify(hunk).get(1, 3, 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class ModdedGenPoolTest {
|
||||
@Test
|
||||
public void executorLookupDoesNotRestartStoppedPool() throws Exception {
|
||||
ModdedGenPool.start();
|
||||
ExecutorService original = ModdedGenPool.pool();
|
||||
ModdedGenPool.shutdown();
|
||||
try {
|
||||
ModdedGenPool.pool();
|
||||
fail("Stopped generation pool must reject executor lookup");
|
||||
} catch (RejectedExecutionException expected) {
|
||||
assertTrue(original.isShutdown());
|
||||
}
|
||||
ModdedGenPool.start();
|
||||
try {
|
||||
assertNotSame(original, ModdedGenPool.pool());
|
||||
} finally {
|
||||
ModdedGenPool.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restartWaitsForPreviousWorkersToTerminate() throws Exception {
|
||||
ModdedGenPool.start();
|
||||
ExecutorService original = ModdedGenPool.pool();
|
||||
CountDownLatch entered = new CountDownLatch(1);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
original.execute(() -> {
|
||||
entered.countDown();
|
||||
boolean released = false;
|
||||
while (!released) {
|
||||
try {
|
||||
release.await();
|
||||
released = true;
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.interrupted();
|
||||
}
|
||||
}
|
||||
});
|
||||
assertTrue(entered.await(5L, TimeUnit.SECONDS));
|
||||
try {
|
||||
Thread.currentThread().interrupt();
|
||||
ModdedGenPool.shutdown();
|
||||
assertTrue(Thread.interrupted());
|
||||
assertFalse(original.isTerminated());
|
||||
try {
|
||||
ModdedGenPool.start();
|
||||
fail("Generation pool must retain workers until they terminate");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertFalse(original.isTerminated());
|
||||
}
|
||||
} finally {
|
||||
Thread.interrupted();
|
||||
release.countDown();
|
||||
assertTrue(original.awaitTermination(5L, TimeUnit.SECONDS));
|
||||
ModdedGenPool.start();
|
||||
assertNotSame(original, ModdedGenPool.pool());
|
||||
ExecutorService restarted = ModdedGenPool.pool();
|
||||
ModdedGenPool.start();
|
||||
assertSame(restarted, ModdedGenPool.pool());
|
||||
ModdedGenPool.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.modded.command.ModdedPackCommands;
|
||||
import art.arcane.iris.pack.BrokenPackException;
|
||||
import art.arcane.iris.pack.PackValidationRegistry;
|
||||
import art.arcane.iris.pack.PackValidationResult;
|
||||
import art.arcane.iris.pack.PackValidator;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class ModdedPackValidationPublicationTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@After
|
||||
public void clearValidation() {
|
||||
PackValidationRegistry.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validationPublishesTheCanonicalRootAndPackName() throws Exception {
|
||||
File root = temporaryFolder.newFolder("terrain");
|
||||
File equivalent = new File(root, ".");
|
||||
PackValidationResult result = loadable(root);
|
||||
try (MockedStatic<PackValidator> validator = mockStatic(PackValidator.class)) {
|
||||
validator.when(() -> PackValidator.validate(equivalent)).thenReturn(result);
|
||||
|
||||
assertSame(result, ModdedStartup.validatePack(equivalent));
|
||||
|
||||
assertSame(result, PackValidationRegistry.requireLoadable(root.toPath()));
|
||||
assertSame(result, PackValidationRegistry.requireLoadable(root.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootInvalidationCannotReusePackNameValidation() throws Exception {
|
||||
File root = temporaryFolder.newFolder("terrain");
|
||||
PackValidationRegistry.publish(loadable(root));
|
||||
PackValidationResult replacement = loadable(root);
|
||||
try (MockedStatic<PackValidator> validator = mockStatic(PackValidator.class);
|
||||
MockedStatic<ModdedPackCommands> commands = mockStatic(ModdedPackCommands.class)) {
|
||||
commands.when(ModdedPackCommands::packsRoot).thenReturn(root.getParentFile());
|
||||
validator.when(() -> PackValidator.validate(root)).thenReturn(replacement);
|
||||
|
||||
assertSame(replacement, ModdedStartup.requirePackForWorldCreation(root.getName()));
|
||||
|
||||
validator.verify(() -> PackValidator.validate(root));
|
||||
assertSame(replacement, PackValidationRegistry.requireLoadable(root.toPath()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changedContentWithPreservedTimestampCannotReuseValidation() throws Exception {
|
||||
File root = temporaryFolder.newFolder("terrain");
|
||||
File content = new File(root, "dimension.json");
|
||||
Files.writeString(content.toPath(), "valid");
|
||||
PackValidationResult original = loadable(root);
|
||||
PackValidationResult broken = new PackValidationResult(root.getName(), List.of("invalid"), List.of(),
|
||||
System.currentTimeMillis());
|
||||
try (MockedStatic<PackValidator> validator = mockStatic(PackValidator.class);
|
||||
MockedStatic<ModdedPackCommands> commands = mockStatic(ModdedPackCommands.class)) {
|
||||
commands.when(ModdedPackCommands::packsRoot).thenReturn(root.getParentFile());
|
||||
validator.when(() -> PackValidator.validate(root)).thenReturn(original, broken);
|
||||
ModdedStartup.validatePack(root);
|
||||
Files.writeString(content.toPath(), "wrong");
|
||||
Files.setLastModifiedTime(content.toPath(), FileTime.fromMillis(1L));
|
||||
Files.setLastModifiedTime(root.toPath(), FileTime.fromMillis(1L));
|
||||
|
||||
assertThrows(BrokenPackException.class,
|
||||
() -> ModdedStartup.requirePackForWorldCreation(root.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalEditDuringValidationCannotPublishMixedSnapshot() throws Exception {
|
||||
File root = temporaryFolder.newFolder("terrain");
|
||||
File content = new File(root, "dimension.json");
|
||||
Files.writeString(content.toPath(), "original");
|
||||
try (MockedStatic<PackValidator> validator = mockStatic(PackValidator.class)) {
|
||||
validator.when(() -> PackValidator.validate(root)).thenAnswer(invocation -> {
|
||||
Files.writeString(content.toPath(), "changed");
|
||||
return loadable(root);
|
||||
});
|
||||
|
||||
assertThrows(BrokenPackException.class, () -> ModdedStartup.validatePack(root));
|
||||
assertNull(PackValidationRegistry.get(root.toPath()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mutationDuringValidationPreventsStalePublication() throws Exception {
|
||||
File root = temporaryFolder.newFolder("terrain");
|
||||
try (MockedStatic<PackValidator> validator = mockStatic(PackValidator.class)) {
|
||||
validator.when(() -> PackValidator.validate(root)).thenAnswer(invocation -> {
|
||||
try (PackValidationRegistry.RootMutation mutation = PackValidationRegistry.beginRootMutation(root.toPath())) {
|
||||
return loadable(root);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
ModdedStartup.validatePack(root);
|
||||
fail("Changed pack must reject stale validation");
|
||||
} catch (BrokenPackException expected) {
|
||||
assertNull(PackValidationRegistry.get(root.toPath()));
|
||||
assertNull(PackValidationRegistry.get(root.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validationFailurePublishesBlockedRoot() throws Exception {
|
||||
File root = temporaryFolder.newFolder("terrain");
|
||||
try (MockedStatic<PackValidator> validator = mockStatic(PackValidator.class);
|
||||
MockedStatic<ModdedIrisLog> log = mockStatic(ModdedIrisLog.class)) {
|
||||
validator.when(() -> PackValidator.validate(root)).thenThrow(new IllegalStateException("Invalid terrain"));
|
||||
|
||||
PackValidationResult result = ModdedStartup.validatePack(root);
|
||||
|
||||
assertFalse(result.isLoadable());
|
||||
assertSame(result, PackValidationRegistry.get(root.toPath()));
|
||||
assertSame(result, PackValidationRegistry.get(root.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private static PackValidationResult loadable(File root) {
|
||||
return new PackValidationResult(root.getName(), List.of(), List.of(), System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
+44
@@ -4,7 +4,10 @@ import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedServer;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeProtocolPlayer;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldTeleport;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeWorld;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
@@ -38,6 +41,12 @@ public class ModdedPrimaryWorldRouterTest {
|
||||
private static final int TICK_INTERVAL = 20;
|
||||
private static final String PRIMARY = "iris:primary";
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearRouter() {
|
||||
ModdedPrimaryWorldRouter.clear();
|
||||
@@ -233,6 +242,41 @@ public class ModdedPrimaryWorldRouterTest {
|
||||
return new ModdedDimensionRegistryStore.PersistentDimension(PRIMARY, "overworld", "overworld", 1337L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disconnectCancelsOldRoutingWithoutAffectingReconnectedPlayer() {
|
||||
NativeModdedServer server = mock(NativeModdedServer.class);
|
||||
NativeWorld overworld = mock(NativeWorld.class);
|
||||
NativeWorld primary = mock(NativeWorld.class);
|
||||
when(overworld.nativeHandle()).thenReturn(new Object());
|
||||
when(primary.nativeHandle()).thenReturn(new Object());
|
||||
when(server.overworld()).thenReturn(overworld);
|
||||
NativeProtocolPlayer player = mock(NativeProtocolPlayer.class);
|
||||
UUID id = UUID.randomUUID();
|
||||
when(player.id()).thenReturn(id);
|
||||
when(player.isInWorld(overworld)).thenReturn(true);
|
||||
onlinePlayers(server, player);
|
||||
CompletableFuture<Boolean> oldRoute = new CompletableFuture<>();
|
||||
CompletableFuture<Boolean> newRoute = new CompletableFuture<>();
|
||||
ModdedModConfig config = config(true, PRIMARY);
|
||||
try (MockedStatic<ModdedModConfig> configs = mockStatic(ModdedModConfig.class);
|
||||
MockedStatic<ModdedDimensionManager> manager = mockStatic(ModdedDimensionManager.class);
|
||||
MockedStatic<NativeWorldTeleport> teleport = mockStatic(NativeWorldTeleport.class)) {
|
||||
configs.when(ModdedModConfig::get).thenReturn(config);
|
||||
manager.when(() -> ModdedDimensionManager.level(server, PRIMARY)).thenReturn(primary);
|
||||
teleport.when(() -> NativeWorldTeleport.teleport(any(), any())).thenReturn(oldRoute, newRoute);
|
||||
evaluate(server);
|
||||
ModdedPrimaryWorldRouter.forget(id);
|
||||
assertTrue(oldRoute.isCancelled());
|
||||
evaluate(server);
|
||||
oldRoute.complete(true);
|
||||
evaluate(server);
|
||||
teleport.verify(() -> NativeWorldTeleport.teleport(any(), any()), times(2));
|
||||
assertFalse(newRoute.isDone());
|
||||
ModdedPrimaryWorldRouter.clear();
|
||||
assertTrue(newRoute.isCancelled());
|
||||
}
|
||||
}
|
||||
|
||||
private static void evaluate(NativeModdedServer server) {
|
||||
for (int tick = 0; tick < TICK_INTERVAL; tick++) {
|
||||
ModdedPrimaryWorldRouter.tick(server);
|
||||
|
||||
+5
@@ -57,6 +57,11 @@ public class ModdedStartupReinjectFailureTest {
|
||||
NativeProtocolPlayer player = mock(NativeProtocolPlayer.class);
|
||||
ModdedStartup.warnStartupFailuresTo(operator);
|
||||
ModdedStartup.warnStartupFailuresTo(player);
|
||||
NativeProtocolPlayer owner = mock(NativeProtocolPlayer.class);
|
||||
when(owner.isServerOwner()).thenReturn(true);
|
||||
ModdedStartup.warnStartupFailuresTo(owner);
|
||||
verify(owner).sendMessage(argThat((String message) -> message.contains("iris:moon")
|
||||
&& message.contains("generation history is unusable")));
|
||||
|
||||
verify(operator).sendMessage(argThat((String message) -> message.contains("iris:moon")
|
||||
&& message.contains("generation history is unusable")));
|
||||
|
||||
+3
@@ -21,6 +21,8 @@ import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
@@ -98,6 +100,7 @@ public class IrisModdedCommandsTeleportTest {
|
||||
when(server.getLevel(dimension)).thenReturn(serverLevel);
|
||||
ServerPlayer serverPlayer = mock(ServerPlayer.class);
|
||||
when(serverPlayer.getUUID()).thenReturn(UUID.randomUUID());
|
||||
when(serverPlayer.getDimensions(Pose.STANDING)).thenReturn(EntityDimensions.scalable(0.6F, 1.8F));
|
||||
NativeWorld level = mock(NativeWorld.class);
|
||||
when(level.nativeHandle()).thenReturn(serverLevel);
|
||||
|
||||
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
package art.arcane.iris.modded.service;
|
||||
|
||||
import art.arcane.iris.diagnostics.splash.IrisSplashPackScanner.SplashPackMetadata;
|
||||
import art.arcane.iris.pack.BuiltInPackUpdates;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedServer;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeProtocolPlayer;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.permissions.LevelBasedPermissionSet;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModdedPackUpdateServiceTest {
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pendingCheckNotifiesOnlineAndLaterOperatorsOnceOnServerTick() {
|
||||
CompletableFuture<ModdedPackUpdateService.PackCheck> pending = new CompletableFuture<>();
|
||||
ModdedPackUpdateService service = new ModdedPackUpdateService(folder -> pending);
|
||||
NativeProtocolPlayer online = player(true, false);
|
||||
NativeModdedServer server = server(online);
|
||||
File root = new File("config/irisworldgen/packs").getAbsoluteFile();
|
||||
try (MockedStatic<IrisPlatforms> platforms = platform(root)) {
|
||||
service.onEnable();
|
||||
service.onServerTick(server);
|
||||
service.notifyPlayer(online);
|
||||
verify(online, never()).sendMessage(anyString());
|
||||
pending.complete(outdated());
|
||||
verify(online, never()).sendMessage(anyString());
|
||||
service.onServerTick(server);
|
||||
service.onServerTick(server);
|
||||
service.notifyPlayer(online);
|
||||
verify(online, times(1)).sendMessage(contains("installed v1, latest built-in release v2"));
|
||||
verify(online, times(1)).sendMessage(contains(new File(root, "overworld").toString()));
|
||||
verify(online, times(1)).sendMessage(contains("/iris download pack=overworld overwrite=true"));
|
||||
verify(online, never()).sendMessage(contains("plugins/"));
|
||||
NativeProtocolPlayer later = player(true, false);
|
||||
service.notifyPlayer(later);
|
||||
verify(later).sendMessage(contains("release metadata is outdated"));
|
||||
service.onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integratedOwnerWithoutCheatsReceivesNoticeAndRemoteOrdinaryPlayersDoNot() {
|
||||
NativeProtocolPlayer owner = player(false, true);
|
||||
NativeProtocolPlayer remote = player(false, false);
|
||||
ModdedPackUpdateService service = new ModdedPackUpdateService(folder -> CompletableFuture.completedFuture(outdated()));
|
||||
try (MockedStatic<IrisPlatforms> platforms = platform(new File("config/irisworldgen/packs"))) {
|
||||
service.onEnable();
|
||||
service.onServerTick(server(owner));
|
||||
verify(owner).sendMessage(contains("release metadata is outdated"));
|
||||
service.notifyPlayer(remote);
|
||||
verify(remote, never()).sendMessage(anyString());
|
||||
service.onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disableCancelsCheckAndRestartDoesNotPublishOldNotices() {
|
||||
CompletableFuture<ModdedPackUpdateService.PackCheck> first = new CompletableFuture<>();
|
||||
CompletableFuture<ModdedPackUpdateService.PackCheck> second = new CompletableFuture<>();
|
||||
AtomicInteger checks = new AtomicInteger();
|
||||
ModdedPackUpdateService service = new ModdedPackUpdateService(folder -> checks.getAndIncrement() == 0 ? first : second);
|
||||
NativeProtocolPlayer operator = player(true, false);
|
||||
NativeModdedServer server = server(operator);
|
||||
try (MockedStatic<IrisPlatforms> platforms = platform(new File("config/irisworldgen/packs"))) {
|
||||
service.onEnable();
|
||||
service.onServerTick(server);
|
||||
service.onDisable();
|
||||
assertTrue(first.isCancelled());
|
||||
assertFalse(first.complete(outdated()));
|
||||
service.onEnable();
|
||||
service.onServerTick(server);
|
||||
second.complete(new ModdedPackUpdateService.PackCheck(List.of(), Map.of()));
|
||||
service.onServerTick(server);
|
||||
verify(operator, never()).sendMessage(anyString());
|
||||
assertEquals(2, checks.get());
|
||||
service.onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentCustomUnknownAndUnavailableVersionsNeverBecomeOutdated() {
|
||||
ModdedPackUpdateService.PackCheck result = new ModdedPackUpdateService.PackCheck(List.of(
|
||||
new SplashPackMetadata("overworld", "unknown"),
|
||||
new SplashPackMetadata("underworld", "3"),
|
||||
new SplashPackMetadata("custom", "1")), Map.of(
|
||||
"overworld", new BuiltInPackUpdates.Update("2"),
|
||||
"underworld", new BuiltInPackUpdates.Update("2")));
|
||||
ModdedPackUpdateService service = new ModdedPackUpdateService(folder -> CompletableFuture.completedFuture(result));
|
||||
NativeProtocolPlayer operator = player(true, false);
|
||||
try (MockedStatic<IrisPlatforms> platforms = platform(new File("config/irisworldgen/packs"))) {
|
||||
service.onEnable();
|
||||
service.onServerTick(server(operator));
|
||||
verify(operator, never()).sendMessage(anyString());
|
||||
service.onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successfulAuthoringUpdateClearsOldNoticesAndRescansInstalledVersion() {
|
||||
CompletableFuture<ModdedPackUpdateService.PackCheck> current = new CompletableFuture<>();
|
||||
AtomicInteger checks = new AtomicInteger();
|
||||
ModdedPackUpdateService service = new ModdedPackUpdateService(folder -> checks.getAndIncrement() == 0
|
||||
? CompletableFuture.completedFuture(outdated()) : current);
|
||||
NativeProtocolPlayer operator = player(true, false);
|
||||
NativeModdedServer server = server(operator);
|
||||
try (MockedStatic<IrisPlatforms> platforms = platform(new File("config/irisworldgen/packs"))) {
|
||||
service.onEnable();
|
||||
service.onServerTick(server);
|
||||
verify(operator).sendMessage(contains("release metadata is outdated"));
|
||||
service.refresh();
|
||||
NativeProtocolPlayer later = player(true, false);
|
||||
service.notifyPlayer(later);
|
||||
verify(later, never()).sendMessage(anyString());
|
||||
service.onServerTick(server);
|
||||
current.complete(new ModdedPackUpdateService.PackCheck(List.of(new SplashPackMetadata("overworld", "2")),
|
||||
Map.of("overworld", new BuiltInPackUpdates.Update("2"))));
|
||||
service.onServerTick(server);
|
||||
service.notifyPlayer(later);
|
||||
verify(later, never()).sendMessage(anyString());
|
||||
assertEquals(2, checks.get());
|
||||
service.onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeOwnerCheckDoesNotGrantGameMasterPermissions() {
|
||||
ServerPlayer handle = mock(ServerPlayer.class);
|
||||
ServerLevel level = mock(ServerLevel.class);
|
||||
MinecraftServer server = mock(MinecraftServer.class);
|
||||
when(handle.level()).thenReturn(level);
|
||||
when(level.getServer()).thenReturn(server);
|
||||
when(handle.permissions()).thenReturn(LevelBasedPermissionSet.ALL);
|
||||
NativeProtocolPlayer player = NativeProtocolPlayer.fromHandle(handle);
|
||||
when(server.isSingleplayerOwner(handle.nameAndId())).thenReturn(true);
|
||||
assertTrue(player.isServerOwner());
|
||||
assertFalse(player.isGameMaster());
|
||||
when(server.isSingleplayerOwner(handle.nameAndId())).thenReturn(false);
|
||||
assertFalse(player.isServerOwner());
|
||||
assertFalse(player.isGameMaster());
|
||||
}
|
||||
|
||||
private static ModdedPackUpdateService.PackCheck outdated() {
|
||||
return new ModdedPackUpdateService.PackCheck(List.of(new SplashPackMetadata("overworld", "1")),
|
||||
Map.of("overworld", new BuiltInPackUpdates.Update("2")));
|
||||
}
|
||||
|
||||
private static MockedStatic<IrisPlatforms> platform(File root) {
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(platform.packsFolderNoCreate()).thenReturn(root);
|
||||
MockedStatic<IrisPlatforms> platforms = mockStatic(IrisPlatforms.class);
|
||||
platforms.when(IrisPlatforms::get).thenReturn(platform);
|
||||
return platforms;
|
||||
}
|
||||
|
||||
private static NativeProtocolPlayer player(boolean operator, boolean owner) {
|
||||
NativeProtocolPlayer player = mock(NativeProtocolPlayer.class);
|
||||
when(player.id()).thenReturn(UUID.randomUUID());
|
||||
when(player.connected()).thenReturn(true);
|
||||
when(player.isGameMaster()).thenReturn(operator);
|
||||
when(player.isServerOwner()).thenReturn(owner);
|
||||
return player;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static NativeModdedServer server(NativeProtocolPlayer player) {
|
||||
NativeModdedServer server = mock(NativeModdedServer.class);
|
||||
when(server.hasPlayerList()).thenReturn(true);
|
||||
doAnswer(invocation -> {
|
||||
invocation.getArgument(0, Consumer.class).accept(player);
|
||||
return null;
|
||||
}).when(server).forEachPlayer(any());
|
||||
return server;
|
||||
}
|
||||
}
|
||||
+57
@@ -4,14 +4,65 @@ import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.modded.ModdedScheduler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModdedStudioHotloadServiceTest {
|
||||
@Test
|
||||
public void shutdownDrainsWorkerBeforeAllowingRestart() throws Exception {
|
||||
ModdedStudioHotloadService service = new ModdedStudioHotloadService();
|
||||
ExecutorService executor = mock(ExecutorService.class);
|
||||
setExecutor(service, executor);
|
||||
when(executor.awaitTermination(30L, TimeUnit.SECONDS)).thenReturn(false);
|
||||
when(executor.awaitTermination(5L, TimeUnit.SECONDS)).thenReturn(true);
|
||||
|
||||
service.onDisable();
|
||||
|
||||
InOrder order = inOrder(executor);
|
||||
order.verify(executor).shutdown();
|
||||
order.verify(executor).awaitTermination(30L, TimeUnit.SECONDS);
|
||||
order.verify(executor).shutdownNow();
|
||||
order.verify(executor).awaitTermination(5L, TimeUnit.SECONDS);
|
||||
service.onEnable();
|
||||
service.onDisable();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undrainedWorkerPreventsRestart() throws Exception {
|
||||
ModdedStudioHotloadService service = new ModdedStudioHotloadService();
|
||||
ExecutorService executor = mock(ExecutorService.class);
|
||||
setExecutor(service, executor);
|
||||
when(executor.isShutdown()).thenReturn(true);
|
||||
try {
|
||||
service.onDisable();
|
||||
fail("Hotload shutdown must report a worker that did not terminate");
|
||||
} catch (IllegalStateException expected) {
|
||||
verify(executor).shutdownNow();
|
||||
}
|
||||
try {
|
||||
service.onEnable();
|
||||
fail("Hotload must not start another worker before the previous worker terminates");
|
||||
} catch (IllegalStateException expected) {
|
||||
assertFalse(executor.isTerminated());
|
||||
}
|
||||
when(executor.isTerminated()).thenReturn(true);
|
||||
service.onEnable();
|
||||
service.onDisable();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsDatapackImportsAcrossLoadedDimensions() {
|
||||
IrisDimension empty = new IrisDimension();
|
||||
@@ -45,4 +96,10 @@ public class ModdedStudioHotloadServiceTest {
|
||||
scheduler.shutdown();
|
||||
}
|
||||
}
|
||||
private static void setExecutor(ModdedStudioHotloadService service, ExecutorService executor) throws Exception {
|
||||
Field field = ModdedStudioHotloadService.class.getDeclaredField("executor");
|
||||
field.setAccessible(true);
|
||||
field.set(service, executor);
|
||||
}
|
||||
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package art.arcane.volmlib.nativelib.minecraft26_2.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeWorld;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeTeleportSafetyTest {
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsTallAndHazardousSupportsAndAcceptsSolidFloor() {
|
||||
ServerPlayer player = player();
|
||||
ServerLevel level = level();
|
||||
for (BlockState support : new BlockState[]{Blocks.OAK_FENCE.defaultBlockState(),
|
||||
Blocks.MAGMA_BLOCK.defaultBlockState(), Blocks.CACTUS.defaultBlockState()}) {
|
||||
setSupport(level, support);
|
||||
assertFalse(NativeWorldTeleport.isSafeStandingPosition(level, player, 8.5D, 4, 8.5D));
|
||||
}
|
||||
setSupport(level, Blocks.STONE.defaultBlockState());
|
||||
assertTrue(NativeWorldTeleport.isSafeStandingPosition(level, player, 8.5D, 4, 8.5D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fractionalPositionUsesWholePlayerBodyAndRequiresNeighborChunk() {
|
||||
ServerPlayer player = player();
|
||||
ServerLevel level = level();
|
||||
setSupport(level, Blocks.STONE.defaultBlockState());
|
||||
when(level.noCollision(any(), any(AABB.class))).thenAnswer(invocation -> {
|
||||
AABB body = invocation.getArgument(1);
|
||||
return body.maxX <= 16D;
|
||||
});
|
||||
assertTrue(NativeWorldTeleport.isSafeStandingPosition(level, player, 15.5D, 4, 8.5D));
|
||||
assertFalse(NativeWorldTeleport.isSafeStandingPosition(level, player, 15.9D, 4, 8.5D));
|
||||
when(level.noCollision(any(), any(AABB.class))).thenReturn(true);
|
||||
when(level.getChunkSource().hasChunk(1, 0)).thenReturn(false);
|
||||
assertFalse(NativeWorldTeleport.isSafeStandingPosition(level, player, 15.9D, 4, 8.5D));
|
||||
EntityDimensions dimensions = player.getDimensions(Pose.STANDING);
|
||||
assertEquals(0, NativeWorldTeleport.warmRadius(dimensions.makeBoundingBox(15.5D, 4D, 8.5D), new ChunkPos(0, 0)));
|
||||
assertEquals(1, NativeWorldTeleport.warmRadius(dimensions.makeBoundingBox(15.9D, 4D, 8.5D), new ChunkPos(0, 0)));
|
||||
assertEquals(1, NativeWorldTeleport.warmRadius(dimensions.makeBoundingBox(-16.1D, 4D, -8.5D), new ChunkPos(-2, -1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scaledStandingBodyStaysInsideActualWorldHeight() {
|
||||
ServerLevel level = level();
|
||||
setSupport(level, Blocks.STONE.defaultBlockState());
|
||||
ServerPlayer player = player();
|
||||
when(player.getDimensions(Pose.STANDING)).thenReturn(EntityDimensions.scalable(0.6F, 13F));
|
||||
assertFalse(NativeWorldTeleport.isSafeStandingPosition(level, player, 8.5D, 4, 8.5D));
|
||||
when(player.getDimensions(Pose.STANDING)).thenReturn(EntityDimensions.scalable(0.6F, 12F));
|
||||
assertTrue(NativeWorldTeleport.isSafeStandingPosition(level, player, 8.5D, 4, 8.5D));
|
||||
assertFalse(NativeWorldTeleport.isSafeStandingPosition(level, player, 8.5D, 0, 8.5D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reconnectDuringChunkWarmupDoesNotTeleportReplacementSession() {
|
||||
MinecraftServer server = mock(MinecraftServer.class, RETURNS_DEEP_STUBS);
|
||||
when(server.isSameThread()).thenReturn(true);
|
||||
ServerLevel level = level();
|
||||
ResourceKey<Level> key = ResourceKey.create(Registries.DIMENSION, Identifier.parse("iris:test"));
|
||||
when(level.getServer()).thenReturn(server);
|
||||
when(level.dimension()).thenReturn(key);
|
||||
when(server.getLevel(key)).thenReturn(level);
|
||||
ServerChunkCache chunks = level.getChunkSource();
|
||||
when(chunks.hasChunk(anyInt(), anyInt())).thenReturn(false);
|
||||
CompletableFuture<Void> loaded = new CompletableFuture<>();
|
||||
doReturn(loaded).when(chunks).addTicketAndLoadWithRadius(any(), any(), anyInt());
|
||||
ServerPlayer original = player();
|
||||
UUID id = UUID.randomUUID();
|
||||
when(original.getUUID()).thenReturn(id);
|
||||
when(server.getPlayerList().getPlayer(id)).thenReturn(original);
|
||||
NativeWorld world = mock(NativeWorld.class);
|
||||
when(world.nativeHandle()).thenReturn(level);
|
||||
CompletableFuture<Boolean> result = NativeWorldTeleport.teleport(NativeProtocolPlayer.fromHandle(original),
|
||||
new NativeWorldTeleport.Destination(NativeModdedServer.fromHandle(server), world, 8.5D, 4D, 8.5D, 0L));
|
||||
assertFalse(result.isDone());
|
||||
ServerPlayer replacement = player();
|
||||
when(server.getPlayerList().getPlayer(id)).thenReturn(replacement);
|
||||
loaded.complete(null);
|
||||
assertFalse(result.join());
|
||||
verify(chunks).removeTicketWithRadius(any(), any(), anyInt());
|
||||
}
|
||||
|
||||
private ServerPlayer player() {
|
||||
ServerPlayer player = mock(ServerPlayer.class);
|
||||
when(player.getDimensions(Pose.STANDING)).thenReturn(EntityDimensions.scalable(0.6F, 1.8F));
|
||||
return player;
|
||||
}
|
||||
|
||||
private ServerLevel level() {
|
||||
ServerLevel level = mock(ServerLevel.class);
|
||||
ServerChunkCache chunks = mock(ServerChunkCache.class);
|
||||
when(level.getChunkSource()).thenReturn(chunks);
|
||||
when(level.getMinY()).thenReturn(0);
|
||||
when(level.getMaxY()).thenReturn(16);
|
||||
when(chunks.hasChunk(anyInt(), anyInt())).thenReturn(true);
|
||||
when(level.noCollision(any(), any(AABB.class))).thenReturn(true);
|
||||
return level;
|
||||
}
|
||||
|
||||
private void setSupport(ServerLevel level, BlockState support) {
|
||||
when(level.getBlockState(any(BlockPos.class))).thenAnswer(invocation -> {
|
||||
BlockPos position = invocation.getArgument(0);
|
||||
return position.getY() == 3 ? support : Blocks.AIR.defaultBlockState();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user