From ef4b82a338b7069b54bfd760a3878e3bc6e9a3a3 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Mon, 9 Mar 2015 12:07:39 +1100 Subject: [PATCH] Added a config option for the BoP worldtype to be selected by default Closes #410 --- .../biomesoplenty/api/biome/BOPBiomes.java | 18 ++++++++ .../config/MiscConfigurationHandler.java | 42 +++++++++++++++++++ ...EventHandler.java => GuiEventHandler.java} | 22 ++++++++-- .../biomesoplenty/common/init/ModBlocks.java | 6 +-- .../common/init/ModConfiguration.java | 3 +- .../common/init/ModHandlers.java | 4 +- .../biomesoplenty/core/BiomesOPlenty.java | 5 +++ 7 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 src/main/java/biomesoplenty/api/biome/BOPBiomes.java create mode 100644 src/main/java/biomesoplenty/common/config/MiscConfigurationHandler.java rename src/main/java/biomesoplenty/common/handler/{DrawScreenEventHandler.java => GuiEventHandler.java} (72%) diff --git a/src/main/java/biomesoplenty/api/biome/BOPBiomes.java b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java new file mode 100644 index 000000000..565c44dc5 --- /dev/null +++ b/src/main/java/biomesoplenty/api/biome/BOPBiomes.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * 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.api.biome; + +import net.minecraft.world.biome.BiomeGenBase; + +import com.google.common.base.Optional; + +public class BOPBiomes +{ + public static Optional alps; +} diff --git a/src/main/java/biomesoplenty/common/config/MiscConfigurationHandler.java b/src/main/java/biomesoplenty/common/config/MiscConfigurationHandler.java new file mode 100644 index 000000000..dc00e1ba8 --- /dev/null +++ b/src/main/java/biomesoplenty/common/config/MiscConfigurationHandler.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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.config; + +import java.io.File; + +import biomesoplenty.core.BiomesOPlenty; +import net.minecraftforge.common.config.Configuration; + +public class MiscConfigurationHandler +{ + public static Configuration config; + + public static boolean useBoPWorldTypeDefault; + + public static void init(File configFile) + { + config = new Configuration(configFile); + + try + { + config.load(); + + //TODO: Make this default to true once all biomes have been implemented + useBoPWorldTypeDefault = config.getBoolean("Default to BoP World Type", "GUI Settings", false, "Use the Biomes O' Plenty World Type by default when selecting a world."); + } + catch (Exception e) + { + BiomesOPlenty.logger.error("Biomes O' Plenty has encountered a problem loading misc.cfg", e); + } + finally + { + if (config.hasChanged()) config.save(); + } + } +} diff --git a/src/main/java/biomesoplenty/common/handler/DrawScreenEventHandler.java b/src/main/java/biomesoplenty/common/handler/GuiEventHandler.java similarity index 72% rename from src/main/java/biomesoplenty/common/handler/DrawScreenEventHandler.java rename to src/main/java/biomesoplenty/common/handler/GuiEventHandler.java index 2f21dace8..2b5d54ee8 100644 --- a/src/main/java/biomesoplenty/common/handler/DrawScreenEventHandler.java +++ b/src/main/java/biomesoplenty/common/handler/GuiEventHandler.java @@ -11,19 +11,33 @@ package biomesoplenty.common.handler; import java.util.ArrayList; import java.util.List; -import biomesoplenty.common.init.ModBiomes; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiCreateWorld; import net.minecraft.client.gui.GuiScreen; import net.minecraft.world.WorldType; import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import biomesoplenty.common.config.MiscConfigurationHandler; +import biomesoplenty.common.init.ModBiomes; -public class DrawScreenEventHandler +public class GuiEventHandler { public static int blockCount = 0; + @SubscribeEvent + public void onPreInitCreateWorld(InitGuiEvent.Pre event) + { + GuiScreen screenGui = event.gui; + + if (MiscConfigurationHandler.useBoPWorldTypeDefault && screenGui instanceof GuiCreateWorld) + { + GuiCreateWorld createWorldGui = (GuiCreateWorld)screenGui; + + createWorldGui.selectedIndex = ModBiomes.worldTypeBOP.getWorldTypeID(); + } + } + @SubscribeEvent public void onDrawScreen(DrawScreenEvent.Post event) { @@ -31,7 +45,7 @@ public class DrawScreenEventHandler if (screenGui instanceof GuiCreateWorld) { - GuiCreateWorld createWorldGui = (GuiCreateWorld) screenGui; + GuiCreateWorld createWorldGui = (GuiCreateWorld)screenGui; GuiButton mapTypeButton = createWorldGui.btnMapType; int worldTypeIndex = createWorldGui.selectedIndex; diff --git a/src/main/java/biomesoplenty/common/init/ModBlocks.java b/src/main/java/biomesoplenty/common/init/ModBlocks.java index 85c9ff550..b3e02a728 100644 --- a/src/main/java/biomesoplenty/common/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/common/init/ModBlocks.java @@ -34,7 +34,7 @@ import biomesoplenty.common.block.BlockCoral; import biomesoplenty.common.block.BlockGem; import biomesoplenty.common.block.BlockGemOre; import biomesoplenty.common.block.BlockHive; -import biomesoplenty.common.handler.DrawScreenEventHandler; +import biomesoplenty.common.handler.GuiEventHandler; import biomesoplenty.common.item.ItemBlockWithVariants; import biomesoplenty.common.util.block.BlockStateUtils; import biomesoplenty.core.BiomesOPlenty; @@ -79,7 +79,7 @@ public class ModBlocks ModelBakery.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + stateName); BiomesOPlenty.proxy.registerBlockForMeshing(block, block.getMetaFromState(state), stateName); - DrawScreenEventHandler.blockCount++; + GuiEventHandler.blockCount++; } } else @@ -89,7 +89,7 @@ public class ModBlocks ModelBakery.addVariantName(Item.getItemFromBlock(block), BiomesOPlenty.MOD_ID + ":" + name); BiomesOPlenty.proxy.registerBlockForMeshing(block, 0, name); - DrawScreenEventHandler.blockCount++; + GuiEventHandler.blockCount++; } return block; diff --git a/src/main/java/biomesoplenty/common/init/ModConfiguration.java b/src/main/java/biomesoplenty/common/init/ModConfiguration.java index de5488fb3..321fbce17 100644 --- a/src/main/java/biomesoplenty/common/init/ModConfiguration.java +++ b/src/main/java/biomesoplenty/common/init/ModConfiguration.java @@ -11,12 +11,13 @@ package biomesoplenty.common.init; import java.io.File; import biomesoplenty.common.config.BiomeConfigurationHandler; +import biomesoplenty.common.config.MiscConfigurationHandler; public class ModConfiguration { public static void init(File configDirectory) { - + MiscConfigurationHandler.init(new File(configDirectory, "misc.cfg")); } public static void initEnd(File configDirectory) diff --git a/src/main/java/biomesoplenty/common/init/ModHandlers.java b/src/main/java/biomesoplenty/common/init/ModHandlers.java index 384c07a4a..956820b9a 100644 --- a/src/main/java/biomesoplenty/common/init/ModHandlers.java +++ b/src/main/java/biomesoplenty/common/init/ModHandlers.java @@ -9,7 +9,7 @@ package biomesoplenty.common.init; import net.minecraftforge.common.MinecraftForge; -import biomesoplenty.common.handler.DrawScreenEventHandler; +import biomesoplenty.common.handler.GuiEventHandler; import biomesoplenty.common.handler.decoration.DecorateBiomeEventHandler; public class ModHandlers @@ -17,6 +17,6 @@ public class ModHandlers public static void init() { MinecraftForge.TERRAIN_GEN_BUS.register(new DecorateBiomeEventHandler()); - MinecraftForge.EVENT_BUS.register(new DrawScreenEventHandler()); + MinecraftForge.EVENT_BUS.register(new GuiEventHandler()); } } diff --git a/src/main/java/biomesoplenty/core/BiomesOPlenty.java b/src/main/java/biomesoplenty/core/BiomesOPlenty.java index 72bfa8a27..d717a819b 100644 --- a/src/main/java/biomesoplenty/core/BiomesOPlenty.java +++ b/src/main/java/biomesoplenty/core/BiomesOPlenty.java @@ -10,6 +10,9 @@ package biomesoplenty.core; import java.io.File; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; @@ -35,6 +38,8 @@ public class BiomesOPlenty @SidedProxy(clientSide = "biomesoplenty.core.ClientProxy", serverSide = "biomesoplenty.core.CommonProxy") public static CommonProxy proxy; + public static Logger logger = LogManager.getLogger(MOD_ID); + private File configDirectory; @EventHandler