aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/makamys/neodymium/Config.java22
-rw-r--r--src/main/java/makamys/neodymium/GuiFactory.java35
-rw-r--r--src/main/java/makamys/neodymium/NdGuiConfig.java14
-rw-r--r--src/main/java/makamys/neodymium/Neodymium.java16
4 files changed, 85 insertions, 2 deletions
diff --git a/src/main/java/makamys/neodymium/Config.java b/src/main/java/makamys/neodymium/Config.java
index 86aade3..54a7017 100644
--- a/src/main/java/makamys/neodymium/Config.java
+++ b/src/main/java/makamys/neodymium/Config.java
@@ -21,11 +21,16 @@ import java.nio.file.Files;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
+import java.util.ArrayList;
+import java.util.List;
import org.lwjgl.input.Keyboard;
+import cpw.mods.fml.client.config.IConfigElement;
import net.minecraft.launchwrapper.Launch;
+import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.config.Property;
public class Config {
@@ -69,6 +74,7 @@ public class Config {
@ConfigBoolean(cat="debug", def=false)
public static boolean wireframe;
+ private static Configuration config;
private static File configFile = new File(Launch.minecraftHome, "config/" + MODID + ".cfg");
private static WatchService watcher;
@@ -83,7 +89,7 @@ public class Config {
e.printStackTrace();
}
- Configuration config = new Configuration(configFile, Neodymium.VERSION);
+ config = new Configuration(configFile, Neodymium.VERSION);
config.load();
@@ -186,6 +192,20 @@ public class Config {
configFile.toPath().getParent().register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
}
+ public static List<IConfigElement> getElements() {
+ List<IConfigElement> list = new ArrayList<IConfigElement>();
+ for(Property prop : config.getCategory("render").values()) {
+ list.add(new ConfigElement(prop));
+ }
+ return list;
+ }
+
+ public static void flush() {
+ if(config.hasChanged()) {
+ config.save();
+ }
+ }
+
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public static @interface NeedsReload {
diff --git a/src/main/java/makamys/neodymium/GuiFactory.java b/src/main/java/makamys/neodymium/GuiFactory.java
new file mode 100644
index 0000000..7db2e32
--- /dev/null
+++ b/src/main/java/makamys/neodymium/GuiFactory.java
@@ -0,0 +1,35 @@
+package makamys.neodymium;
+
+import java.util.Set;
+
+import cpw.mods.fml.client.IModGuiFactory;
+import cpw.mods.fml.client.config.GuiConfig;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+
+public class GuiFactory implements IModGuiFactory {
+
+ @Override
+ public void initialize(Minecraft minecraftInstance) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Class<? extends GuiScreen> mainConfigGuiClass() {
+ return NdGuiConfig.class;
+ }
+
+ @Override
+ public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/main/java/makamys/neodymium/NdGuiConfig.java b/src/main/java/makamys/neodymium/NdGuiConfig.java
new file mode 100644
index 0000000..d61dffd
--- /dev/null
+++ b/src/main/java/makamys/neodymium/NdGuiConfig.java
@@ -0,0 +1,14 @@
+package makamys.neodymium;
+
+import static makamys.neodymium.Neodymium.MODID;
+
+import cpw.mods.fml.client.config.GuiConfig;
+import net.minecraft.client.gui.GuiScreen;
+
+public class NdGuiConfig extends GuiConfig {
+
+ public NdGuiConfig(GuiScreen parent) {
+ super(parent, Config.getElements(), MODID, MODID, false, false, "Neodymium render settings");
+ }
+
+}
diff --git a/src/main/java/makamys/neodymium/Neodymium.java b/src/main/java/makamys/neodymium/Neodymium.java
index 8602e60..932e33f 100644
--- a/src/main/java/makamys/neodymium/Neodymium.java
+++ b/src/main/java/makamys/neodymium/Neodymium.java
@@ -7,6 +7,8 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+
+import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
@@ -35,7 +37,7 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
-@Mod(modid = Neodymium.MODID, version = Neodymium.VERSION)
+@Mod(modid = Neodymium.MODID, version = Neodymium.VERSION, guiFactory = "makamys.neodymium.GuiFactory")
public class Neodymium
{
public static final String MODID = "neodymium";
@@ -61,6 +63,11 @@ public class Neodymium
public void preInit(FMLPreInitializationEvent event)
{
MCLibModules.updateCheckAPI.submitModTask(MODID, "@UPDATE_URL@");
+
+ if(VERSION.equals("@VERSION@")) {
+ // Allow using config GUI in dev env
+ event.getModMetadata().autogenerated = false;
+ }
}
@EventHandler
@@ -70,6 +77,13 @@ public class Neodymium
MinecraftForge.EVENT_BUS.register(this);
}
+ @SubscribeEvent
+ public void onConfigChanged(ConfigChangedEvent event) {
+ if(event.modID.equals(MODID)) {
+ Config.flush();
+ }
+ }
+
@EventHandler
public void onServerAboutToStart(FMLServerAboutToStartEvent event)
{