Jump to content

Recommended Posts

Posted

When I set my config option to true in the Config GUI, it doesn't save the change. I set up a System.out.println("[ModCompat] Code Activated"); in the onConfigChanged code, as shown below, and it doesn't activate after setting the config in the Config GUI.

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
System.out.println("[ModCompat] Code Activated");
     if(eventArgs.modID.equals("modcompat")){
        syncConfig();
        }
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Posted

You need to register your EventHandler to the EventBus.

Ok, I've done that, and it still does the same thing. Here is the new code:

Main Class:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}
@EventHandler
public void Init(FMLInitializationEvent event){
MinecraftForge.EVENT_BUS.register(new ConfigChangedHandler());
}
}

 

And the ConfigChangedHandler:

 

public class ConfigChangedHandler {
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
   	 System.out.println("[ModCompat]Config Changed");
     if(eventArgs.modID.equals("modcompat")){
        ModCompatBase.syncConfig();
      	 System.out.println("[ModCompat]ModCompat Config Changed");
     }
}
}

 

EDIT: Another piece of possibly important information: My config is in a subcategory of the main GUI Config, like the way the Minecraft Forge config GUI is set up.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

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.