Re-added support for biomes from other mods. Closes #1670
This commit is contained in:
parent
ae366e8877
commit
7a9533387b
3 changed files with 95 additions and 14 deletions
|
@ -18,6 +18,8 @@ import net.minecraft.util.RegistryKey;
|
|||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biomes;
|
||||
import net.minecraft.world.gen.INoiseRandom;
|
||||
import net.minecraftforge.common.BiomeManager;
|
||||
import net.minecraftforge.common.BiomeManager.BiomeType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
@ -26,27 +28,34 @@ import java.util.stream.Collectors;
|
|||
|
||||
public enum BOPClimates
|
||||
{
|
||||
ICE_CAP,
|
||||
TUNDRA,
|
||||
WET_BOREAL,
|
||||
DRY_BOREAL,
|
||||
WET_TEMPERATE,
|
||||
DRY_TEMPERATE,
|
||||
COOL_TEMPERATE,
|
||||
WARM_TEMPERATE,
|
||||
SUBTROPICAL,
|
||||
TROPICAL,
|
||||
MEDITERRANEAN,
|
||||
SAVANNA,
|
||||
HOT_DESERT,
|
||||
NETHER;
|
||||
ICE_CAP (BiomeType.ICY),
|
||||
TUNDRA (BiomeType.ICY),
|
||||
WET_BOREAL (BiomeType.COOL),
|
||||
DRY_BOREAL (BiomeType.COOL),
|
||||
WET_TEMPERATE (BiomeType.COOL),
|
||||
DRY_TEMPERATE (BiomeType.WARM),
|
||||
COOL_TEMPERATE (BiomeType.COOL),
|
||||
WARM_TEMPERATE (BiomeType.WARM),
|
||||
SUBTROPICAL (BiomeType.WARM),
|
||||
TROPICAL (BiomeType.DESERT),
|
||||
MEDITERRANEAN (BiomeType.WARM),
|
||||
SAVANNA (BiomeType.DESERT),
|
||||
HOT_DESERT (BiomeType.DESERT),
|
||||
WASTELAND (null),
|
||||
NETHER (null);
|
||||
|
||||
public final BiomeType biomeType;
|
||||
private int totalBiomesWeight;
|
||||
private int totalIslandBiomesWeight;
|
||||
|
||||
private ArrayList<WeightedBiomeEntry> landBiomes = Lists.newArrayList();
|
||||
private ArrayList<WeightedBiomeEntry> islandBiomes = Lists.newArrayList();
|
||||
|
||||
BOPClimates(BiomeType biomeType)
|
||||
{
|
||||
this.biomeType = biomeType;
|
||||
}
|
||||
|
||||
public BOPClimates addBiome(int weight, RegistryKey<Biome> biome)
|
||||
{
|
||||
return this.addBiome(new WeightedBiomeEntry(weight, biome));
|
||||
|
|
|
@ -61,6 +61,7 @@ public class BiomesOPlenty
|
|||
private void loadComplete(final FMLLoadCompleteEvent event) // PostRegistrationEven
|
||||
{
|
||||
proxy.init();
|
||||
ModCompatibility.setup();
|
||||
}
|
||||
|
||||
private void serverStarting(final FMLServerAboutToStartEvent event)
|
||||
|
|
71
src/main/java/biomesoplenty/init/ModCompatibility.java
Normal file
71
src/main/java/biomesoplenty/init/ModCompatibility.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2014-2020, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
package biomesoplenty.init;
|
||||
|
||||
import biomesoplenty.api.enums.BOPClimates;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.common.BiomeManager;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModCompatibility
|
||||
{
|
||||
public static void setup()
|
||||
{
|
||||
copyModBiomeWeights();
|
||||
}
|
||||
|
||||
private static void copyModBiomeWeights()
|
||||
{
|
||||
for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values())
|
||||
{
|
||||
// Removes vanilla entries by checking if the biome namespace is not "minecraft"
|
||||
// If a mod makes their biome with minecraft namespace, they need a bug report as that's a big no-no.
|
||||
List<BiomeManager.BiomeEntry> moddedBiomesInType = BiomeManager.getBiomes(type).stream()
|
||||
.filter(biomeEntry -> !biomeEntry.getKey().getRegistryName().getNamespace().equals("minecraft"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// calls remapBiomeToBoP on each modded biome and its weight.
|
||||
moddedBiomesInType.stream().forEach(biomeEntry -> remapBiomeToBoP(biomeEntry.getKey(), type, biomeEntry.weight));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make this more accurate, possibly analyze heights, temps, rainfall and/or biome dictionary tags
|
||||
private static void remapBiomeToBoP(RegistryKey<Biome> biome, BiomeManager.BiomeType type, int weight)
|
||||
{
|
||||
/* If any of our climates already have the biome (from a mod using our api), then skip this biome */
|
||||
for (BOPClimates climate : BOPClimates.values())
|
||||
{
|
||||
List<BOPClimates.WeightedBiomeEntry> entries = Lists.newArrayList();
|
||||
entries.addAll(climate.getLandBiomes());
|
||||
entries.addAll(climate.getIslandBiomes());
|
||||
|
||||
for (BOPClimates.WeightedBiomeEntry entry : entries)
|
||||
{
|
||||
if (entry.biome == biome)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (BOPClimates climate : BOPClimates.values())
|
||||
{
|
||||
if (climate.biomeType == type)
|
||||
{
|
||||
climate.addBiome(weight, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue