I made a config file using the new in game config gui with forge but when I change the properties in the gui, nothing changes in the game, but if I change the config directly it works. Maybe an issue with not saving the config? Not sure, here's all the code:
ConfigurationHandler.java
package com.phobophobe.lifehacks;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.common.config.Configuration;
import java.io.File;
public class ConfigurationHandler
{
public static Configuration configuration;
public static boolean enableXray;
public static void init(File configFile)
{
// Create the configuration object from the given configuration file
if (configuration == null)
{
configuration = new Configuration(configFile);
loadConfiguration();
}
}
private static void loadConfiguration()
{
enableXray = configuration.getBoolean("Enable X-Ray Block", Configuration.CATEGORY_GENERAL, false, "Enables or disables X-Ray Block");
configuration.save();
}
@SubscribeEvent
public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{
if (event.modID.equalsIgnoreCase(MainRegistry.MODID))
{
loadConfiguration();
}
}
}
GuiFactory.java
package com.phobophobe.lifehacks;
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 GuiConfigLifeHacks.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
{
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element)
{
return null;
}
}
GuiConfigLifeHacks.java
package com.phobophobe.lifehacks;
import cpw.mods.fml.client.config.GuiConfig;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
public class GuiConfigLifeHacks extends GuiConfig
{
public GuiConfigLifeHacks(GuiScreen guiScreen)
{
super(guiScreen,
new ConfigElement(ConfigurationHandler.configuration.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
MainRegistry.MODID,
false,
false,
GuiConfig.getAbridgedConfigPath(ConfigurationHandler.configuration.toString()));
}
}
ConfigurationHandler.java
GuiFactory.java
GuiConfigLifeHacks.java
You need to hook the ingame config changed event :
@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent event)
{
if (event.modID.equals(Const.MODID)) ModConfig.syncConfig();
}
My Released Mods
Twitter