Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Cant Get a Config File Working 1.16.5

Recommended Posts

I've been trying to get a config file working for my mod so that certain armor sets can be disabled. I followed a tutorial i found on youtube, however it doesnt seem to be working.


It seems that i am always getting the default value for each option, rather than the one in the config file.


My config class is as follows:


import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
import org.apache.commons.lang3.tuple.Pair;

public class ArmorConfig {

    public static class Common {

        public final BooleanValue enableOakWood;
        public final BooleanValue enableBirchWood;
        public final BooleanValue enableJungleWood;
        public final BooleanValue enableSpruceWood;
        public final BooleanValue enableDarkOakWood;
        public final BooleanValue enableAcaciaWood;
        public final BooleanValue enableCactus;
        public final BooleanValue enableObsidian;
        public final BooleanValue enableMagma;
        public final BooleanValue enableMelon;
        public final BooleanValue enableQuartz;
        public final BooleanValue enableBone;
        public final BooleanValue enableMolten;
        public final BooleanValue enablePumpkin;
        public final BooleanValue enablePhantom;
        public final BooleanValue enableGhost;
        public final BooleanValue enableCryingObsidian;
        public final BooleanValue enableIce;
        public final BooleanValue enableSnow;
        public final BooleanValue enableGlowstone;
        public final BooleanValue enablePrismarineShard;
        public final BooleanValue enablePrismarineCrystal;
        public final BooleanValue enableHoneycomb;
        public final BooleanValue enableEmerald;
        public final BooleanValue enableEnder;

