diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-04-19 03:30:08 +0100 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-04-19 03:30:08 +0100 |
| commit | 2a7e0a624f482a28af1c770dbcf2a20f52f94f78 (patch) | |
| tree | 39b7652b939dd20763e242fbd49eb6d2ad6924da /src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java | |
| parent | 9dc6f69f701e42b30adf7d1b01488f425eaec265 (diff) | |
Added Midas Touch
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java')
| -rw-r--r-- | src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java | 93 |
1 files changed, 52 insertions, 41 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java b/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java index 9f568a3..9553111 100644 --- a/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java +++ b/src/main/java/darkknight/jewelrycraft/config/ConfigHandler.java @@ -2,54 +2,65 @@ package darkknight.jewelrycraft.config; import java.io.File; import net.minecraftforge.common.config.Configuration; +import cpw.mods.fml.client.event.ConfigChangedEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import darkknight.jewelrycraft.util.Variables; public class ConfigHandler { public static Configuration config; - public static int ingotCoolingTime = 100; - public static int ingotMeltingTime = 1500; - public static int jewelryCraftingTime = 200; - private static boolean isInitialized = false; - public static boolean generateVillageNetherstar = false; - public static boolean canFurnacesGenerateIngots = true; - public static int maxVillageJewelers = 1; - public static int jewelerWeight = 30; - public static int ingotChestMin = 1; - public static int ingotChestMax = 4; - public static int ingotChestMaxStack = 2; - public static int jewelsChestMin = 2; - public static int jewelsChestMax = 5; - public static int furnacesIngotStackMin = 2; - public static int furnacesIngotStackMax = 5; + public static final ConfigHandler INSTANCE = new ConfigHandler(); + public static final String[] categories = { "Timers", "Village Generation"}; - /** - * Generates the config file and all the elements and attributes them to the appropriate variables if they exist - * - * @param e FMLPreInitializationEvent - */ - public static void preInit(FMLPreInitializationEvent e) + public static int INGOT_COOLING_TIME; + public static int INGOT_MELTING_TIME; + public static int GEM_PLACEMENT_TIME; + public static int RITUAL_TIME; + + public static boolean GENERATE_VILLAGE_NETHERSTAR; + public static boolean CAN_FURNACE_GENERATE_INGOTS; + public static int MAX_VILLAGE_JEWELERS; + public static int JEWELER_WEIGHT; + public static int INGOT_CHEST_MIN; + public static int INGOT_CHEST_MAX; + public static int INGOT_CHEST_MAX_STACK; + public static int GEM_CHEST_MIN; + public static int GEM_CHEST_MAX; + public static int FURNACE_MIN_INGOT_STACK; + public static int FURNACE_MAX_INGOT_STACK; + + public void loadConfig(FMLPreInitializationEvent event) + { + config = new Configuration(event.getSuggestedConfigurationFile(),true); + config.load(); + syncConfigs(); + } + + private void syncConfigs() + { + INGOT_COOLING_TIME = config.getInt("Molder Ingot Cooling Time", categories[0], 100, 5, Integer.MAX_VALUE, "This sets the number of ticks you need to wait before the mold is cooled."); + INGOT_MELTING_TIME = config.getInt("Ingot Melting Time", categories[0], 1500, 5, Integer.MAX_VALUE, "This sets the number of ticks you need to wait before an ingot is completely smelted."); + GEM_PLACEMENT_TIME = config.getInt( "Jewelry Crafting Time", categories[0], 200, 5, Integer.MAX_VALUE, "This sets the number of ticks it takes for a jewel to be modified."); + RITUAL_TIME = config.getInt( "Ritual Time", categories[0], 1000, 5, Integer.MAX_VALUE, "This sets the number of ticks it takes for the ritual to end."); + + GENERATE_VILLAGE_NETHERSTAR = config.getBoolean("Netherstar Generation", categories[1], false, "If set to true Nether Stars will be able to generate in Jewelers chests."); + CAN_FURNACE_GENERATE_INGOTS = config.getBoolean("Furnace Ingots Generation", categories[1], true, "If set to true jewelers will generate ingots in furnaces."); + MAX_VILLAGE_JEWELERS = config.getInt("Maximum Jewelers", categories[1], 1, 0, Integer.MAX_VALUE, "Sets how many jewelers can be in a village."); + JEWELER_WEIGHT = config.getInt("Jewelers Weight", categories[1], 30, 0, Integer.MAX_VALUE, "Chance of getting a jeweler in a village. The higher the value, the higher the chance."); + INGOT_CHEST_MIN = config.getInt("Ingot Chest Min", categories[1], 1, 0, Integer.MAX_VALUE, "Minimum number of ingots that can be found in a chest from the Jeweler. (It's the chest from the back part)"); + INGOT_CHEST_MAX = config.getInt("Ingot Chest Max", categories[1], 4, 0, Integer.MAX_VALUE, "Maximum number of ingots that can be found in a chest from the Jeweler. (It's the chest from the back part)"); + INGOT_CHEST_MAX_STACK = config.getInt("Ingot Chest Max Stack", categories[1], 2, 0, Integer.MAX_VALUE, "Maximum number of the stack the ingots can be. For example: if set to 2 and ingots have a chance of generating, you have a chance of getting a stack of max 2 ingots in a chest."); + GEM_CHEST_MIN = config.getInt("Jewelers Chest Min", categories[1], 2, 0, Integer.MAX_VALUE, "Determines the minimum nuber of jewels/modifiers that can be generated in the front chests of a Jeweler."); + GEM_CHEST_MAX = config.getInt("Jewelers Chest Max", categories[1], 5, 0, Integer.MAX_VALUE, "Determines the maximum nuber of jewels/modifiers that can be generated in the front chests of a Jeweler."); + FURNACE_MIN_INGOT_STACK = config.getInt("Ingot Furnace Min", categories[1], 2, 0, Integer.MAX_VALUE, "Determines the minimum number of ingots that can generate in a furnace."); + FURNACE_MAX_INGOT_STACK = config.getInt("Ingot Furnace Max", categories[1], 5, 0, Integer.MAX_VALUE, "Determines the maximum number of ingots that can generate in a furnace."); + if (config.hasChanged()) config.save(); + } + + @SubscribeEvent + public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { - if (!isInitialized){ - config = new Configuration(new File(e.getModConfigurationDirectory(), Variables.MODID+".cfg")); - config.load(); - ingotCoolingTime = config.get("Timers", "Molder Ingot Cooling Time", ingotCoolingTime, "This sets the number of ticks you need to wait before the mold is cooled.").getInt(); - ingotMeltingTime = config.get("Timers", "Ingot Melting Time", ingotMeltingTime, "This sets the number of ticks you need to wait before an ingot is completely smelted.").getInt(); - jewelryCraftingTime = config.get("Timers", "Jewelry Crafting Time", jewelryCraftingTime, "This sets the number of ticks it takes for a jewel to be modified.").getInt(); - generateVillageNetherstar = config.get("Village Generation", "Netherstar Generation", generateVillageNetherstar, "If set to true Nether Stars will be able to generate in Jewelers chests.").getBoolean(generateVillageNetherstar); - canFurnacesGenerateIngots = config.get("Village Generation", "Furnace Ingots Generation", canFurnacesGenerateIngots, "If set to true jewelers will generate ingots in furnaces.").getBoolean(canFurnacesGenerateIngots); - maxVillageJewelers = config.get("Village Generation", "Maximum Jewelers", maxVillageJewelers, "Sets how many jewelers can be in a village.").getInt(); - jewelerWeight = config.get("Village Generation", "Jewelers Weight", jewelerWeight, "Chance of getting a jeweler in a village. The higher the value, the higher the chance.").getInt(); - ingotChestMin = config.get("Village Generation", "Ingot Chest Min", ingotChestMin, "Minimum number of ingots that can be found in a chest from the Jeweler. (It's the chest from the back part)").getInt(); - ingotChestMax = config.get("Village Generation", "Ingot Chest Max", ingotChestMax, "Maximum number of ingots that can be found in a chest from the Jeweler. (It's the chest from the back part)").getInt(); - ingotChestMaxStack = config.get("Village Generation", "Ingot Chest Max Stack", ingotChestMaxStack, "Maximum number of the stack the ingots can be. For example: if set to 2 and ingots have a chance of generating, you have a chance of getting a stack of max 2 ingots in a chest.").getInt(); - jewelsChestMin = config.get("Village Generation", "Jewelers Chest Min", jewelsChestMin, "Determines the minimum nuber of jewels/modifiers that can be generated in the front chests of a Jeweler.").getInt(); - jewelsChestMax = config.get("Village Generation", "Jewelers Chest Max", jewelsChestMax, "Determines the maximum nuber of jewels/modifiers that can be generated in the front chests of a Jeweler.").getInt(); - furnacesIngotStackMin = config.get("Village Generation", "Ingot Furnace Min", furnacesIngotStackMin, "Determines the minimum number of ingots that can generate in a furnace.").getInt(); - furnacesIngotStackMax = config.get("Village Generation", "Ingot Furnace Max", furnacesIngotStackMax, "Determines the maximum number of ingots that can generate in a furnace.").getInt(); - config.save(); - isInitialized = true; - } + if (event.modID.equals(Variables.MODID)) syncConfigs(); } } |
