This commit is contained in:
Brian Neumann-Fopiano
2026-07-18 18:12:04 -04:00
parent 0193f75daa
commit ad41b6795c
48 changed files with 1193 additions and 141 deletions
@@ -104,7 +104,6 @@ public final class ModdedEngineBootstrap {
ModdedStartup.prepareForStartup();
IrisModdedChunkGenerator.startGenPool();
bindWorldGenerators(server);
ModdedStartup.runOnce(server);
services().enableAll();
ModdedProtocolHandler.start(server);
ModdedSentry.start(loader());
@@ -125,6 +124,7 @@ public final class ModdedEngineBootstrap {
public static void serverStarted(MinecraftServer server) {
bindWorldGenerators(server);
ModdedStartup.runOnce(server);
reconcileSpawn(server);
ModdedWorldCheck.serverStarted(server);
}
@@ -284,7 +284,8 @@ public final class ModdedEngineBootstrap {
IrisPlatforms.bind(created);
rollback.add(() -> restorePlatform(previousPlatform));
ModdedServerAccess previousServerAccess = ModdedDimensionManager.bindAccess(new ModdedServerLevels());
ModdedServerAccess previousServerAccess = ModdedDimensionManager.bindAccess(
new ModdedServerLevels(boundLoader::invalidateLevelCache));
rollback.add(() -> ModdedDimensionManager.restoreAccess(previousServerAccess));
IrisObjectRotation.StateRotator previousRotator = IrisObjectRotation.bindPlatformRotator(new ModdedStateRotator());
@@ -32,6 +32,8 @@ public interface ModdedLoader {
MinecraftServer currentServer();
void invalidateLevelCache(MinecraftServer server);
boolean clientEnvironment();
Path configDir();
@@ -24,9 +24,17 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.LevelStorageSource;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
public final class ModdedServerLevels implements ModdedServerAccess {
private final Consumer<MinecraftServer> levelCacheInvalidator;
public ModdedServerLevels(Consumer<MinecraftServer> levelCacheInvalidator) {
this.levelCacheInvalidator = Objects.requireNonNull(levelCacheInvalidator);
}
@Override
public Executor levelExecutor(MinecraftServer server) {
return server.executor;
@@ -39,17 +47,29 @@ public final class ModdedServerLevels implements ModdedServerAccess {
@Override
public ServerLevel putLevel(MinecraftServer server, ResourceKey<Level> key, ServerLevel level) {
return server.levels.put(key, level);
ServerLevel previous = server.levels.put(key, level);
if (previous != level) {
levelCacheInvalidator.accept(server);
}
return previous;
}
@Override
public ServerLevel putLevelIfAbsent(MinecraftServer server, ResourceKey<Level> key, ServerLevel level) {
return server.levels.putIfAbsent(key, level);
ServerLevel previous = server.levels.putIfAbsent(key, level);
if (previous == null) {
levelCacheInvalidator.accept(server);
}
return previous;
}
@Override
public ServerLevel removeLevel(MinecraftServer server, ResourceKey<Level> key) {
return server.levels.remove(key);
ServerLevel removed = server.levels.remove(key);
if (removed != null) {
levelCacheInvalidator.accept(server);
}
return removed;
}
@Override
@@ -66,7 +66,7 @@ public final class ModdedStartup {
}
public static void runOnce(MinecraftServer server) {
if (server == null) {
if (server == null || server.getPlayerList() == null) {
return;
}
prepareForStartup();
@@ -72,6 +72,44 @@ public class ModdedLifecycleFailureContractTest {
assertTrue(failure.contains(", e);"));
}
@Test
public void persistentReinjectionWaitsForPlayerServicesAndServerStarted() throws IOException {
String bootstrapSource = source("ModdedEngineBootstrap.java");
String start = method(bootstrapSource, "public static void start(");
String serverAboutToStart = method(bootstrapSource, "public static void serverAboutToStart(");
String serverStarted = method(bootstrapSource, "public static void serverStarted(");
assertFalse(start.contains("ModdedStartup.runOnce(server);"));
assertFalse(serverAboutToStart.contains("ModdedStartup.runOnce(server);"));
assertEquals(1, occurrences(serverStarted, "ModdedStartup.runOnce(server);"));
assertBefore(serverStarted, "bindWorldGenerators(server);", "ModdedStartup.runOnce(server);");
assertBefore(serverStarted, "ModdedStartup.runOnce(server);", "reconcileSpawn(server);");
String startupSource = source("ModdedStartup.java");
String runOnce = method(startupSource, "public static void runOnce(");
assertBefore(runOnce, "server.getPlayerList() == null", "STARTED.compareAndSet(false, true)");
}
@Test
public void dynamicLevelMutationsInvalidateLoaderTickCaches() throws IOException {
String levelsSource = source("ModdedServerLevels.java");
String put = method(levelsSource, "public ServerLevel putLevel(");
String putIfAbsent = method(levelsSource, "public ServerLevel putLevelIfAbsent(");
String remove = method(levelsSource, "public ServerLevel removeLevel(");
assertBefore(put, "server.levels.put(key, level);", "levelCacheInvalidator.accept(server);");
assertTrue(put.contains("if (previous != level)"));
assertBefore(putIfAbsent, "server.levels.putIfAbsent(key, level);", "levelCacheInvalidator.accept(server);");
assertTrue(putIfAbsent.contains("if (previous == null)"));
assertBefore(remove, "server.levels.remove(key);", "levelCacheInvalidator.accept(server);");
assertTrue(remove.contains("if (removed != null)"));
String loaderSource = source("ModdedLoader.java");
assertTrue(loaderSource.contains("void invalidateLevelCache(MinecraftServer server);"));
String bootstrapSource = source("ModdedEngineBootstrap.java");
assertTrue(bootstrapSource.contains("new ModdedServerLevels(boundLoader::invalidateLevelCache)"));
}
@Test
public void packDimensionLoadingNeverSuppressesTheFailureAsNull() throws IOException {
String source = source("ModdedDimensionManager.java");