Bridge host levels

- Publish and remove dynamic levels through host lifecycle methods when available.
- Attach hybrid host level data before engine binding and publication.
- Preserve native loader behavior when host extensions are absent.
This commit is contained in:
Brian Neumann-Fopiano committed 2026-08-28 16:30:05 -04:00
1 parent 95d8523d1d
commit fd8c55076e
5 files changed
+320 -2

No files matched your search

@@ -0,0 +1,94 @@
package art.arcane.iris.modded;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class ModdedLevelDataAttachmentTest {
@Test
public void detectsAndInvokesHostLevelDataAttachment() {
ModdedServerLevels.HostLevelDataAttachment attachment =
ModdedServerLevels.HostLevelDataAttachment.detect(
AttachedLevelData.class, RootData.class, DimensionKey.class);
AttachedLevelData levelData = new AttachedLevelData();
RootData rootData = new RootData();
DimensionKey dimensionKey = new DimensionKey();
assertTrue(attachment.supported());
attachment.attach(levelData, rootData, dimensionKey);
assertSame(rootData, levelData.rootData);
assertSame(dimensionKey, levelData.dimensionKey);
}
@Test
public void ignoresLevelDataWithoutAttachmentCapability() {
ModdedServerLevels.HostLevelDataAttachment attachment =
ModdedServerLevels.HostLevelDataAttachment.detect(
StandardLevelData.class, RootData.class, DimensionKey.class);
assertFalse(attachment.supported());
}
@Test
public void propagatesHostAttachmentFailureWithoutReflectionWrapper() {
ModdedServerLevels.HostLevelDataAttachment attachment =
ModdedServerLevels.HostLevelDataAttachment.detect(
FailingLevelData.class, RootData.class, DimensionKey.class);
IllegalStateException failure = assertThrows(IllegalStateException.class,
() -> attachment.attach(new FailingLevelData(), new RootData(), new DimensionKey()));
assertNull(failure.getCause());
}
@Test
public void initializesLevelDataBeforeBindingAndPublication() throws IOException {
String source = Files.readString(sourcePath("ModdedDimensionManager.java"));
int construction = source.indexOf("ServerLevel level = new ServerLevel(");
int initialization = source.indexOf("serverAccess.initializeLevelData(server, level);", construction);
int binding = source.indexOf("generator.bindLevel(level);", initialization);
int publication = source.indexOf("serverAccess.putLevelIfAbsent(server, key, level);", binding);
assertTrue(construction >= 0);
assertTrue(initialization > construction);
assertTrue(binding > initialization);
assertTrue(publication > binding);
}
private static Path sourcePath(String fileName) {
return Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded", fileName);
}
public static final class AttachedLevelData {
private RootData rootData;
private DimensionKey dimensionKey;
public void attach(RootData rootData, DimensionKey dimensionKey) {
this.rootData = rootData;
this.dimensionKey = dimensionKey;
}
}
public static final class FailingLevelData {
public void attach(RootData rootData, DimensionKey dimensionKey) {
throw new IllegalStateException("attachment failed");
}
}
public static final class StandardLevelData {
}
public static final class RootData {
}
public static final class DimensionKey {
}
}
@@ -0,0 +1,73 @@
package art.arcane.iris.modded;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class ModdedServerLevelsTest {
@Test
public void detectsAndInvokesHostLevelPublicationPair() {
ModdedServerLevels.HostLevelPublication publication =
ModdedServerLevels.HostLevelPublication.detect(PublishingServer.class, PublishedLevel.class);
PublishingServer server = new PublishingServer();
PublishedLevel level = new PublishedLevel();
assertTrue(publication.supported());
publication.add(server, level);
assertSame(level, server.added);
publication.remove(server, level);
assertSame(level, server.removed);
}
@Test
public void rejectsPartialHostLevelPublicationCapability() {
ModdedServerLevels.HostLevelPublication publication =
ModdedServerLevels.HostLevelPublication.detect(AddOnlyServer.class, PublishedLevel.class);
assertFalse(publication.supported());
}
@Test
public void propagatesHostPublicationFailureWithoutReflectionWrapper() {
ModdedServerLevels.HostLevelPublication publication =
ModdedServerLevels.HostLevelPublication.detect(FailingServer.class, PublishedLevel.class);
IllegalStateException failure = assertThrows(IllegalStateException.class,
() -> publication.add(new FailingServer(), new PublishedLevel()));
assertNull(failure.getCause());
}
public static final class PublishingServer {
private PublishedLevel added;
private PublishedLevel removed;
public void addLevel(PublishedLevel level) {
added = level;
}
public void removeLevel(PublishedLevel level) {
removed = level;
}
}
public static final class AddOnlyServer {
public void addLevel(PublishedLevel level) {
}
}
public static final class FailingServer {
public void addLevel(PublishedLevel level) {
throw new IllegalStateException("publication failed");
}
public void removeLevel(PublishedLevel level) {
}
}
public static final class PublishedLevel {
}
}