        Common(ForgeConfigSpec.Builder builder){
            builder.comment("Armor Config")

            enableOakWood = builder
                    .comment("Enable or Disable Oak Wood Armor")
                    .define("enableOakWood", true);
            enableBirchWood = builder
                    .comment("Enable or Disable Birch Wood Armor")
                    .define("enableBirchWood", true);
            enableJungleWood = builder
                    .comment("Enable or Disable Jungle Wood Armor")
                    .define("enableJungleWood", true);
            enableSpruceWood = builder
                    .comment("Enable or Disable Spruce Wood Armor")
                    .define("enableSpruceWood", true);
            enableDarkOakWood = builder
                    .comment("Enable or Disable Dark Oak Wood Armor")
                    .define("enableDarkOakWood", true);
            enableAcaciaWood = builder
                    .comment("Enable or Disable Acacia Wood Armor")
                    .define("enableAcaciaWood", true);
            enableCactus = builder
                    .comment("Enable or Disable Cactus Armor")
                    .define("enableCactus", true);
            enableObsidian = builder
                    .comment("Enable or Disable Obsidian Armor")
                    .define("enableObsidian", true);
            enableMagma = builder
                    .comment("Enable or Disable Magma Armor")
                    .define("enableMagma", true);
            enableMelon = builder
                    .comment("Enable or Disable Melon Armor")
                    .define("enableMelon", true);
            enableQuartz = builder
                    .comment("Enable or Disable Quartz Armor")
                    .define("enableQuartz", true);
            enableBone = builder
                    .comment("Enable or Disable Bone Armor")
                    .define("enableBone", true);
            enableMolten = builder
                    .comment("Enable or Disable Molten Armor")
                    .define("enableMolten", true);
            enablePumpkin = builder
                    .comment("Enable or Disable Pumpkin Armor")
                    .define("enablePumpkin", true);
            enablePhantom = builder
                    .comment("Enable or Disable Phantom Armor")
                    .define("enablePhantom", true);
            enableGhost = builder
                    .comment("Enable or Disable Ghost Armor")
                    .define("enableGhost", true);
            enableCryingObsidian = builder
                    .comment("Enable or Disable Crying Obsidian Armor")
                    .define("enableCryingObsidian", true);
            enableIce = builder
                    .comment("Enable or Disable Ice Armor")
                    .define("enableIce", true);
            enableSnow = builder
                    .comment("Enable or Disable Snow Armor")
                    .define("enableSnow", true);
            enableGlowstone = builder
                    .comment("Enable or Disable Glowstone Armor")
                    .define("enableGlowstone", true);
            enablePrismarineShard = builder
                    .comment("Enable or Disable Prismarine Shard Armor")
                    .define("enablePrismarineShard", true);
            enablePrismarineCrystal = builder
                    .comment("Enable or Disable Prismarine Crystal Armor")
                    .define("enablePrismarineCrystal", true);
            enableHoneycomb = builder
                    .comment("Enable or Disable Honeycomb Armor")
                    .define("enableHoneycomb", true);
            enableEmerald = builder
                    .comment("Enable or Disable Emerald Armor")
                    .define("enableEmerald", true);
            enableEnder = builder
                    .comment("Enable or Disable Ender Armor")
                    .define("enableEnder", true);


    public static final ForgeConfigSpec COMMON_SPEC;
    public static final Common COMMON;
                final Pair<Common, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Common::new);
                COMMON_SPEC = specPair.getRight();
                COMMON = specPair.getLeft();



and the config file (generated):


#Armor Config
	#Enable or Disable Cactus Armor
	enableCactus = true
	#Enable or Disable Honeycomb Armor
	enableHoneycomb = true
	#Enable or Disable Oak Wood Armor
	enableOakWood = true
	#Enable or Disable Obsidian Armor
	enableObsidian = true
	#Enable or Disable Ice Armor
	enableIce = true
	#Enable or Disable Glowstone Armor
	enableGlowstone = true
	#Enable or Disable Acacia Wood Armor
	enableAcaciaWood = true
	#Enable or Disable Crying Obsidian Armor
	enableCryingObsidian = true
	#Enable or Disable Molten Armor
	enableMolten = true
	#Enable or Disable Melon Armor
	enableMelon = true
	#Enable or Disable Ender Armor
	enableEnder = true
	#Enable or Disable Prismarine Crystal Armor
	enablePrismarineCrystal = true
	#Enable or Disable Birch Wood Armor
	enableBirchWood = true
	#Enable or Disable Pumpkin Armor
	enablePumpkin = true
	#Enable or Disable Spruce Wood Armor
	enableSpruceWood = true
	#Enable or Disable Magma Armor
	enableMagma = true
	#Enable or Disable Dark Oak Wood Armor
	enableDarkOakWood = true
	#Enable or Disable Quartz Armor
	enableQuartz = true
	#Enable or Disable Ghost Armor
	enableGhost = true
	#Enable or Disable Emerald Armor
	enableEmerald = true
	#Enable or Disable Jungle Wood Armor
	enableJungleWood = true
	#Enable or Disable Bone Armor
	enableBone = true
	#Enable or Disable Phantom Armor
	enablePhantom = true
	#Enable or Disable Snow Armor
	enableSnow = true
	#Enable or Disable Prismarine Shard Armor
	enablePrismarineShard = true


Here is where i'm expecting to load the config (the main class for the mod):


import com.bailym.extraarmor.config.ArmorConfig;
import com.bailym.extraarmor.util.RegistryHandler;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
public class ExtraArmor
    public static final String MOD_ID = "extraarmor";
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();

    public ExtraArmor() {

        // Register the setup method for modloading
        // Register the doClientStuff method for modloading

        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ArmorConfig.COMMON_SPEC);

        //Call the method to initialize the registry. (Multiple registries require multiple calls).
        // Register ourselves for server and other game events we are interested in


    private void setup(final FMLCommonSetupEvent event)

