Jump to content

Cant Get a Config File Working 1.16.5


Bailym

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")
                    .push("Armor");

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

            builder.pop();
        }
    }

    public static final ForgeConfigSpec COMMON_SPEC;
    public static final Common COMMON;
            static{
                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
[Armor]
	#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
@Mod("extraarmor")
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
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

      //HERE IS WHERE I AM REGISTERING THE CONFIG AND CHECKING ONE OF THE VALUES
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ArmorConfig.COMMON_SPEC);
      //DOESNT GIVE THE VALUE IN THE CONFIG FILE. ONLY THE DEFAULT VALUE IN THE CONFIG CLASS
        System.out.println(ArmorConfig.COMMON.enableOakWood.get());	

        //Call the method to initialize the registry. (Multiple registries require multiple calls).
        RegistryHandler.init();
        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);


    }

    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.
        @Override
        public ItemStack createIcon() {
            return new ItemStack(Items.LEATHER_CHESTPLATE);
        }
    };

}

 

 

Any help is appreciated. Thanks.

Link to comment
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 comment
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 comment
Share on other sites

Hmmm... 

 

i did notice that the forge docs are using:

FMLModLoadingContext.get().getModEventBus().addListener(this::commonSetup);

 

whereas i am using:

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetup);

 

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

Link to comment
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 comment
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?

 

Thanks

 

 

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

    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Slot Aster88 adalah bocoran slot rekomendasi gacor dari Aster88 yang bisa anda temukan di SLOT Aster88. Situs SLOT Aster88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Aster88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Aster88 merupakan SLOT Aster88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Aster88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Aster88 hari ini yang telah disediakan SLOT Aster88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Aster88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Aster88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Aster88 di link SLOT Aster88.
  • Topics

×
×
  • Create New...

Important Information

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