diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/iris/ModdedBiomeDetector.java b/src/main/java/com/gtnewhorizons/angelica/compat/iris/ModdedBiomeDetector.java index 8810c47bf..808ce66a1 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/iris/ModdedBiomeDetector.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/iris/ModdedBiomeDetector.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.angelica.compat.iris; +import com.gtnewhorizons.angelica.compat.ModStatus; import net.coderbot.iris.parsing.BiomeCategories; import net.minecraft.world.biome.BiomeGenBase; @@ -8,7 +9,7 @@ import java.util.Map; /** * Detects and categorizes biomes from popular modded biome mods using cached class checks. - * Currently supports: BiomesOPlenty (BOP), Realistic World Gen (RWG) + * Currently supports: BiomesOPlenty (BOP), Realistic World Gen (RWG), lotr (b36.15) */ public class ModdedBiomeDetector { private static boolean initialized = false; @@ -23,12 +24,15 @@ public class ModdedBiomeDetector { // LinkedHashMap maintains insertion order for deterministic behavior private static final Map, BiomeCategories> rwgClassMap = new LinkedHashMap<>(); + private static Class lotrBiomeClass = null; + private static synchronized void initialize() { if (initialized) return; initialized = true; initializeBOP(); initializeRWG(); + initializeLOTR(); } private static void initializeBOP() { @@ -59,6 +63,16 @@ public class ModdedBiomeDetector { tryAddRWGClass("rwg.biomes.base.BaseBiomeSnowForest", BiomeCategories.TAIGA); // Snow forests are taiga } + private static void initializeLOTR() { + if (ModStatus.isLotrLoaded) { + try { + lotrBiomeClass = Class.forName("lotr.common.world.biome.LOTRBiome"); + } catch (ClassNotFoundException ignored) { + // lotr not installed + } + } + } + private static void tryAddRWGClass(String className, BiomeCategories category) { try { final Class clazz = Class.forName(className); @@ -91,12 +105,64 @@ public class ModdedBiomeDetector { // fall through to name/property-based detection // Realistic World Gen detection - for (Map.Entry, BiomeCategories> entry : rwgClassMap.entrySet()) { - if (entry.getKey().isInstance(biome)) { - return entry.getValue(); + if (biome.getBiomeClass().getName().contains("rwg.biomes")) { + for (Map.Entry, BiomeCategories> entry : rwgClassMap.entrySet()) { + if (entry.getKey().isInstance(biome)) { + return entry.getValue(); + } } } + // lotr + if (lotrBiomeClass.isInstance(biome)) { + return detectLOTRBiome(biome); + } + return null; } + + private static BiomeCategories detectLOTRBiome(BiomeGenBase biome) { + return switch (biome.biomeName) { + case "river", "farHaradJungleLake", "lake" -> BiomeCategories.RIVER; + case "rohan", "rivendell", "rhunIsland", "rhunLandHills", "rhunLandSteppe", "rhunLand", "andrast", + "blackrootVale", "lamedon", "imlothMelui", "towerHills", "dorwinion", "dale", "shireMoors", "wold", + "anduinVale", "rhun", "lebennin", "pertorogwaith", "breeland", "island", "pinnathGelin", + "minhiriath", "pelennor", "adornland", "nanCurunir", "ithilienWasteland", "fangornClearing", + "barrowDowns", "dorEnErnilHills", "dorEnErnil", "nurn", "wilderland", "eastBight", "lindon", + "eregion", "enedwaith", "meneltarma", "anduinHills", "eriador", "angle", "loneLandsHills", + "loneLands", "pelargir", "rohanUrukHighlands", "celebrant", "gondor", "shire", "nurnen", "farHarad" -> + BiomeCategories.PLAINS; + case "mistyMountains", "windMountains", "farHaradVolcano", "redMountains", "haradMountains", + "angmarMountains", "blueMountains", "greyMountains", "whiteMountains", "mordorMountains" -> + BiomeCategories.MOUNTAIN; + case "shireWoodlands", "rhunIslandForest", "rhunRedForest", "pukel", "lossarnach", "gulfHaradForest", + "nearHaradFertileForest", "dolGuldur", "rhunForest", "tauredainClearing", "umbarForest", + "farHaradForest", "chetwood", "woodlandRealmHills", "mirkwoodNorth", "whiteDowns", "ithilienHills", + "gondorWoodlands", "rohanWoodlands", "fangornWasteland", "mirkwoodMountains", "lindonWoodlands", + "lothlorienEdge", "erynVorn", "oldForest", "fangorn", "dunland", "ithilien", "mirkwoodCorrupted", + "woodlandRealm", "trollshaws", "lothlorien", "farHaradKanuka" -> BiomeCategories.FOREST; + case "mordor", "lastDesert", "harnedor", "easternDesolation", "morgulVale", "gorgoroth", "udun", + "nearHaradRedDesert", "nearHaradSemiDesert", "lostladen", + "nearHaradHills", "nearHarad", "nanUngol", "dagorlad", "brownLands" -> BiomeCategories.DESERT; + case "ironHills", "rivendellHills", "windMountainsFoothills", "lamedonHills", "redMountainsFoothills", + "tolfalas", "dorwinionHills", "whiteMountainsFoothills", "blueMountainsFoothills", + "greyMountainsFoothills", "mistyMountainsFoothills", "erebor", "angmar", "eriadorDowns", + "ettenmoors", "emynMuil" -> BiomeCategories.EXTREME_HILLS; + case "deadMarshes", "shireMarshes", "farHaradMangrove", "farHaradSwamp", "swanfleet", "nindalf", + "longMarshes", "entwashMouth", "nurnMarshes", "gladdenFields", "midgewater", "anduinMouth" -> + BiomeCategories.SWAMP; + case "harondor", "nearHaradOasis", "nearHaradRiverbank", "farHaradBushlandHills", "farHaradBushland", + "gulfHarad", "nearHaradFertile", "umbarHills", "umbar", "farHaradAridHills", "farHaradArid" -> + BiomeCategories.SAVANNA; + case "ocean" -> BiomeCategories.OCEAN; + case "forodwaith", "forodwaithGlacier", "tundra", "forodwaithMountains" -> BiomeCategories.ICY; + case "lindonCoast", "beachWhite", "farHaradCoast", "forodwaithCoast", "beachGravel", "beach" -> + BiomeCategories.BEACH; + case "coldfells", "wilderlandNorth", "taiga" -> BiomeCategories.TAIGA; + case "farHaradJungle", "halfTrollForest", "farHaradJungleMountains", + "farHaradCloudForest", "farHaradJungleEdge" -> BiomeCategories.JUNGLE; + case "utumno" -> BiomeCategories.NONE; + default -> null; + }; + } } diff --git a/src/main/java/net/coderbot/iris/uniforms/BiomeUniforms.java b/src/main/java/net/coderbot/iris/uniforms/BiomeUniforms.java index 5bfd3ff95..844c35c08 100644 --- a/src/main/java/net/coderbot/iris/uniforms/BiomeUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/BiomeUniforms.java @@ -25,9 +25,11 @@ import net.minecraft.world.biome.BiomeGenSnow; import net.minecraft.world.biome.BiomeGenStoneBeach; import net.minecraft.world.biome.BiomeGenSwamp; import net.minecraft.world.biome.BiomeGenTaiga; +import net.minecraftforge.common.BiomeDictionary; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -107,6 +109,9 @@ public class BiomeUniforms { return biome != null ? biome.temperature : 0.0F; } + /** + * Biome ids in 1.7.10 are not unique, instead of this the biome category should be used + */ public static int getBiomeId() { final BiomeGenBase biome = getCachedBiome(); return biome != null ? biome.biomeID : 0; @@ -142,36 +147,51 @@ public class BiomeUniforms { } private static int determineBiomeCategory(BiomeGenBase biome) { - // Tier 1: Hardcoded vanilla biome IDs BiomeGenBase lookupBiome = biome; if (biome instanceof BiomeGenMutated mutated && mutated.baseBiome != null) { lookupBiome = mutated.baseBiome; } - BiomeCategories category = getVanillaBiomeCategory(lookupBiome.biomeID); + BiomeCategories category = null; + + // Tier 1: Hardcoded vanilla biome IDs + // biomes not in the biomeGenArray are also not registered to the forge biomeDictionary + if (Arrays.asList(BiomeGenBase.getBiomeGenArray()).contains(biome)) { + category = getVanillaBiomeCategory(lookupBiome.biomeID); + + if (category != null) { + return category.ordinal(); + } + + // Tier 2: forge BiomeDictionary detection + if (BiomeDictionary.isBiomeRegistered(biome)) { + category = detectBiomeByBiomeDictionary(biome); + } + } + if (category != null) { return category.ordinal(); } - // Tier 2: Class-based detection for vanilla biome types + // Tier 3: Class-based detection for vanilla biome types category = detectVanillaBiomeByClass(biome); if (category != null) { return category.ordinal(); } - // Tier 3: Modded biome detection (BiomesOPlenty, Realistic World Gen) + // Tier 4: Modded biome detection (BiomesOPlenty, Realistic World Gen, lotr) category = detectModdedBiome(biome); if (category != null) { return category.ordinal(); } - // Tier 4: Name pattern matching + // Tier 5: Name pattern matching category = detectBiomeByName(biome); if (category != null) { return category.ordinal(); } - // Tier 5: Temperature/rainfall heuristics + // Tier 6: Temperature/rainfall heuristics category = detectBiomeByProperties(biome); if (category != null) { return category.ordinal(); @@ -366,4 +386,42 @@ public class BiomeUniforms { return null; } + + /** + * Use the forge BiomeDictionary when available + */ + private static BiomeCategories detectBiomeByBiomeDictionary(BiomeGenBase biome) { + + var biomeDictTypes = Arrays.asList(BiomeDictionary.getTypesForBiome(biome)); + + if (biomeDictTypes.contains(BiomeDictionary.Type.SAVANNA)) { + return BiomeCategories.SAVANNA; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.JUNGLE)) { + return BiomeCategories.JUNGLE; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.NETHER)) { + return BiomeCategories.NETHER; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.END)) { + return BiomeCategories.THE_END; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.MUSHROOM)) { + return BiomeCategories.MUSHROOM; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.OCEAN)) { + return BiomeCategories.OCEAN; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.RIVER)) { + return BiomeCategories.RIVER; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.MESA)) { + return BiomeCategories.MESA; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.FOREST)) { + return BiomeCategories.FOREST; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.PLAINS)) { + return BiomeCategories.PLAINS; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.MOUNTAIN)) { + return BiomeCategories.MOUNTAIN; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.SWAMP)) { + return BiomeCategories.SWAMP; + } else if (biomeDictTypes.contains(BiomeDictionary.Type.SANDY)) { + return BiomeCategories.DESERT; + } + + return null; + } }