summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-19 14:59:50 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-19 14:59:50 +0100
commit62fb391a76901643a9f9baba4faeb11a4d84616a (patch)
tree0aaef161fcc3ce22311b95020faf1103f4cb5240
parent7420844ff22be83bec4d040d6eaedaa8e6f1f76d (diff)
downloadnoctis-62fb391a76901643a9f9baba4faeb11a4d84616a.tar.bz2
Add configuration handling
-rw-r--r--src/main/java/net/flarn/noctis/Noctis.java5
-rw-r--r--src/main/java/net/flarn/noctis/client/gui/GuiFactory.java29
-rw-r--r--src/main/java/net/flarn/noctis/client/gui/ModGuiConfig.java17
-rw-r--r--src/main/java/net/flarn/noctis/handler/ConfigHandler.java42
-rw-r--r--src/main/java/net/flarn/noctis/refs/Refs.java4
5 files changed, 93 insertions, 4 deletions
diff --git a/src/main/java/net/flarn/noctis/Noctis.java b/src/main/java/net/flarn/noctis/Noctis.java
index 37a32a2..8dda04f 100644
--- a/src/main/java/net/flarn/noctis/Noctis.java
+++ b/src/main/java/net/flarn/noctis/Noctis.java
@@ -5,10 +5,11 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import net.flarn.noctis.handler.ConfigHandler;
import net.flarn.noctis.proxy.IProxy;
import net.flarn.noctis.refs.Refs;
-@Mod(modid = Refs.MOD_ID, name = Refs.MOD_NAME, version = Refs.VERSION)
+@Mod(modid = Refs.MOD_ID, name = Refs.MOD_NAME, version = Refs.VERSION, guiFactory = Refs.GUI_FACTORY_CLASS)
public class Noctis {
@Mod.Instance(Refs.MOD_ID)
@@ -20,6 +21,8 @@ public class Noctis {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
// Network, mod config, items, blocks
+ ConfigHandler.init(event.getSuggestedConfigurationFile());
+
}
@Mod.EventHandler
diff --git a/src/main/java/net/flarn/noctis/client/gui/GuiFactory.java b/src/main/java/net/flarn/noctis/client/gui/GuiFactory.java
new file mode 100644
index 0000000..ec732e5
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/client/gui/GuiFactory.java
@@ -0,0 +1,29 @@
+package net.flarn.noctis.client.gui;
+
+import cpw.mods.fml.client.IModGuiFactory;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+
+import java.util.Set;
+
+public class GuiFactory implements IModGuiFactory {
+ @Override
+ public void initialize(Minecraft minecraftInstance) {
+
+ }
+
+ @Override
+ public Class<? extends GuiScreen> mainConfigGuiClass() {
+ return ModGuiConfig.class;
+ }
+
+ @Override
+ public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
+ return null;
+ }
+
+ @Override
+ public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
+ return null;
+ }
+}
diff --git a/src/main/java/net/flarn/noctis/client/gui/ModGuiConfig.java b/src/main/java/net/flarn/noctis/client/gui/ModGuiConfig.java
new file mode 100644
index 0000000..b4d4697
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/client/gui/ModGuiConfig.java
@@ -0,0 +1,17 @@
+package net.flarn.noctis.client.gui;
+
+import cpw.mods.fml.client.config.GuiConfig;
+import net.flarn.noctis.handler.ConfigHandler;
+import net.flarn.noctis.refs.Refs;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraftforge.common.config.ConfigElement;
+import net.minecraftforge.common.config.Configuration;
+
+public class ModGuiConfig extends GuiConfig {
+ public ModGuiConfig(GuiScreen guiScreen) {
+ super(guiScreen,
+ new ConfigElement(ConfigHandler.configuration.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
+ Refs.MOD_ID, false, false,
+ GuiConfig.getAbridgedConfigPath(ConfigHandler.configuration.toString()));
+ }
+}
diff --git a/src/main/java/net/flarn/noctis/handler/ConfigHandler.java b/src/main/java/net/flarn/noctis/handler/ConfigHandler.java
new file mode 100644
index 0000000..b0cf38c
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/handler/ConfigHandler.java
@@ -0,0 +1,42 @@
+package net.flarn.noctis.handler;
+
+import cpw.mods.fml.client.event.ConfigChangedEvent;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import net.flarn.noctis.refs.Refs;
+import net.flarn.noctis.utils.LogHelper;
+import net.minecraftforge.common.config.Configuration;
+
+import java.io.File;
+
+public class ConfigHandler {
+
+ public static Configuration configuration = null;
+
+ public static Boolean cheapRecipes = false;
+
+ public static void init(File configFile) {
+ if (configuration == null) {
+ configuration = new Configuration(configFile);
+ }
+ }
+
+ public void loadConfiguration() {
+ try {
+ cheapRecipes = configuration.getBoolean("cheapRecipes", Configuration.CATEGORY_GENERAL, false,
+ "Use cheap recipes (e.g. sticks instead of diamond swords)");
+ } catch (Exception e) {
+ LogHelper.warn(e);
+ } finally {
+ if (configuration.hasChanged()) {
+ configuration.save();
+ }
+ }
+ }
+
+ @SubscribeEvent
+ public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event) {
+ if (event.modID.equalsIgnoreCase(Refs.MOD_ID)) {
+ loadConfiguration();
+ }
+ }
+}
diff --git a/src/main/java/net/flarn/noctis/refs/Refs.java b/src/main/java/net/flarn/noctis/refs/Refs.java
index a8043da..9aceee1 100644
--- a/src/main/java/net/flarn/noctis/refs/Refs.java
+++ b/src/main/java/net/flarn/noctis/refs/Refs.java
@@ -1,12 +1,10 @@
package net.flarn.noctis.refs;
-/**
- * Created by dsilvers on 19/10/14.
- */
public class Refs {
// Mod strings
public static final String MOD_ID = "Noctis";
public static final String MOD_NAME = "Noctis - Spatio inter Stellarum";
public static final String VERSION = "1.7.10-0.0.1";
+ public static final String GUI_FACTORY_CLASS = "net.flarn.noctis.client.gui.GuiFactory";
}