So I have recently been working on a minecraft 1.8.9 forge mod, just to play around and see what there is (eventually I am planning on making a utilities mod with versions for 1.8-1.19, which is why I'm so far back). I have had no problems... until I got to configs. I already have code to create and read from a config file, but I can not figure out how to use MinecraftForge's mod options > config menu to allow GUI modification of the settings. I have had no luck finding any information on how to do this back in 1.8, so if anyone could help me out a bit (linking sources, giving example code, or referring me to a forge class that has the relevant code in it), I would greatly appreciate it.
TL;DR I need help implementing forge's config gui system.
My current config code (in the Main class):
public static Configuration config;
private File confDir;
public static Logger lmao;
public static Configuration getConfig()
{
return config;
}
@EventHandler
public void preinit(FMLPreInitializationEvent event) {
lmao = event.getModLog();
confDir = event.getModConfigurationDirectory();
config = null;
File configFile = new File(confDir,"config.cfg");
config = new Configuration(configFile);
syncConfig(true);
event.getModLog().log(Level.ALL,"Preinitialization complete.");
}
private static void syncConfig(boolean load)
{
List<String> propOrder = new ArrayList<String>();
if (!config.isChild)
{
if (load)
{
config.load();
}
Property enableGlobalCfg = config.get(CATEGORY_GENERAL, "enableGlobalConfig", false).setShowInGui(false);
if (enableGlobalCfg.getBoolean(false))
{
Configuration.enableGlobalConfig();
}
}
Property prop;
//set prop value, then:
//propOrder.add(prop.getName());
prop = config.get(CATEGORY_GENERAL,"testbool",false);
prop.comment = "for testing purposes";
prop.setLanguageKey("mod.conf.testbool");
propOrder.add(prop.getName());
prop = reConf.get(CATEGORY_GENERAL,"testvar","can you see this?");
prop.comment = "for testing purposes only";
prop.setLanguageKey("mod.conf.teststring");
propOrder.add(prop.getName());
config.setCategoryPropertyOrder(CATEGORY_GENERAL, propOrder);
if (config.hasChanged())
{
config.save();
}
}
public static void syncConf(boolean load1) {
//public configuration sync method
syncConfig(load1);
}
@SubscribeEvent
public void onConfigChangedEvent(OnConfigChangedEvent event)
{
if (event.modID.equals(MODID))
{
if (Configuration.CATEGORY_GENERAL.equals(event.configID))
{
syncConfig(false);
}
}
}
//much of this was taken from or inspired by forge's source code, and adapted to work with this mod.
I have written some GUI code, but managed to mess it up enough that I will just rewrite it based off ForgeGuiFactory.java later, which is why I have attached no GUI code here.
If anyone can help, please do. If this post is breaking a forum rule, DEFINITELY tell me, since I need to know.
Thanks ahead of time,
-MiSt_Rocky