Jump to content

Recommended Posts

Posted

On my mod I've got a

GuiFactory

setup to show a config screen in-game. The changes work on the game, but I cannot get it to save to the actual .cfg file. I checked and the .cfg isn't read only. It's even properly putting in the

# Configuration file

header, but isn't updating the settings. Relevant code:

GuiConfig class

 

public class GuiConfigMineCalc extends GuiConfig
{
// http://jabelarminecraft.blogspot.com/p/minecraft-modding-configuration-guis.html
public GuiConfigMineCalc(GuiScreen parent)
{
	super(parent,
			new ConfigElement(MCConfig.getConfig().getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
			MineCalc.MODID, false, false, "Calculate All the Things",
			MCConfig.getConfig().getConfigFile().getAbsolutePath());
}

@Override
public void initGui()
{
	// You can add buttons and initialize fields here
	super.initGui();
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
	// You can do things like create animations, draw additional elements,
	// etc. here
	super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
protected void actionPerformed(GuiButton button)
{
	// You can process any additional buttons you may have added here
	super.actionPerformed(button);
}
}

 

Config class:

 

public class MCConfig
{
private static Configuration config;

public static void loadConfig(File location)
{
	File configFile = new File(location + "/MineCalc.cfg");
	if(!configFile.exists())
	{
		try
		{
			configFile.createNewFile();
		}
		catch(Exception e)
		{
			MineCalc.Logger.warn("Couldn't create a new config file. Reason:");
			MineCalc.Logger.warn(e.getLocalizedMessage());
		}
	}
	config = new Configuration(configFile);
	config.load();

	syncConfig();
}

public static void syncConfig()
{
	returnInput = config.getBoolean("Prepend Input to Output", Configuration.CATEGORY_GENERAL, true, null);
	fancyRemainders = config.getBoolean("Display remainders with a fancy output", Configuration.CATEGORY_GENERAL,
			true, "Looks like: 5 % 2 = 2R1 versus 5 % 2 = 1");
	zeroMultWarns = config.getBoolean("Display warnings when multiplying by 0", Configuration.CATEGORY_GENERAL,
			true, "Also applied to power of 0");

	config.save();
}

@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent event)
{
	if(event.getModID().equalsIgnoreCase(MineCalc.MODID))
	{
		syncConfig();
	}
}

public static boolean returnInput;
public static boolean fancyRemainders;
public static boolean zeroMultWarns;

public static Configuration getConfig()
{
	return config;
}
}

 

From the class with the @mod annotation:

 

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	MCConfig.loadConfig(event.getModConfigurationDirectory());
	MinecraftForge.EVENT_BUS.register(new MCConfig());
}

 

I didn't include the

GuiFactory

class since the only overwritten method simply returns the

GuiConfig

class. Any idea what's wrong?

Posted

I assume you're following a tutorial like this one: http://www.minecraftforge.net/wiki/How_to_make_an_advanced_configuration_file

 

Also, I have a tutorial on config GUI here: http://www.minecraftforge.net/wiki/How_to_make_an_advanced_configuration_file

 

Both of the above were working for 1.8. I'm just going through effort to port to 1.10 so not sure if anything changed, although probably not.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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