fix(test): use tag membership for climate band assertions

With Biomes O' Plenty installed, the FROZEN/HOT bands are filled with BOP
cold/hot biomes which the previous hardcoded vanilla-only assertion sets
did not include, causing a false failure (FROZEN measured 31% vs real ~100%).

Assertions now resolve the surface tags from the real registry and check
membership, so vanilla + BOP biomes are both counted. Adds a per-band
breakdown to the report for easier diagnostics.

Validated with Create + JEI + Biomes O' Plenty + Tectonic + deps:
  spawn=birch_forest | north=100% | south=100% | swamp=1.26%
This commit is contained in:
feldenr
2026-06-15 23:10:24 +02:00
parent 169a447f7b
commit 45213d3580
@@ -110,24 +110,59 @@ public class LatitudeGameTest {
ResourceKey<Biome> spawnKey = source.getNoiseBiome(0, 64 >> 2, 0, null).unwrapKey().orElse(null);
// Resolve the three surface tags so assertions can use tag membership (the source of
// truth) instead of a hardcoded vanilla-only biome list. This correctly counts BOP biomes.
Set<ResourceKey<Biome>> coldTag = resolveTagKeys(getter, BiomeBand.COLD.surfaceTag());
Set<ResourceKey<Biome>> temperateTag = resolveTagKeys(getter, BiomeBand.TEMPERATE.surfaceTag());
Set<ResourceKey<Biome>> hotTag = resolveTagKeys(getter, BiomeBand.HOT.surfaceTag());
Set<ResourceKey<Biome>> coldOceans = new HashSet<>(List.of(
Biomes.FROZEN_OCEAN, Biomes.DEEP_FROZEN_OCEAN, Biomes.COLD_OCEAN, Biomes.DEEP_COLD_OCEAN,
Biomes.FROZEN_RIVER));
Set<ResourceKey<Biome>> hotOceans = new HashSet<>(List.of(
Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN));
StringBuilder r = new StringBuilder();
r.append("Latitude GameTest Report (seed=").append(SEED).append(")\n\n");
r.append("Spawn @ (0,0): ").append(spawnKey).append("\n\n");
int total = global.values().stream().mapToInt(Integer::intValue).sum();
r.append("Global biome distribution (top 20):\n");
global.entrySet().stream()
.sorted(Map.Entry.<ResourceKey<Biome>, Integer>comparingByValue().reversed())
.limit(20)
.forEach(e -> r.append(String.format(" %-45s %6.2f%%%n", e.getKey(), 100.0 * e.getValue() / total)));
// Per-band breakdown for diagnostics.
for (BiomeBand band : BiomeBand.values()) {
Map<ResourceKey<Biome>, Integer> m = perBand.get(band);
int bt = m.values().stream().mapToInt(Integer::intValue).sum();
if (bt == 0) continue;
r.append("\nBand ").append(band).append(" (").append(bt).append(" samples):\n");
m.entrySet().stream()
.sorted(Map.Entry.<ResourceKey<Biome>, Integer>comparingByValue().reversed())
.limit(8)
.forEach(e -> r.append(String.format(" %-43s %6.2f%%%n", e.getKey(), 100.0 * e.getValue() / bt)));
}
Files.writeString(OUT_DIR.resolve("latitude_report.txt"), r.toString());
// ---- Assertions ----
// ---- Assertions (tag-based: correctly counts vanilla + BOP biomes) ----
assertNotNull(spawnKey, "spawn biome resolved");
assertTrue(isSafeSpawn(spawnKey), "spawn must be a safe biome, was " + spawnKey);
double north = bandRatio(perBand.get(BiomeBand.FROZEN), frozenColdKeys());
assertTrue(north > 60.0, "FROZEN band should be >60%% cold/frozen, was %.1f%%".formatted(north));
Set<ResourceKey<Biome>> northExpected = new HashSet<>();
northExpected.addAll(coldTag);
northExpected.addAll(coldOceans);
Set<ResourceKey<Biome>> undergroundCold = new HashSet<>(List.of(
Biomes.DRIPSTONE_CAVES, Biomes.DEEP_DARK));
northExpected.addAll(undergroundCold);
double north = bandRatio(perBand.get(BiomeBand.FROZEN), northExpected);
assertTrue(north > 60.0, "FROZEN band should be >60%% cold/frozen (by tag), was %.1f%%".formatted(north));
double south = bandRatio(perBand.get(BiomeBand.HOT), hotWarmKeys());
assertTrue(south > 60.0, "HOT band should be >60%% warm/hot, was %.1f%%".formatted(south));
Set<ResourceKey<Biome>> southExpected = new HashSet<>();
southExpected.addAll(hotTag);
southExpected.addAll(hotOceans);
southExpected.add(Biomes.MANGROVE_SWAMP);
double south = bandRatio(perBand.get(BiomeBand.HOT), southExpected);
assertTrue(south > 60.0, "HOT band should be >60%% warm/hot (by tag), was %.1f%%".formatted(south));
Map<ResourceKey<Biome>, Integer> temperate = perBand.get(BiomeBand.TEMPERATE);
int temperateTotal = temperate.values().stream().mapToInt(Integer::intValue).sum();
@@ -150,18 +185,11 @@ public class LatitudeGameTest {
return 100.0 * match / total;
}
private static Set<ResourceKey<Biome>> frozenColdKeys() {
return new HashSet<>(List.of(Biomes.SNOWY_PLAINS, Biomes.ICE_SPIKES, Biomes.SNOWY_TAIGA, Biomes.GROVE,
Biomes.SNOWY_SLOPES, Biomes.JAGGED_PEAKS, Biomes.FROZEN_PEAKS, Biomes.TAIGA,
Biomes.OLD_GROWTH_PINE_TAIGA, Biomes.OLD_GROWTH_SPRUCE_TAIGA, Biomes.WINDSWEPT_HILLS,
Biomes.WINDSWEPT_FOREST, Biomes.FROZEN_OCEAN, Biomes.DEEP_FROZEN_OCEAN,
Biomes.COLD_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.FROZEN_RIVER));
}
private static Set<ResourceKey<Biome>> hotWarmKeys() {
return new HashSet<>(List.of(Biomes.DESERT, Biomes.BADLANDS, Biomes.WOODED_BADLANDS,
Biomes.ERODED_BADLANDS, Biomes.JUNGLE, Biomes.SPARSE_JUNGLE, Biomes.BAMBOO_JUNGLE,
Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.WARM_OCEAN));
/** Resolve all biome keys that belong to a tag, via the real registry. */
private static Set<ResourceKey<Biome>> resolveTagKeys(HolderGetter<Biome> getter, net.minecraft.tags.TagKey<Biome> tag) {
Set<ResourceKey<Biome>> keys = new HashSet<>();
getter.get(tag).ifPresent(set -> set.forEach(h -> h.unwrapKey().ifPresent(keys::add)));
return keys;
}
private static boolean isSafeSpawn(ResourceKey<Biome> key) {