Jump to content

Forge Configuration API


OnePoundPP

Recommended Posts

What are the basic ways of creating/readingfrom/writing to config files? I have searched for the forge config api on the docs but all links on google take you to the readthedocs homepage...

 

If anyone could tell me, or link me a working example (as the docs are screwed) of how to:

Create a base config file if one doesn't exist

Write to a config file

Read from a config file

 

Thanks for anyone willing to help :)

Link to comment
Share on other sites

I'd look at:

net.minecraftforge.common.config.Configuration

...

 

 

Here is a class from an older mod I have:

public class Config {

    public static Configuration config;

    public static void preInit() {
        config = new Configuration(new File(Reference.MAIN_FOLDER + "/Enabled_Modules.cfg"));

        try{
            config.load();

            // module on/off states \\
            RingsHUD.Enabled = config.getBoolean("CheckpointHUD","Modules",true,"Whether to show the CheckpointHUD.");
            RingsHUD.DisableChat = config.getBoolean("DisableCPChat","Modules",true,"Whether to disable the checkpoint reached message in chat.");
            TIPCanceler.Enabled = config.getBoolean("ShowTips","Modules",true,"Whether to show Tips.");
            TimerGuiClass.Enabled = config.getBoolean("ShowTimer","Modules",true,"Whether to show the Timer.");


        }catch(Exception e){
            System.out.println("Error loading config, returning to default variables.");
        }finally {
            config.save();
        }
    }

    public static void setModule(String module, boolean to){
        config.get("Modules",module,true).set(to);
        config.save();
        preInit();
    }
}

Ofc the preInit is called from the mod's preInit,

But you can call it anytime I'm pretty sure to update it...

Its my code so if something dont work dont blame me cuz im stupid :D

 

I used the

setModule(String module, boolean to)

to set the module's state ingame, a.k.a in an options gui...

Doing stuff n' things

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.