From f90cb547086e56c9078069cccf5e0a30583a66f9 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Thu, 14 Jan 2016 16:36:12 +1100 Subject: [PATCH] Mod biomes are once again copied to our world type --- build.properties | 2 +- .../common/init/ModCompatibility.java | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/build.properties b/build.properties index 7d50f5bc7..daff459bf 100644 --- a/build.properties +++ b/build.properties @@ -1,4 +1,4 @@ minecraft_version=1.8.9 -forge_version=11.15.0.1684 +forge_version=11.15.0.1696 mod_version=3.0.0 mappings_version=snapshot_nodoc_20160104 \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/init/ModCompatibility.java b/src/main/java/biomesoplenty/common/init/ModCompatibility.java index 4de977a8f..d56cea2dc 100644 --- a/src/main/java/biomesoplenty/common/init/ModCompatibility.java +++ b/src/main/java/biomesoplenty/common/init/ModCompatibility.java @@ -1,8 +1,19 @@ package biomesoplenty.common.init; +import java.util.List; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; + +import biomesoplenty.common.enums.BOPClimates; import biomesoplenty.common.integration.ThaumcraftCompat; import biomesoplenty.core.BiomesOPlenty; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.BiomeManager; +import net.minecraftforge.common.BiomeManager.BiomeEntry; +import net.minecraftforge.common.BiomeManager.BiomeType; import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.relauncher.ReflectionHelper; public class ModCompatibility { @@ -19,5 +30,84 @@ public class ModCompatibility BiomesOPlenty.logger.error("There was an error while integrating Thaumcraft with Biomes O' Plenty", e); } } + + copyModBiomeWeights(); + } + + private static void copyModBiomeWeights() + { + try + { + // An array containing lists of default biome entries for only standard BiomeTypes + List[] vanillaBiomes = (List[])ReflectionHelper.findMethod(BiomeManager.class, null, new String[] { "setupBiomes" }).invoke(null); + + for (BiomeType type : BiomeManager.BiomeType.values()) + { + // Creates a mutable version of the current biome type's biome array and wraps entries to support .equals() + List entries = Lists.transform(Lists.newArrayList(BiomeManager.getBiomes(type)), WRAP_BIOME_ENTRIES); + // Custom types may have been added, we only want the vanilla ones + final List vanillaEntries = type.ordinal() < vanillaBiomes.length ? Lists.transform(vanillaBiomes[type.ordinal()], WRAP_BIOME_ENTRIES) : (List)Lists.newArrayList(); + + //Remove all default biomes from the entries list + entries.removeAll(vanillaEntries); + + for (WrappedBiomeEntry wrappedEntry : entries) + { + remapBiomeToBoP(wrappedEntry.biomeEntry.biome, type, wrappedEntry.biomeEntry.itemWeight); + } + } + } + catch (Exception e) + { + BiomesOPlenty.logger.error("An error has occurred whilst copying mod biomes"); + e.printStackTrace(); + return; + } + } + + //TODO: Make this more accurate, possibly analyze heights, temps, rainfall and/or biome dictionary tags + private static void remapBiomeToBoP(BiomeGenBase biome, BiomeType type, int weight) + { + for (BOPClimates climate : BOPClimates.values()) + { + if (climate.biomeType == type) + { + climate.addLandBiome(weight, biome); + } + } + } + + public static final Function WRAP_BIOME_ENTRIES = new Function() + { + @Override + public WrappedBiomeEntry apply(BiomeEntry input) + { + return new WrappedBiomeEntry(input); + } + }; + + /** + * Provides working equals functionality for BiomeEntries + * */ + private static class WrappedBiomeEntry + { + private BiomeEntry biomeEntry; + + private WrappedBiomeEntry(BiomeEntry biomeEntry) + { + this.biomeEntry = biomeEntry; + } + + @Override + public boolean equals(Object input) + { + if (input == null) return false; + if (input == this) return true; + if (!(input instanceof WrappedBiomeEntry)) return false; + + WrappedBiomeEntry other = (WrappedBiomeEntry)input; + + return other.biomeEntry.itemWeight == this.biomeEntry.itemWeight && other.biomeEntry.biome.biomeID == this.biomeEntry.biome.biomeID; + } } }