From 5ba7de449de5775276f871afde3839edc8c802a8 Mon Sep 17 00:00:00 2001 From: An Sar Date: Sat, 27 May 2017 20:26:57 -0700 Subject: [PATCH] config file --- .idea/workspace.xml | 424 ------------------ .../nmd/primal/forgecraft/ForgeCraft.java | 19 +- .../nmd/primal/forgecraft/init/ModConfig.java | 60 +++ 3 files changed, 78 insertions(+), 425 deletions(-) delete mode 100644 .idea/workspace.xml create mode 100644 1.11/src/main/java/nmd/primal/forgecraft/init/ModConfig.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 90d0abbb..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,424 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1482033001334 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/1.11/src/main/java/nmd/primal/forgecraft/ForgeCraft.java b/1.11/src/main/java/nmd/primal/forgecraft/ForgeCraft.java index 11dc2155..25f474ca 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/ForgeCraft.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/ForgeCraft.java @@ -9,10 +9,16 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import nmd.primal.core.common.PrimalCore; import nmd.primal.forgecraft.compat.ModDictionary; import nmd.primal.forgecraft.gui.GuiHandler; import nmd.primal.forgecraft.init.*; import nmd.primal.forgecraft.proxy.CommonProxy; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.util.Locale; //import nmd.primal.forgecraft.common.init.*; @@ -31,15 +37,22 @@ public class ForgeCraft public static SimpleNetworkWrapper NETWORK; @SidedProxy(clientSide = ModInfo.CLIENT_PROXY, serverSide = ModInfo.SERVER_PROXY) public static CommonProxy proxy; + public static Logger LOGGER = LogManager.getLogger(ModInfo.MOD_ID); + private static File CONFIG_FILE; @EventHandler public void preInit(FMLPreInitializationEvent event) { + LOGGER.info("Pre-Init"); + LOGGER.info("Debug Level: " + ModConfig.DEBUG_LEVEL); + + CONFIG_FILE = new File(PrimalCore.getConfigDirectory(), ModInfo.MOD_ID + ".cfg"); + LOGGER.info("Loading Config File: " + CONFIG_FILE); + ModConfig.init(CONFIG_FILE); NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(ModInfo.MOD_CHANNEL); NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler()); - ModBlocks.init(); ModBlocks.register(); ModItems.init(); @@ -56,6 +69,8 @@ public class ForgeCraft @EventHandler public void init(FMLInitializationEvent event) { + LOGGER.info("Init"); + //this.proxy.init(event); proxy.init(); ModDictionary.registerDictionaryNames(); @@ -67,6 +82,8 @@ public class ForgeCraft @EventHandler public void postInit(FMLPostInitializationEvent event) { + LOGGER.info("Post-Init"); + //this.proxy.postInit(event); } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/init/ModConfig.java b/1.11/src/main/java/nmd/primal/forgecraft/init/ModConfig.java new file mode 100644 index 00000000..d04c0b43 --- /dev/null +++ b/1.11/src/main/java/nmd/primal/forgecraft/init/ModConfig.java @@ -0,0 +1,60 @@ +package nmd.primal.forgecraft.init; + +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +import java.io.File; + +public class ModConfig +{ + // ************************************************************************ // + // development + // ************************************************************************ // + public static int DEBUG_LEVEL; + + // ************************************************************************ // + // init config defaults + // ************************************************************************ // + public static void init(File configFile) + { + // you will be able to find the config file in .minecraft/config/ and it will be named "modname".cfg + // here our Configuration has been instantiated, and saved under the name "config" + Configuration config = new Configuration(configFile); + + // loading the configuration from its file + config.load(); + + // + // features + // + //String features_title = "feature hooks"; + //ConfigCategory featuresCategory = config.getCategory(features_title); + //featuresCategory.setComment("Hooks for controlling various aspects of the mod"); + + // + // crafting + // + //String crafting_title = "crafting control"; + //ConfigCategory craftingCategory = config.getCategory(crafting_title); + //craftingCategory.setComment("Control over Crafting"); + + // + // dev and debugging + // + String debug_title = "debug settings"; + ConfigCategory settingCategory = config.getCategory(debug_title); + settingCategory.setComment("Options useful for debugging and server operators"); + + Property dev_debug_level = config.get(debug_title, "DEBUG_LEVEL", 0); + dev_debug_level.setComment("Debug level, by default a zero value disables debug features."); + DEBUG_LEVEL = dev_debug_level.getInt(0); + + // ************************************************************************ // + // save config + // ************************************************************************ // + if(config.hasChanged()) { + config.save(); + } + } +} \ No newline at end of file -- 2.49.1