From bdb5caea8d730a1bd50a33b0afa7ac269c88b8c1 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Thu, 16 Jan 2014 15:49:40 +1100 Subject: [PATCH] Village biome config options are now generated dynamically --- .../java/biomesoplenty/BiomesOPlenty.java | 2 + .../biomesoplenty/api/BOPBiomeHelper.java | 8 + .../configuration/BOPConfiguration.java | 2 + .../structures/BOPConfigurationVillages.java | 132 ++++++++++++++ .../biomesoplenty/common/core/BOPBiomes.java | 163 ++++++++++-------- 5 files changed, 234 insertions(+), 73 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/configuration/structures/BOPConfigurationVillages.java diff --git a/src/main/java/biomesoplenty/BiomesOPlenty.java b/src/main/java/biomesoplenty/BiomesOPlenty.java index 774d400e3..4bcafc1b3 100644 --- a/src/main/java/biomesoplenty/BiomesOPlenty.java +++ b/src/main/java/biomesoplenty/BiomesOPlenty.java @@ -3,6 +3,7 @@ package biomesoplenty; import net.minecraft.creativetab.CreativeTabs; import biomesoplenty.common.configuration.BOPConfiguration; import biomesoplenty.common.configuration.BOPConfigurationWorldFeatures; +import biomesoplenty.common.configuration.structures.BOPConfigurationVillages; import biomesoplenty.common.core.BOPArmor; import biomesoplenty.common.core.BOPBiomes; import biomesoplenty.common.core.BOPBlocks; @@ -54,6 +55,7 @@ public class BiomesOPlenty BOPArmor.init(); BOPCrafting.init(); BOPBiomes.init(); + BOPConfigurationVillages.init(BOPConfiguration.villagesConfigFile); WorldGenFieldAssociation.init(); BOPConfigurationWorldFeatures.init(BOPConfiguration.worldFeaturesConfigFile); ForcedBOPWorldGenerators.init(); diff --git a/src/main/java/biomesoplenty/api/BOPBiomeHelper.java b/src/main/java/biomesoplenty/api/BOPBiomeHelper.java index 4d8da5a0e..0e8f3ef94 100644 --- a/src/main/java/biomesoplenty/api/BOPBiomeHelper.java +++ b/src/main/java/biomesoplenty/api/BOPBiomeHelper.java @@ -3,6 +3,9 @@ package biomesoplenty.api; import java.util.ArrayList; import java.util.HashMap; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.text.WordUtils; + import net.minecraft.world.biome.BiomeGenBase; import biomesoplenty.common.world.GenLayerBiomeBOP; @@ -20,6 +23,11 @@ public class BOPBiomeHelper return biomeList.get(name); } + public static String convertBiomeName(String originalName) + { + return StringUtils.remove(StringUtils.uncapitalize(WordUtils.capitalize(originalName)), " "); + } + public static ArrayList getCorrespondingTemperatureTypeList(BOPBiomeTemperatureType type) { switch (type) diff --git a/src/main/java/biomesoplenty/common/configuration/BOPConfiguration.java b/src/main/java/biomesoplenty/common/configuration/BOPConfiguration.java index 60d385d4d..497ae66c9 100644 --- a/src/main/java/biomesoplenty/common/configuration/BOPConfiguration.java +++ b/src/main/java/biomesoplenty/common/configuration/BOPConfiguration.java @@ -8,6 +8,7 @@ public class BOPConfiguration public static File worldFeaturesConfigFile; public static File biomeGenConfigFile; public static File terrainGenConfigFile; + public static File villagesConfigFile; public static File idConfigFile; public static File miscConfigFile; @@ -17,6 +18,7 @@ public class BOPConfiguration worldFeaturesConfigFile = new File(configpath + "worldfeatures.cfg"); biomeGenConfigFile = new File(configpath + "biomegen.cfg"); terrainGenConfigFile = new File(configpath + "terraingen.cfg"); + villagesConfigFile = new File(configpath + "structures/villages.cfg"); idConfigFile = new File(configpath + "ids.cfg"); miscConfigFile = new File(configpath + "misc.cfg"); diff --git a/src/main/java/biomesoplenty/common/configuration/structures/BOPConfigurationVillages.java b/src/main/java/biomesoplenty/common/configuration/structures/BOPConfigurationVillages.java new file mode 100644 index 000000000..b4b4a7c54 --- /dev/null +++ b/src/main/java/biomesoplenty/common/configuration/structures/BOPConfigurationVillages.java @@ -0,0 +1,132 @@ +package biomesoplenty.common.configuration.structures; + +import java.io.File; +import java.util.ArrayList; + +import org.apache.logging.log4j.Level; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.BiomeManager; +import net.minecraftforge.common.config.Configuration; +import biomesoplenty.api.BOPBiomeHelper; + +public class BOPConfigurationVillages +{ + public static Configuration config; + + public static ArrayList enabledBiomes = new ArrayList(); + + public static void addDefaultVillageBiomes() + { + addVillageBiome("alps"); + addVillageBiome("arctic"); + //addVillageBiome("autumnHills"); + //addVillageBiome("badlands"); + addVillageBiome("bambooForest"); + addVillageBiome("bayou"); + addVillageBiome("bog"); + addVillageBiome("borealForest"); + addVillageBiome("brushland"); + addVillageBiome("canyon"); + addVillageBiome("chaparral"); + addVillageBiome("cherryBlossomGrove"); + addVillageBiome("coniferousForest"); + addVillageBiome("snowyConiferousForest"); + addVillageBiome("deadForest"); + //addVillageBiome("deadForestSnow"); + addVillageBiome("deadSwamp"); + addVillageBiome("deciduousForest"); + addVillageBiome("dunes"); + addVillageBiome("fen"); + addVillageBiome("flowerField"); + addVillageBiome("frostForest"); + //addVillageBiome("glacier"); + addVillageBiome("grassland"); + addVillageBiome("grove"); + addVillageBiome("heathland"); + addVillageBiome("highland"); + //addVillageBiome("hotSprings"); + addVillageBiome("jadeCliffs"); + addVillageBiome("lushDesert"); + addVillageBiome("lushSwamp"); + //addVillageBiome("mangrove"); + addVillageBiome("mapleWoods"); + addVillageBiome("marsh"); + addVillageBiome("meadow"); + //addVillageBiome("meadowForest"); + //addVillageBiome("mesa"); + addVillageBiome("moor"); + addVillageBiome("mountain"); + //addVillageBiome("oasis"); + + //addVillageBiome("orchard"); + addVillageBiome("outback"); + //addVillageBiome("overgrownGreens"); + addVillageBiome("pasture"); + //addVillageBiome("polar"); + addVillageBiome("prairie"); + addVillageBiome("quagmire"); + addVillageBiome("rainforest"); + addVillageBiome("redwoodForest"); + + addVillageBiome("seasonalForest"); + addVillageBiome("shield"); + //addVillageBiome("scrubland"); + addVillageBiome("shrubland"); + addVillageBiome("sludgepit"); + addVillageBiome("spruceWoods"); + //addVillageBiome("steppe"); + addVillageBiome("temperateRainforest"); + addVillageBiome("thicket"); + addVillageBiome("timber"); + addVillageBiome("tropicalRainforest"); + addVillageBiome("tropics"); + addVillageBiome("tundra"); + addVillageBiome("volcano"); + + addVillageBiome("wetland"); + addVillageBiome("woodland"); + } + + public static void init(File configFile) + { + addDefaultVillageBiomes(); + + config = new Configuration(configFile); + + try + { + config.load(); + + for (BiomeGenBase biome : BOPBiomeHelper.biomeList.values()) + { + String name = biome.biomeName; + String convertedName = BOPBiomeHelper.convertBiomeName(name); + + if (config.get("Allow Villages", name.replace(" ", ""), enabledBiomes.contains(convertedName)).getBoolean(enabledBiomes.contains(convertedName))) + { + BiomeManager.addVillageBiome(biome, true); + } + } + + FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Generated Villages Config!"); + } + catch (Exception e) + { + FMLLog.log(Level.ERROR, "Biomes O Plenty has had a problem loading its configuration", e); + } + finally + { + if (config.hasChanged()) { + config.save(); + } + } + } + + public static void addVillageBiome(String biomeName) + { + enabledBiomes.add(biomeName); + } +} diff --git a/src/main/java/biomesoplenty/common/core/BOPBiomes.java b/src/main/java/biomesoplenty/common/core/BOPBiomes.java index 786ed8c6c..c21b917e4 100644 --- a/src/main/java/biomesoplenty/common/core/BOPBiomes.java +++ b/src/main/java/biomesoplenty/common/core/BOPBiomes.java @@ -85,7 +85,7 @@ public class BOPBiomes registerBiomes(); useOnlyBiome(); addSpawnBiomes(); - addVillageBiomes(); + //addStrongholdBiomes(); } private static void registerBiomes() @@ -198,74 +198,96 @@ public class BOPBiomes private static void addVillageBiomes() { - addVillageBiome(BOPBiomeHelper.get("alps"), BOPConfigurationTerrainGen.alpsVillage); - addVillageBiome(BOPBiomeHelper.get("arctic"), BOPConfigurationTerrainGen.arcticVillage); - //addVillageBiome(BOPBiomeHelper.get("autumnHills"), BOPConfigurationTerrainGen.autumnHillsVillage); - //addVillageBiome(BOPBiomeHelper.get("badlands"), BOPConfigurationTerrainGen.badlandsVillage); - addVillageBiome(BOPBiomeHelper.get("bambooForest"), BOPConfigurationTerrainGen.bambooForestVillage); - addVillageBiome(BOPBiomeHelper.get("bayou"), BOPConfigurationTerrainGen.bayouVillage); - addVillageBiome(BOPBiomeHelper.get("bog"), BOPConfigurationTerrainGen.bogVillage); - addVillageBiome(BOPBiomeHelper.get("borealForest"), BOPConfigurationTerrainGen.borealForestVillage); - addVillageBiome(BOPBiomeHelper.get("brushland"), BOPConfigurationTerrainGen.brushlandVillage); - addVillageBiome(BOPBiomeHelper.get("canyon"), BOPConfigurationTerrainGen.canyonVillage); - addVillageBiome(BOPBiomeHelper.get("chaparral"), BOPConfigurationTerrainGen.chaparralVillage); - addVillageBiome(BOPBiomeHelper.get("cherryBlossomGrove"), BOPConfigurationTerrainGen.cherryBlossomGroveVillage); - addVillageBiome(BOPBiomeHelper.get("coniferousForest"), BOPConfigurationTerrainGen.coniferousForestVillage); - addVillageBiome(BOPBiomeHelper.get("snowyConiferousForest"), BOPConfigurationTerrainGen.snowyConiferousForest); - addVillageBiome(BOPBiomeHelper.get("deadForest"), BOPConfigurationTerrainGen.deadForestVillage); - //addVillageBiome(BOPBiomeHelper.get("deadForestSnow"), BOPConfigurationTerrainGen.deadForestSnowVillage); - addVillageBiome(BOPBiomeHelper.get("deadSwamp"), BOPConfigurationTerrainGen.deadSwampVillage); - addVillageBiome(BOPBiomeHelper.get("deciduousForest"), BOPConfigurationTerrainGen.deciduousForestVillage); - addVillageBiome(BOPBiomeHelper.get("dunes"), BOPConfigurationTerrainGen.dunesVillage); - addVillageBiome(BOPBiomeHelper.get("fen"), BOPConfigurationTerrainGen.fenVillage); - addVillageBiome(BOPBiomeHelper.get("flowerField"), BOPConfigurationTerrainGen.flowerField); - addVillageBiome(BOPBiomeHelper.get("frostForest"), BOPConfigurationTerrainGen.frostForestVillage); - //addVillageBiome(BOPBiomeHelper.get("glacier"), BOPConfigurationTerrainGen.glacierVillage); - addVillageBiome(BOPBiomeHelper.get("grassland"), BOPConfigurationTerrainGen.grasslandVillage); - addVillageBiome(BOPBiomeHelper.get("grove"), BOPConfigurationTerrainGen.groveVillage); - addVillageBiome(BOPBiomeHelper.get("heathland"), BOPConfigurationTerrainGen.heathlandVillage); - addVillageBiome(BOPBiomeHelper.get("highland"), BOPConfigurationTerrainGen.highlandVillage); - //addVillageBiome(BOPBiomeHelper.get("hotSprings"), BOPConfigurationTerrainGen.hotSpringsVillage); - addVillageBiome(BOPBiomeHelper.get("jadeCliffs"), BOPConfigurationTerrainGen.jadeCliffsVillage); - addVillageBiome(BOPBiomeHelper.get("lushDesert"), BOPConfigurationTerrainGen.lushDesertVillage); - addVillageBiome(BOPBiomeHelper.get("lushSwamp"), BOPConfigurationTerrainGen.lushSwampVillage); - //addVillageBiome(BOPBiomeHelper.get("mangrove"), BOPConfigurationTerrainGen.mangroveVillage); - addVillageBiome(BOPBiomeHelper.get("mapleWoods"), BOPConfigurationTerrainGen.mapleWoodsVillage); - addVillageBiome(BOPBiomeHelper.get("marsh"), BOPConfigurationTerrainGen.marshVillage); - addVillageBiome(BOPBiomeHelper.get("meadow"), BOPConfigurationTerrainGen.meadowVillage); - //addVillageBiome(BOPBiomeHelper.get("meadowForest"), BOPConfigurationTerrainGen.meadowVillage); - //addVillageBiome(BOPBiomeHelper.get("mesa"), BOPConfigurationTerrainGen.mesaVillage); - addVillageBiome(BOPBiomeHelper.get("moor"), BOPConfigurationTerrainGen.moorVillage); - addVillageBiome(BOPBiomeHelper.get("mountain"), BOPConfigurationTerrainGen.mountainVillage); - //addVillageBiome(BOPBiomeHelper.get("oasis"), BOPConfigurationTerrainGen.oasisVillage); - //addVillageBiome(BOPBiomeHelper.get("orchard"), BOPConfigurationTerrainGen.orchardVillage); - addVillageBiome(BOPBiomeHelper.get("outback"), BOPConfigurationTerrainGen.outbackVillage); - //addVillageBiome(BOPBiomeHelper.get("overgrownGreens"), BOPConfigurationTerrainGen.overgrownGreensVillage); - addVillageBiome(BOPBiomeHelper.get("pasture"), BOPConfigurationTerrainGen.pastureVillage); - //addVillageBiome(BOPBiomeHelper.get("polar"), BOPConfigurationTerrainGen.polarVillage); - addVillageBiome(BOPBiomeHelper.get("prairie"), BOPConfigurationTerrainGen.prairieVillage); - addVillageBiome(BOPBiomeHelper.get("quagmire"), BOPConfigurationTerrainGen.quagmireVillage); - addVillageBiome(BOPBiomeHelper.get("rainforest"), BOPConfigurationTerrainGen.rainforestVillage); - addVillageBiome(BOPBiomeHelper.get("redwoodForest"), BOPConfigurationTerrainGen.redwoodForestVillage); + } + + private static void addStrongholdBiomes() + { + /*addStrongholdBiome(Biomes.alps); + addStrongholdBiome(Biomes.arctic); + addStrongholdBiome(Biomes.autumnHills); + addStrongholdBiome(Biomes.badlands); + addStrongholdBiome(Biomes.bambooForest); + addStrongholdBiome(Biomes.bayou); + addStrongholdBiome(Biomes.birchForest); + addStrongholdBiome(Biomes.bog); + addStrongholdBiome(Biomes.borealForest); + addStrongholdBiome(Biomes.brushland); + addStrongholdBiome(Biomes.canyon); + addStrongholdBiome(Biomes.chaparral); + addStrongholdBiome(Biomes.cherryBlossomGrove); + addStrongholdBiome(Biomes.coniferousForest); + addStrongholdBiome(Biomes.coniferousForestSnow); + addStrongholdBiome(Biomes.crag); + addStrongholdBiome(Biomes.deadForest); + addStrongholdBiome(Biomes.deadForestSnow); + addStrongholdBiome(Biomes.deadSwamp); + addStrongholdBiome(Biomes.deadlands); + addStrongholdBiome(Biomes.deciduousForest); + addStrongholdBiome(Biomes.dunes); + addStrongholdBiome(Biomes.fen); + addStrongholdBiome(Biomes.field); + addStrongholdBiome(Biomes.frostForest); + addStrongholdBiome(Biomes.fungiForest); + addStrongholdBiome(Biomes.garden); + addStrongholdBiome(Biomes.glacier); + addStrongholdBiome(Biomes.grassland); + addStrongholdBiome(Biomes.grove); + addStrongholdBiome(Biomes.heathland); + addStrongholdBiome(Biomes.highland); + addStrongholdBiome(Biomes.hotSprings); + addStrongholdBiome(Biomes.icyHills); + addStrongholdBiome(Biomes.jadeCliffs); + addStrongholdBiome(Biomes.lavenderFields); + addStrongholdBiome(Biomes.lushDesert); + addStrongholdBiome(Biomes.lushSwamp); + addStrongholdBiome(Biomes.mangrove); + addStrongholdBiome(Biomes.mapleWoods); + addStrongholdBiome(Biomes.marsh); + addStrongholdBiome(Biomes.meadow); + addStrongholdBiome(Biomes.mesa); + addStrongholdBiome(Biomes.moor); + addStrongholdBiome(Biomes.mountain); + addStrongholdBiome(Biomes.mysticGrove); + addStrongholdBiome(Biomes.oasis); + addStrongholdBiome(Biomes.ominousWoods); + addStrongholdBiome(Biomes.orchard); + addStrongholdBiome(Biomes.outback); + addStrongholdBiome(Biomes.overgrownGreens); + addStrongholdBiome(Biomes.pasture); + addStrongholdBiome(Biomes.polar); + addStrongholdBiome(Biomes.prairie); + addStrongholdBiome(Biomes.quagmire); + addStrongholdBiome(Biomes.rainforest); + addStrongholdBiome(Biomes.redwoodForest); + addStrongholdBiome(Biomes.sacredSprings); + addStrongholdBiome(Biomes.savanna); + addStrongholdBiome(Biomes.scrubland); + addStrongholdBiome(Biomes.seasonalForest); + addStrongholdBiome(Biomes.shield); + addStrongholdBiome(Biomes.shrubland); + addStrongholdBiome(Biomes.silkglades); + addStrongholdBiome(Biomes.sludgepit); + addStrongholdBiome(Biomes.spruceWoods); + addStrongholdBiome(Biomes.steppe); + addStrongholdBiome(Biomes.temperateRainforest); + addStrongholdBiome(Biomes.thicket); + addStrongholdBiome(Biomes.timber); + addStrongholdBiome(Biomes.tropicalRainforest); + addStrongholdBiome(Biomes.tropics); + addStrongholdBiome(Biomes.tundra); + addStrongholdBiome(Biomes.volcano); + addStrongholdBiome(Biomes.wasteland); + addStrongholdBiome(Biomes.wetland); + addStrongholdBiome(Biomes.woodland); - addVillageBiome(BOPBiomeHelper.get("seasonalForest"), BOPConfigurationTerrainGen.seasonalForestVillage); - addVillageBiome(BOPBiomeHelper.get("shield"), BOPConfigurationTerrainGen.shieldVillage); - //addVillageBiome(BOPBiomeHelper.get("scrubland"), BOPConfigurationTerrainGen.scrublandVillage); - addVillageBiome(BOPBiomeHelper.get("shrubland"), BOPConfigurationTerrainGen.shrublandVillage); - addVillageBiome(BOPBiomeHelper.get("sludgepit"), BOPConfigurationTerrainGen.sludgepitVillage); - addVillageBiome(BOPBiomeHelper.get("spruceWoods"), BOPConfigurationTerrainGen.spruceWoodsVillage); - //addVillageBiome(BOPBiomeHelper.get("steppe"), BOPConfigurationTerrainGen.steppeVillage); - addVillageBiome(BOPBiomeHelper.get("temperateRainforest"), BOPConfigurationTerrainGen.temperateRainforestVillage); - addVillageBiome(BOPBiomeHelper.get("thicket"), BOPConfigurationTerrainGen.thicketVillage); - addVillageBiome(BOPBiomeHelper.get("timber"), BOPConfigurationTerrainGen.timberVillage); - addVillageBiome(BOPBiomeHelper.get("tropicalRainforest"), BOPConfigurationTerrainGen.tropicalRainforestVillage); - addVillageBiome(BOPBiomeHelper.get("tropics"), BOPConfigurationTerrainGen.tropicsVillage); - addVillageBiome(BOPBiomeHelper.get("tundra"), BOPConfigurationTerrainGen.tundraVillage); - addVillageBiome(BOPBiomeHelper.get("volcano"), BOPConfigurationTerrainGen.volcanoVillage); - - addVillageBiome(BOPBiomeHelper.get("wetland"), BOPConfigurationTerrainGen.wetlandVillage); - addVillageBiome(BOPBiomeHelper.get("woodland"), BOPConfigurationTerrainGen.woodlandVillage); + addStrongholdBiome(Biomes.plainsNew); + addStrongholdBiome(Biomes.desertNew); + addStrongholdBiome(Biomes.forestNew); + addStrongholdBiome(Biomes.extremeHillsNew); + addStrongholdBiome(Biomes.taigaNew); + addStrongholdBiome(Biomes.swamplandNew); + addStrongholdBiome(Biomes.jungleNew);*/ } public static void registerOnlyBiome(BOPBiomeListEntry biome) @@ -275,7 +297,7 @@ public class BOPBiomes public static void registerBiome(BOPBiomeListEntry biome) { - BOPBiomeHelper.registerBiome(biome.biome, StringUtils.remove(StringUtils.uncapitalize(WordUtils.capitalize(biome.biome.biomeName)), " ")); + BOPBiomeHelper.registerBiome(biome.biome, BOPBiomeHelper.convertBiomeName(biome.biome.biomeName)); addBiomeToList(biome); } @@ -289,11 +311,6 @@ public class BOPBiomes BiomeManager.addSpawnBiome(biome); } - private static void addVillageBiome(BiomeGenBase biome, boolean flag) - { - if (biome != null && flag) BiomeManager.addVillageBiome(biome, true); - } - public static void clearAllSpawnBiomes() { WorldChunkManager.allowedBiomes.clear();