This commit is contained in:
Brian Neumann-Fopiano
2026-08-04 11:13:16 -06:00
parent 10b2363226
commit aaccbacf32
66 changed files with 930 additions and 557 deletions
@@ -53,15 +53,19 @@ final class VanillaStructureBiomes {
if (structure == null) {
throw new IllegalArgumentException("Registered structure does not exist: " + structureKey);
}
boolean hasFilterEntries = false;
for (Holder<Biome> holder : structure.biomes()) {
hasFilterEntries = true;
Optional<ResourceKey<Biome>> key = holder.unwrapKey();
if (key.isPresent()) {
keys.add(key.get().identifier().toString());
}
}
if (keys.isEmpty()) {
// An empty biome filter is legal datapack content (opt-in structures whose tags only
// reference absent modded biomes); the structure is unreachable, not an error state.
if (keys.isEmpty() && hasFilterEntries) {
throw new IllegalStateException("Registered structure '" + structureKey
+ "' exposes no registered biome keys");
+ "' has biome filter entries but none resolve to registered biome keys");
}
return keys;
}
@@ -0,0 +1,38 @@
package art.arcane.iris.core.nms.v26_2_R1;
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.assertTrue;
/**
* A registered structure with an EMPTY biome filter is legal datapack content: opt-in structures
* (e.g. Towns and Towers' towns_and_towers:exclusives/*) ship biome tags that only reference
* optional modded biomes, so the filter resolves to zero entries on a vanilla server. Resolving
* biome keys for such a structure must return an empty set (the structure is simply unreachable),
* never throw — a throw here aborts the whole /iris structure verify run and degrades /iris find.
* The defensive throw is only kept for a NON-empty filter whose holders all fail to resolve keys.
*/
public class VanillaStructureBiomesEmptyFilterContractTest {
@Test
public void emptyBiomeFilterReturnsEmptyKeysInsteadOfThrowing() throws IOException {
String source = Files.readString(Path.of(System.getProperty("iris.vanillaStructureBiomesSource")));
assertTrue(source.contains("if (keys.isEmpty() && hasFilterEntries)"));
assertTrue(source.contains("has biome filter entries but none resolve to registered biome keys"));
assertFalse(source.contains("exposes no registered biome keys"));
}
@Test
public void moddedHookMatchesEmptyFilterContract() throws IOException {
String source = Files.readString(Path.of(System.getProperty("iris.moddedStructureHooksSource")));
assertTrue(source.contains("if (keys.isEmpty() && hasFilterEntries)"));
assertTrue(source.contains("has biome filter entries but none resolve to registered biome keys"));
assertFalse(source.contains("exposes no registered biome keys"));
}
}