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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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