Jump to content

[1.13.2] Mod configuration using ForgeConfigSpec


BatHeart

Recommended Posts

I've been trying to set up my mod config using the new ForgeConfigSpec calls.

For reference, I have been following the way it is done in ForgeConfig, for Forge's own config.

I am still puzzled because I can't get it to launch without errors.

Does anyone have a working example of this for 1.13.2 - ForgeConfigSpec - that I can examine and learn from?

Link to comment
Share on other sites

My modConfig:

package de.madone.nimox.config;

import net.minecraftforge.common.ForgeConfigSpec;

public class ModConfig {
    private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
    public static final General GENERAL = new General(BUILDER);
    public static final ForgeConfigSpec spec = BUILDER.build();

    public static class General {
        public final ForgeConfigSpec.ConfigValue<Boolean> ModEnabled;
        public final ForgeConfigSpec.ConfigValue<Integer> TorchDistance;

        public General(ForgeConfigSpec.Builder builder) {
            builder.push("General");
            ModEnabled = builder
                    .comment("Enables/Disables the whole Mod [false/true|default:true]")
                    .translation("enable.ocdtorcher.config")
                    .define("enableMod", true);
            TorchDistance = builder
                    .comment("sets the Reach of the Torcher [0..50|default:20]")
                    .translation("distance.ocdtorcher.config")
                    .defineInRange("TorcherDistance", 20, 0,50);
            builder.pop();
        }
    }
}

 

Main-Class-Constructor:

  // load Configfile
        ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.COMMON, de.madone.nimox.config.ModConfig.spec);

 

But it's not available at registration time. (NPE)

  • Thanks 1
Link to comment
Share on other sites

Thanks for this LTNightshade!

I had found another example in the mean time, but all examples are very useful.

