Jump to content

Recommended Posts

Posted

Hi, I am trying to write to a config file in MC 1.8.9. I type in the new value (90, previously 45), press done, and I go back in the config, and it's 45 again! Code to write to value:

public static void syncConfig() {
	    try {
	        config.load();
	        
	        Property configFOV = config.get(Configuration.CATEGORY_GENERAL,
	                "FOV",
	                "45",
	                "Amount to zoom to");

	        FOVVal = configFOV.getInt();
	        System.out.println(FOVVal);
	    } catch (Exception error) {
	        
	    } finally {
	        config.save();
	    }
	}

Code for detecting if done button is pushed:

protected void actionPerformed(GuiButton button)
    {
        if (button.id == 2000)
        {
        	FOVMod.syncConfig();
            boolean flag = true;
            try
            {
                if ((configID != null || parentScreen == null || !(parentScreen instanceof FOVGuiConfig)) 
                        && (entryList.hasChangedEntry(true)))
                {
                    boolean requiresMcRestart = entryList.saveConfigElements();

                    if (Loader.isModLoaded(Reference.MODID))
                    {
                        ConfigChangedEvent event = new OnConfigChangedEvent(Reference.MODID, "FOV", isWorldRunning, false);
                        MinecraftForge.EVENT_BUS.post(event);
                        if (!event.getResult().equals(Result.DENY))
                            MinecraftForge.EVENT_BUS.post(new PostConfigChangedEvent(Reference.MODID, "FOV", isWorldRunning, false));
                        
                        if (requiresMcRestart)
                        {
                            flag = false;
                            mc.displayGuiScreen(new GuiMessageDialog(parentScreen, "fml.configgui.gameRestartTitle", 
                                    new ChatComponentText(I18n.format("fml.configgui.gameRestartRequired")), "fml.configgui.confirmRestartMessage"));
                        }
                        
                        if (parentScreen instanceof FOVGuiConfig)
                            ((FOVGuiConfig) parentScreen).needsRefresh = true;
                    }
                }
            }
            catch (Throwable e)
            {
                e.printStackTrace();
            }
            
            if (flag)
                mc.displayGuiScreen(parentScreen);
        }
    }

I have been working on this for hours, and any help would be appreciated greatly. Thanks!

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.