Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

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/

  • Author

You posted the same link twice.

Edit: I now realize I have a noet linked to one of your articles in the GuiConfig class. Small world or something.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.