I have actually got mine working now, but it appears that the Config button on the Mods screen is not yet implemented (It doesn't work for the Forge internal mod either).

However, I can edit my configuration toml file manually and my mod picks up the changes, which felt like a great leap forward!

 

The one problem I've had to workaround is that my config was split into 3 subsections. I don't know how to do this in the new ForgeConfigSpec implementation without getting crashes. So for the moment I've just used the one config section.

Link to comment
Share on other sites

Where's the problem :)

 

public class ModConfig {
    private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
    public static final General GENERAL = new General(BUILDER);
    public static final Section2 SECTION_2 = new Section2(BUILDER);
    public static final ForgeConfigSpec spec = BUILDER.build();

    public static class General {
        public final ForgeConfigSpec.ConfigValue<Boolean> ModEnabled;
        public final ForgeConfigSpec.ConfigValue<Integer> TorchDistance;

        public General(ForgeConfigSpec.Builder builder) {
            builder.push("General");
            ModEnabled = builder
                    .comment("Enables/Disables the whole Mod [false/true|default:true]")
                    .translation("enable.ocdtorcher.config")
                    .define("enableMod", true);
            TorchDistance = builder
                    .comment("sets the Reach of the Torcher [0..50|default:20]")
                    .translation("distance.ocdtorcher.config")
                    .defineInRange("TorcherDistance", 20, 0,50);
            builder.pop();
        }

    }

    public static class Section2 {
        public final ForgeConfigSpec.ConfigValue<Boolean> BoolVal2;
        public Section2(ForgeConfigSpec.Builder builder) {
            builder.push("section2");
            BoolVal2 = builder
                    .comment("Enables/Disables whatever [false/true|default:true]")
                    .translation("enable.sec2.ocdtorcher.config")
                    .define("ensec2", true);
        }
    }
}

 

Link to comment
Share on other sites

Difficult to describe without screenshots, but I have too many options to put easily on one screen, so in all of my previous versions I split them up into 3 screens.

So when you click on Config the first thing you see is the choice of 3: "Coordinates Options" "Timer Options" or "Infopanel Options".

Clicking on "Coordinates Options" brings up a page of just those options, etc.

I implemented all this in 1.12 using the @config annotation system, which allowed this kind of structure (outer-level config, 3x inner-level configs)

I just don't see whether the new ForgeConfigSpec system permits you to do this.

Link to comment
Share on other sites

Oh. I see your example.

Well, the problem I get when doing that is I get a run time error saying there is a conflict between my mod's config and itself.

It's as though it sees each of them as my mod, and doesn't allow duplicates of the same mod to have config.

 

The log file shows the error as:
[22Feb2019 14:20:01.027] [modloading-worker-1/ERROR] [net.minecraftforge.fml.config.ConfigTracker/CONFIG]: Detected config file conflict coordinatesplusmod-client.toml between coordinatesplusmod and coordinatesplusmod
[22Feb2019 14:20:01.028] [modloading-worker-1/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/LOADING]: Failed to create mod instance. ModID: coordinatesplusmod, class battys.coordinatesplusmod.BattyBaseUI

Edited by BatHeart
log file info
Link to comment
Share on other sites

  • 3 months later...
On 2/22/2019 at 12:55 PM, BatHeart said:

Thanks for this LTNightshade!

I had found another example in the mean time, but all examples are very useful.

I have actually got mine working now, but it appears that the Config button on the Mods screen is not yet implemented (It doesn't work for the Forge internal mod either).

However, I can edit my configuration toml file manually and my mod picks up the changes, which felt like a great leap forward!

 

The one problem I've had to workaround is that my config was split into 3 subsections. I don't know how to do this in the new ForgeConfigSpec implementation without getting crashes. So for the moment I've just used the one config section.

 

How did you update the changes in game?

Link to comment
Share on other sites

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

On 6/20/2019 at 2:24 PM, Vistaf said:

 

How did you update the changes in game?

I couldn't update them in game. As I say in that post, I don't think the in-game config button is implemented yet, so I just updated the toml file manually.

However, since I made that post, I've been shown that the Forge config really wasn't working at that point. Hopefully it's now better, and I'll have another go at including it.

I've had to tell people that basically there is no configuration possible of the 1.13 version of my mod.

Link to comment
Share on other sites

It’s not implemented yet because cpw has much larger priorities and not much free time. Massive amounts of the config GUI code need to be rewritten

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

9 hours ago, Cadiboo said:

It’s not implemented yet because cpw has much larger priorities and not much free time. Massive amounts of the config GUI code need to be rewritten

Thanks. I'd pretty much worked that out back in Feb. I'm prepared to wait. I wasn't going to say anything more, but then I saw the question Vistaf was asking me, and had to clarify.

Link to comment
Share on other sites

On 6/23/2019 at 1:34 AM, Cadiboo said:

It’s not implemented yet because cpw has much larger priorities and not much free time. Massive amounts of the config GUI code need to be rewritten

With your example, do the config values change during runtime? (i.e you don't have to reload the minecraft client in order to get the changes made directly to the config in say a text editor?) and if they do, how? Like which values should i be getting, ive tried like ExampleModConfig.clientBoolean but that doesn't update.

 

Thanks!

Link to comment
Share on other sites

In my example, ConfigHelper.setAndSave saves a value. To use it, you need a ModConfig, a path for the value you want to set, and an actual value to set.

Config saving is done async, so the changes you make will be applied usually within the next 10 seconds. 

 

Examples of setting a value https://github.com/Cadiboo/NoCubes/blob/6c28c100c61e8c629d33a83ba87dbaa41f7f7662/src/main/java/io/github/cadiboo/nocubes/config/ConfigHelper.java#L392-L407

Examples of setting a value + updating the baked value (unclean code, but it gets the job done until there’s a way to force a non-async save+load) https://github.com/Cadiboo/NoCubes/blob/91dcad05ec74621a4af31c0cc5e06ebbb3b094e2/src/main/java/io/github/cadiboo/nocubes/client/ClientEventSubscriber.java#L86-L104


 

Edit: I now use this method (which includes some hacks to replicate the functionality that my PR adds)

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

  • 6 months later...

Has the GUI config button been implemented? (Jan 22, 2020)

 

On Minecraft 1.15.2 Forge 30.0.41, all config buttons are disabled, including the forge one.

When will this feature be available? Should I start migrating to 1.15.2 or stay at 1.12.2?

My mod: SimElectricity - High Voltages, Electrical Power Transmission & Distribution

https://github.com/RoyalAliceAcademyOfSciences/SimElectricity

Link to comment
Share on other sites

Yep, PR: https://github.com/MinecraftForge/MinecraftForge/pull/6421

I’m currently working on the Forge docs for the config system, here’s my tutorial on them in the meantime.

  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.