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

I managed to load configs from a config file. But i can't seem to find where to add the save part to. If i add it to the keypress, it crashes the game. If i add it to the toggleenabled function called by the keypress it crashes the game. I have no gui, other than the keybindings added to Controls.

 

Here is the code i've been trying to use to save the configs.

Configuration config = new Configuration();
    		config.load();
    		Property p;
    		config.addCustomCategoryComment(Configuration.CATEGORY_GENERAL, "Allows you to Enable or Disable the display of Coordinates.");
    		p = config.get(Configuration.CATEGORY_GENERAL, "Enable/Disable", true);
    	    p.comment = "Enable/Disable display of coordinates";
    	    
    	    p.set(EventManager.Enabled);
    	    config.save();

  • Author

Well this is my preInit

@EventHandler
public void preInit(FMLPreInitializationEvent event){
	FMLCommonHandler.instance().bus().register(new com.datacraftcoords.KeyInputHandler());
	com.datacraftcoords.KeyBindings.init();
	Configuration config = new Configuration(event.getSuggestedConfigurationFile());

        config.load();
        EventManager.Enabled = config.get(Configuration.CATEGORY_GENERAL, "Enabled", false).getBoolean(true);

        config.save();
}

 

How would i save the config after the state of EventManager.Enabled has changed?

  • Author

Just in case someone else runs into this issue, here's the code i used to solve it with a little help from diesieben07.

 

This goes in your Mod loader code. The preInit, Init, postInit section.

private File configFile;

@EventHandler
public void preInit(FMLPreInitializationEvent event){
	FMLCommonHandler.instance().bus().register(new KeyInputHandler());
	KeyBindings.init();

	configFile = event.getSuggestedConfigurationFile();
	Configs.LoadConfigSettings(configFile);

 

Next create a new class and paste this code in.

package com.datacraftcoords;
import java.io.File;

import com.datacraftcoords.event.EventManager;

import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;


public class Configs {
public static final String CATEGORY_GENERAL = "general";
public static Configuration config = null;
public static void LoadConfigSettings(File configFile)
    {
    	ReadConfigSettings(configFile, true);
    }
public static void SaveConfigSettings()
    {
    	ReadConfigSettings(null, false);
    }
    
    /**
     * Creates the config file if it doesn't already exist.
     * It loads/saves config values from/to the config file.
     * @param configFile Standard Forge configuration file
     * @param loadSettings set to true to load the settings from the config file, 
     * or false to save the settings to the config file
     */
    private static void ReadConfigSettings(File configFile, boolean loadSettings)
    {
    	//NOTE: doing config.save() multiple times will bug out and add additional quotes to
    	//categories with more than 1 word
    	//Configuration config = null;
    	if(loadSettings)
    	{
            config = new Configuration(configFile);
            config.load();
    	}
        
        Property p;
        config.addCustomCategoryComment(CATEGORY_GENERAL, "Allows you to Enable or Disable the display of Coordinates.");
	p = config.get(CATEGORY_GENERAL, "Enabled", true);
    p.comment = "Enable/Disable display of coordinates";
    
    p.set(EventManager.Enabled);
    config.save();
    }
}

 

Next add this where you want to save your configs.

Configs.SaveConfigSettings();

 

 

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.