Merge origin/master into terrain-first hydrology

Brings master's Sentry removal, bound platform classification, Vision
entity toggle, release version and generation context binding onto the
rivers rework while keeping the hydrology system master had removed.
Hydrology files master deleted are restored from the branch, master's
non-hydrology edits are kept, and the modded adapter builds drop the
Sentry dependency with master.

Also removes the ridge_tunnel find selector: no course publishes ridge
bores any more, so it could never return a result.
This commit is contained in:
Brian Neumann-Fopiano committed 2026-09-02 02:52:08 -04:00
commit f6a7ad7472
74 files changed
+869 -726

No files matched your search

@@ -0,0 +1,150 @@
package art.arcane.iris.modded;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.ChunkGenerator;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
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;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ModdedGenerationBootstrapBindingTest {
private static final String SOURCE_ROOT_PROPERTY = "iris.moddedCommonSources";
@Test
public void publishedLevelRequiresCurrentGeneratorIdentity() {
IrisModdedChunkGenerator generator = mock(IrisModdedChunkGenerator.class, CALLS_REAL_METHODS);
MinecraftServer server = mock(MinecraftServer.class);
ServerLevel level = mock(ServerLevel.class);
ServerChunkCache chunkSource = mock(ServerChunkCache.class);
when(server.getLevel(Level.OVERWORLD)).thenReturn(level);
when(level.dimension()).thenReturn(Level.OVERWORLD);
when(level.getChunkSource()).thenReturn(chunkSource);
when(chunkSource.getGenerator()).thenReturn(generator);
assertSame(level, generator.requirePublishedLevel(server, Level.OVERWORLD));
ChunkGenerator otherGenerator = mock(ChunkGenerator.class);
when(chunkSource.getGenerator()).thenReturn(otherGenerator);
IllegalStateException mismatch = assertThrows(IllegalStateException.class,
() -> generator.requirePublishedLevel(server, Level.OVERWORLD));
assertTrue(mismatch.getMessage().contains("does not use Iris generator"));
}
@Test
public void publishedLevelRejectsMissingServerAndWorld() {
IrisModdedChunkGenerator generator = mock(IrisModdedChunkGenerator.class, CALLS_REAL_METHODS);
IllegalStateException missingServer = assertThrows(IllegalStateException.class,
() -> generator.requirePublishedLevel(null, Level.OVERWORLD));
assertTrue(missingServer.getMessage().contains("server is unavailable"));
MinecraftServer server = mock(MinecraftServer.class);
IllegalStateException missingWorld = assertThrows(IllegalStateException.class,
() -> generator.requirePublishedLevel(server, Level.OVERWORLD));
assertTrue(missingWorld.getMessage().contains("no published ServerLevel"));
}
@Test
public void staleSnapshotResolvesOnlyCanonicalOverworldOwnedByGenerator() {
IrisModdedChunkGenerator generator = mock(IrisModdedChunkGenerator.class, CALLS_REAL_METHODS);
MinecraftServer server = mock(MinecraftServer.class);
ServerLevel overworld = mock(ServerLevel.class);
ServerChunkCache chunkSource = mock(ServerChunkCache.class);
when(server.getLevel(Level.OVERWORLD)).thenReturn(overworld);
when(overworld.getChunkSource()).thenReturn(chunkSource);
when(chunkSource.getGenerator()).thenReturn(generator);
assertSame(overworld, generator.resolveBoundLevel(server, List.of()));
ChunkGenerator otherGenerator = mock(ChunkGenerator.class);
when(chunkSource.getGenerator()).thenReturn(otherGenerator);
assertNull(generator.resolveBoundLevel(server, List.of()));
verify(server, never()).getLevel(Level.NETHER);
}
@Test
public void dynamicLevelStillResolvesFromSnapshotWithoutCanonicalLookup() {
IrisModdedChunkGenerator generator = mock(IrisModdedChunkGenerator.class, CALLS_REAL_METHODS);
MinecraftServer server = mock(MinecraftServer.class);
ServerLevel dynamicLevel = mock(ServerLevel.class);
ServerChunkCache chunkSource = mock(ServerChunkCache.class);
when(dynamicLevel.getChunkSource()).thenReturn(chunkSource);
when(chunkSource.getGenerator()).thenReturn(generator);
assertSame(dynamicLevel, generator.resolveBoundLevel(server, List.of(dynamicLevel)));
verify(server, never()).getLevel(Level.OVERWORLD);
}
@Test
public void firstGenerationStagesProvideAuthoritativeLevelContext() throws IOException {
String source = source("IrisModdedChunkGenerator.java");
String structures = method(source, "public void createStructures(");
String references = method(source, "public void createReferences(");
assertTrue(structures.contains("Engine current = engine(levelKey);"));
assertTrue(references.contains("Engine current = engine(level.getLevel());"));
String publishedBinding = method(source, "private Engine engine(ResourceKey<Level> levelKey)");
assertTrue(publishedBinding.contains("requirePublishedLevel(ModdedEngineBootstrap.currentServer(), levelKey)"));
assertTrue(publishedBinding.contains("return bindGenerationLevel(level);"));
assertFalse(publishedBinding.contains("ModdedServerLevels.level("));
String fullBinding = method(source, "private Engine bindGenerationLevel(ServerLevel level)");
assertTrue(fullBinding.contains("bindLevel(level);"));
assertTrue(fullBinding.contains("Engine bound = readyEngine();"));
String genericBinding = method(source, "Engine engine()");
assertTrue(genericBinding.contains("return bindGenerationLevel(level);"));
}
@Test
public void constructorMixinIsNotPartOfGenerationBootstrap() throws IOException {
String sourceRoot = System.getProperty(SOURCE_ROOT_PROPERTY);
assertTrue(sourceRoot != null && !sourceRoot.isBlank());
Path root = Path.of(sourceRoot);
assertFalse(Files.exists(root.resolve(Path.of("art", "arcane", "iris", "modded", "mixin",
"ServerLevelBindingMixin.java"))));
String mixinConfig = Files.readString(root.getParent().resolve("resources/irisworldgen.entity.mixins.json"));
assertFalse(mixinConfig.contains("ServerLevelBindingMixin"));
}
private String source(String fileName) throws IOException {
String sourceRoot = System.getProperty(SOURCE_ROOT_PROPERTY);
assertTrue(sourceRoot != null && !sourceRoot.isBlank());
return Files.readString(Path.of(sourceRoot, "art", "arcane", "iris", "modded", fileName));
}
private String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue(start >= 0);
int body = source.indexOf('{', start);
assertTrue(body >= 0);
int depth = 0;
for (int index = body; index < source.length(); index++) {
char token = source.charAt(index);
if (token == '{') {
depth++;
} else if (token == '}') {
depth--;
if (depth == 0) {
return source.substring(start, index + 1);
}
}
}
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
}
}
@@ -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 {
}
}