    private void doClientStuff(final FMLClientSetupEvent event) {

    //Creates a custom ItemGroup with the label extraArmorTab. In game Label can be set in lang files.
    public static final ItemGroup TAB = new ItemGroup("extraArmorTab") {
        //Overrides the vanilla createIcon method to chnge the icon used for this tab to a new item.
        public ItemStack createIcon() {
            return new ItemStack(Items.LEATHER_CHESTPLATE);




Any help is appreciated. Thanks.

Link to post
Share on other sites

Config files are not loaded that early on purpose. They are only available from FMLCommonSetupEvent and later. From your config names I guess you want to conditionally register your items - this is a big reason why config files are not available that early. Do not conditionally register things. Always register all your items, blocks, etc.

Link to post
Share on other sites

Thanks for the info! I'll look into the CommonSetup stage.


Yes I was intending to only register items with true values.What's the alternative? 

Is there some other way to make items unavailable in game other than just not registering them?


Thanks for the help!

Link to post
Share on other sites

I'm now registering the config in the onCommonSetup method which i have been reading about here (https://mcforge.readthedocs.io/en/latest/concepts/lifecycle/)


However i'm still getting true (the default value) even if the value in the config file is false


private void onCommonSetup(FMLCommonSetupEvent event)
        //Register the config
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ArmorConfig.COMMON_SPEC);
        System.out.println(ArmorConfig.COMMON.enableOakWood.get()); //Always True



Link to post
Share on other sites



i did notice that the forge docs are using:



whereas i am using:



is there a difference between the two? (FMLModloadingContext and FMLJavaModLoadingContext) as i cant seem to import the former.

Link to post
Share on other sites

I can't reproduce this. I cloned your repo and re-enabled the commented-out config registration. Setting a value to false in the common config file worked fine.


Your Git repository contains a lot of unnecessary stuff and is therefor slow to clone. The MDK comes with a gitignore file for a reason - please use it.

Link to post
Share on other sites

I initially removed the .gitignore because i wanted to preserve the world saves, ill add it back in with the necessary exceptions.


Just to clarify.

If you set enableOakWood to false in extraarmor-common.toml the line 


System.out.println(ArmorConfig.COMMON.enableOakWood.get()); //Always True


returns false as expected? As i'm not getting the same behavior

Link to post
Share on other sites
2 minutes ago, Bailym said:

I initially removed the .gitignore because i wanted to preserve the world saves, ill add it back in with the necessary exceptions.

Git is not the right way to store worlds or other large files.


4 minutes ago, Bailym said:

If you set enableOakWood to false in extraarmor-common.toml the line 


System.out.println(ArmorConfig.COMMON.enableOakWood.get()); //Always True


returns false as expected? As i'm not getting the same behavior

There is no such line in the repository you posted. I used the debugger and put a breakpoint in the FMLCommonSetupEvent handler. Then I used evaluate expression and ArmorConfig.COMMON.enableOakWood.get() was false, as expected.

Link to post
Share on other sites

Having followed those instructions I am getting the same results.


It seems my lack of understanding of forge in general is the issue :)


Thanks for the advice, its been really helpful.


Just one final thing. If i were to disable recipes and creative tab entries as you suggested, would i do so inside the FMLCommonSetupEvent handler or some place else?





Link to post
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.

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.

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • after the 2nd click it places blocks should that be on the server also?
    • We only send vanilla packets. Any of your random translator projects is on them to support these vanilla packets. There is nothing we need to do on our end, and there is nothing we can do to support hacky setups like this.
    • Whenever i try to run the installer it says This application requires a java runtime environment 1.6.0 im runing windows 10
    • So I thought that I had gotten pretty far on my own but now apparently my code crashes the game. I am new to using the forge API and modding in general and some help on why this crashes the game and how to fix it would be greatly appreciated:   public class SpecialItem extends ShootableItem {      public SpecialItem(Properties properties){ super(properties); }      @Override      public Predicate<ItemStack> getInventoryAmmoPredicate() { return null; }      @Override      public int func_230305_d_() { return 15; }      public int tcount=0;      @SubscribeEvent public void ontick(TickEvent.ClientTickEvent event){            tcount++;      }      @Override      public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {      if (!playerIn.getCooldownTracker().hasCooldown(this)) {           playerIn.getCooldownTracker().setCooldown(this, 40);           Vector3d v3 = playerIn.getLook(1);           for (tcount = 0; tcount <= 40;) {                if (tcount%10 == 0 && tcount!= 40) {                     final SmallFireballEntity entitysmallfireball = new SmallFireballEntity(playerIn.getEntityWorld(), playerIn.getPosX(), playerIn.getPosY() + playerIn.getEyeHeight() - 0.4, playerIn.getPosZ(), v3.x + playerIn.getRNG().nextGaussian() * 0.05, v3.y, v3.z);                     entitysmallfireball./* shoot */func_234612_a_(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0f, 1.5f, 1.0f); worldIn.addEntity(entitysmallfireball); } } tcount = 0;                     return ActionResult.resultSuccess(playerIn.getHeldItem(handIn));            } return ActionResult.resultFail(playerIn.getHeldItem(handIn));      } }
    • I found a way to handle this, using javapoet as you suggested. For those who are interested in how it works, you can take a look at my sample here: https://github.com/DarkShadow44/compatibilitymod/tree/sourcegen Might not work with eclipse yet, but it builds properly.
  • Topics

  • Who's Online (See full list)

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.