Jump to content

[1.18.2] Config files being ignored


webox

Recommended Posts

Hi! I'm having an issue with config files being ignored after editing and restarting the client or server (Neither client, common nor server configs are working).

I'm learning how to use config files so my first file is pretty straightforward, I created a  config class that looks like this:

 

package com.webox.myMod.config;

import net.minecraftforge.common.ForgeConfigSpec;

public class MyModCommonConfigs {

    public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
    public static final ForgeConfigSpec SPEC;

    public static final ForgeConfigSpec.ConfigValue<Integer> CITRINE_ORE_VEINS_PER_CHUNK;
    public static final ForgeConfigSpec.ConfigValue<Integer> CITRINE_ORE_VEIN_SIZE;

    static {
        BUILDER.push("Configs for my Mod");

        CITRINE_ORE_VEINS_PER_CHUNK = BUILDER.comment("How many Citrine Ore Veins spawn per chunk!")
                .define("Veins Per Chunk", 7);
        CITRINE_ORE_VEIN_SIZE = BUILDER.comment("How many Citrine Ore Blocks spawn in one Vein!")
                .defineInRange("Vein Size", 8, 4, 20);

        BUILDER.pop();
        SPEC = BUILDER.build();
    }
}

And in my main class I'm using:

public MyMod()
    {
        // Register the setup method for modloading
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        ModItems.register(eventBus);

        // Passing setup functions as parameters with :: operator
        eventBus.addListener(this::commonSetup);
        eventBus.addListener(this::clientSetup);

        //////THIS IS WHERE I REGISTER MY CONFIG FILE ////
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, MyModCommonConfigs.SPEC);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
        var bus = MinecraftForge.EVENT_BUS;


    }

 

And finally, when I try to read a configuration I use:

System.out.println(MyModCommonConfigs.CITRINE_ORE_VEIN_SIZE.get());

 This always outputs the default value no matter what the file says.

-------------------------------------

The entire process seems to work at first, since the toml file is created correctly but whenever I edit for example the vein size, and then try to access it from a place after the registration of the config file I get the default value and not the value that I've overwritten in the toml file. I've no idea what I might be doing wrong, I checked some mods on github and they all seem to be doing the same as me. 

Some important remarks that may help pinpoint the problem:

- I'm not getting any errors on the console, at least that I can distinguish
- I've tried making a client config, a sever config and a common config all with the same result
- I've already tried to generate the jar file and import it into a running forge server and I got the same result, so it's not just on my dev env
- I'm using windows
- I followed this Kaupenjoe tutorial https://www.youtube.com/watch?v=QN9jq3_V-I8&list=PLKGarocXCE1Hut51TKKqZKqVZtKLZC48x&index=62&ab_channel=ModdingbyKaupenjoe
- I'm using forge 40.1.76
- I'm using minecraft 1.18.2
- Whenever I save the file, and the client or server are running I get a message from tracker that says that the file was modified and it's sending notifies 
- I've explored the forum with a ton of keywords but found nothing :(

Thanks in advance! I Hope someone can help me

Edited by webox
Link to comment
Share on other sites

You can't access the config during the static initialization, it will just contain default values.

Config files are not loaded until after registration happens.

In 1.19 it now throws an error if you try to do this.

But you don't need to setup config options for world gen. The world gen configs are overridable via the datapack mechanism.

 

If you do want your world gen to access your config you need to write your own Feature(Configuration) that does this.

Either directly or for example by writing and registering your own IntProvider for use in the feature configuration/json.

This just seems like a lot of work for no real gain.

Edited by warjort
  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Hi warjort!

Thanks for the answer, it steered me in the right direction!! As you said, the error was that I was apprently trying to access before registration finished.

As for the wordlgen part, I should've used a better example, it was just a sample config from the tutorial I was doing, my mod doesn't use worldgen. What I need to do in my config file is store a few strings (item names) that are used to fill a dictionary.

What I don't fully understand is how to know that registration has ended and that the configurations are ready to be read. Yersterday I was placing that println that I showed in the post right after:

MinecraftForge.EVENT_BUS.register(this);

 

But now I assume that's probably not synchronous and that was the reason why I wasn't getting the correct info. What I did now that worked was use the event "onServerStarting" so I did:

   @SubscribeEvent
    public void onServerStarting(ServerStartingEvent event)
    {
      InitizalizeRegistry();
      // Do something when the server starts
      LOGGER.info("HELLO from server starting");
   }

   private static void InitizalizeRegistry() {        
    System.out.println(MyModCommonConfigs.CITRINE_ORE_VEIN_SIZE.get());
   }

When I do that, I get the correct value but I'm not sure if it's the correct thing to do. So I have a few follow up question

- Is there an event to subscribe that is triggered when the registration has ended? Is that event onServerStarting?

Thanks a lot for the help! I've just started learning about minecraft modding with forge like a week or two ago so I'm struggling a bit

 

 

Link to comment
Share on other sites

FMLCommonSetupEvent or FMLClientSetupEvent runs after the config loading (I assume you are not using server configs which are loaded with the world)
.

See: https://forge.gemwire.uk/wiki/Stages_of_Modloading

You should read that wiki in general.

Edited by warjort
  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.