From f0ada0dc81dbb1d63fbb2aa592fd90cc5856a8e4 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sun, 29 Mar 2015 15:17:17 +1100 Subject: [PATCH] The BoP WorldType once again functions correctly --- .../common/biome/BOPBiomeManager.java | 45 +++++++++++++++++++ .../config/BiomeConfigurationHandler.java | 8 +--- .../common/util/config/JsonBiome.java | 15 +++++++ .../common/world/layer/GenLayerBiomeBOP.java | 14 +++++- 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/biome/BOPBiomeManager.java diff --git a/src/main/java/biomesoplenty/common/biome/BOPBiomeManager.java b/src/main/java/biomesoplenty/common/biome/BOPBiomeManager.java new file mode 100644 index 000000000..e02b3c64e --- /dev/null +++ b/src/main/java/biomesoplenty/common/biome/BOPBiomeManager.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright 2015, 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.common.biome; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.ImmutableList; + +import net.minecraftforge.common.BiomeManager.BiomeEntry; +import net.minecraftforge.common.BiomeManager.BiomeType; + +public class BOPBiomeManager +{ + private static ArrayList[] biomes = new ArrayList[4]; + + static + { + for (int i = 0; i < biomes.length; i++) + { + biomes[i] = new ArrayList(); + } + } + + public static void addBiome(BiomeType type, BiomeEntry entry) + { + int idx = type.ordinal(); + List list = idx > biomes.length ? null : biomes[idx]; + if (list != null) list.add(entry); + } + + public static ImmutableList getBiomes(BiomeType type) + { + int idx = type.ordinal(); + List list = idx > biomes.length ? null : biomes[idx]; + + return list != null ? ImmutableList.copyOf(list) : null; + } +} diff --git a/src/main/java/biomesoplenty/common/config/BiomeConfigurationHandler.java b/src/main/java/biomesoplenty/common/config/BiomeConfigurationHandler.java index 2b9aa2583..f2ef164f4 100644 --- a/src/main/java/biomesoplenty/common/config/BiomeConfigurationHandler.java +++ b/src/main/java/biomesoplenty/common/config/BiomeConfigurationHandler.java @@ -15,21 +15,18 @@ import java.util.Map; import java.util.Map.Entry; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.gen.feature.WorldGenCactus; -import net.minecraftforge.common.BiomeManager; import net.minecraftforge.common.BiomeManager.BiomeEntry; import net.minecraftforge.common.BiomeManager.BiomeType; -import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate; import org.apache.commons.io.FileUtils; import biomesoplenty.api.biome.BiomeOwner; import biomesoplenty.api.biome.IExtendedBiome; +import biomesoplenty.common.biome.BOPBiomeManager; import biomesoplenty.common.biome.ExtendedBiomeRegistry; import biomesoplenty.common.biome.ExtendedBiomeRegistry.GenerationManager; import biomesoplenty.common.util.config.JsonBiome; import biomesoplenty.common.util.config.JsonEntitySpawn; -import biomesoplenty.core.BiomesOPlenty; import com.google.gson.JsonSyntaxException; @@ -136,8 +133,7 @@ public class BiomeConfigurationHandler //Updates the biome's weights to be in line with the config file extendedBiome.addWeight(biomeType, weight); - //TODO: Change to use our biome manager rather than Vanilla's - BiomeManager.addBiome(biomeType, new BiomeEntry(biome, weight)); + BOPBiomeManager.addBiome(biomeType, new BiomeEntry(biome, weight)); } } diff --git a/src/main/java/biomesoplenty/common/util/config/JsonBiome.java b/src/main/java/biomesoplenty/common/util/config/JsonBiome.java index a17eb8620..2e48552ab 100644 --- a/src/main/java/biomesoplenty/common/util/config/JsonBiome.java +++ b/src/main/java/biomesoplenty/common/util/config/JsonBiome.java @@ -10,12 +10,15 @@ package biomesoplenty.common.util.config; import java.util.ArrayList; import java.util.Map; +import java.util.Map.Entry; import net.minecraft.block.state.IBlockState; import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.BiomeManager.BiomeEntry; import net.minecraftforge.common.BiomeManager.BiomeType; import biomesoplenty.api.biome.IExtendedBiome; import biomesoplenty.api.biome.IGenerator; +import biomesoplenty.common.biome.BOPBiomeManager; import biomesoplenty.common.biome.ExtendedBiomeRegistry; import biomesoplenty.common.biome.ExtendedBiomeRegistry.GenerationManager; @@ -65,6 +68,18 @@ public class JsonBiome biome.weights = extendedBiome.getWeightMap(); biome.decoration = generationManager.getGeneratorMap(); + + //TODO: Add a system for making Vanilla biome weights configurable. This won't necessarily be in this class, however it's worth noting. + for (Entry entry : extendedBiome.getWeightMap().entrySet()) + { + if (entry != null) + { + BiomeType biomeType = entry.getKey(); + int weight = entry.getValue(); + + BOPBiomeManager.addBiome(biomeType, new BiomeEntry(baseBiome, weight)); + } + } } return biome; diff --git a/src/main/java/biomesoplenty/common/world/layer/GenLayerBiomeBOP.java b/src/main/java/biomesoplenty/common/world/layer/GenLayerBiomeBOP.java index 2b1022c93..d48c5d6bc 100644 --- a/src/main/java/biomesoplenty/common/world/layer/GenLayerBiomeBOP.java +++ b/src/main/java/biomesoplenty/common/world/layer/GenLayerBiomeBOP.java @@ -13,6 +13,7 @@ import static net.minecraftforge.common.BiomeManager.BiomeType.DESERT; import static net.minecraftforge.common.BiomeManager.BiomeType.ICY; import static net.minecraftforge.common.BiomeManager.BiomeType.WARM; +import java.util.ArrayList; import java.util.List; import net.minecraft.util.WeightedRandom; @@ -24,6 +25,9 @@ import net.minecraft.world.gen.layer.IntCache; import net.minecraftforge.common.BiomeManager; import net.minecraftforge.common.BiomeManager.BiomeEntry; import net.minecraftforge.fml.relauncher.ReflectionHelper; +import biomesoplenty.common.biome.BOPBiomeManager; + +import com.google.common.collect.ImmutableList; public class GenLayerBiomeBOP extends GenLayerBiome { @@ -36,6 +40,14 @@ public class GenLayerBiomeBOP extends GenLayerBiome biomes = ReflectionHelper.getPrivateValue(GenLayerBiome.class, this, "biomes"); //TODO: Use vanilla biome weights + for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values()) + { + ImmutableList biomesToAdd = BOPBiomeManager.getBiomes(type); + int idx = type.ordinal(); + + if (biomes[idx] == null) biomes[idx] = new ArrayList(); + if (biomesToAdd != null) biomes[idx].addAll(biomesToAdd); + } } @Override @@ -43,7 +55,7 @@ public class GenLayerBiomeBOP extends GenLayerBiome { int[] inputBiomeIds = this.parent.getInts(areaX, areaY, areaWidth, areaHeight); int[] outputBiomeIds = IntCache.getIntCache(areaWidth * areaHeight); - + for (int x = 0; x < areaHeight; ++x) { for (int z = 0; z < areaWidth; ++z)