Jump to content

Config Doesnt Update the File or the actual variable


drok0920

Recommended Posts

Hello,

I have made a config using the annotation.  It displays fine but the values dont seem to actually save nor do they change.  Here is my config class:

 

package net.drok.poverhaul;

import net.minecraftforge.common.config.Config;

@Config(modid = POHMod.MODID)
public class ModConfig {

	public static Tools tools = new Tools();
	
	public static class Tools
	{
		@Config.Comment("Defines whether or not to use a more realistic harvest system.")
		public boolean fixedHarvest = true;
		
		@Config.Comment("The speed scaling of tools with a quality of 0")
		public double minToolScaling = 0.3;
		
		@Config.Comment("The speed scaling of tools with a quality of 100")
		public double maxToolScaling = 1.2;
	}
	
}

 

And I am using ModConfig.tools.value to access the values.  As i said i can change them in the gui but the value is always the default value when i print it to the console.

Link to comment
Share on other sites

14 minutes ago, MrBendelScrolls said:

I don't know much about configs, but I believe you need to synchronize your config with ConfigManager#sync().
At least, if you're talking about GUI changes, this is definitely the case. Read below:

 

Where would i call the sync function?  Is there an event?

Link to comment
Share on other sites

I will make it simple.
To save changes made from GUI, subscribe to ConfigChangedEvent.OnConfigChangedEvent. Check if event's modid is the modid of your mod, then call ConfigManager#sync(). I don't have access to sources right now, but the code looks like this:

@EventBusSubscriber
public class ConfigEventHandler {
/* I prefer to make it inner class of my config class,
   but it doesn't have to be, it just needs to be registered.
   Read docs about events if you don't understand. */
  
  @SubscribeEvent
  public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
    if (event.getModid().equals(modid) {
      ConfigManager.sync(modid, Config.Type.INSTANCE);
    }
  }
}

 

I believe,ConfigManager#sync() also saves changes made to fields to your config file, but as I said, I don't know much about configs .

  • Like 1
Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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