Jump to content

Recommended Posts

Posted

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.

Posted

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!

Posted

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

    }

 

Posted

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.

Posted

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

Posted

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

 

 

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

    • Hey! I noticed you're trying to register your alexandrite item and possibly set its resource location manually with setId(...). I wanted to help clarify a few things that might simplify your code and avoid errors. ✅ The issue: You're using setId(...) inside the item registration like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties().useItemDescriptionPrefix() .setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "alexandrite"))))); But: Item.Properties does not have a setId(...) method — this line will either fail or do nothing meaningful. useItemDescriptionPrefix() is mostly used for translation keys (like "item.modid.name") but isn't needed unless you have a very specific reason. 🛠 The fix: You only need to register your item like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties())); Forge automatically handles the ResourceLocation (modid:alexandrite) based on the name passed into .register(...), so there’s no need to manually assign it. 📝 For the texture: Make sure you have this file in your resources: src/main/resources/assets/tutorialmod/models/item/alexandrite.json { "parent": "item/generated", "textures": { "layer0": "tutorialmod:item/alexandrite" } } And your texture PNG goes here: src/main/resources/assets/tutorialmod/textures/item/alexandrite.png 🌍 For the name in-game: Add this to your en_us.json under: src/main/resources/assets/tutorialmod/lang/en_us.json { "item.tutorialmod.alexandrite": "Alexandrite" }   Note: if im wrong about the issue you are encountering, i apologize.
    • 🛠️ Fix for Transparent or Clipping Item Render Issues When Held in First Person (Forge 1.20+) Hey everyone! I recently ran into a frustrating bug while making a custom item (a rocket) for my Forge mod, and I’m sharing the fix because it’s a bit obscure — and it worked wonders. 💥 The Problem: My item rendered semi-transparent and see-through — but only in first person. It also clipped through nearby blocks when held, unlike default items like swords or leads. The texture file was confirmed to be fully opaque (alpha 255), so the issue wasn’t the PNG itself. Interestingly, when no texture was present and the default purple-black checkerboard appeared, the clipping issue disappeared. ✅ The Fix: I ended up resolving it by randomly trying something I found on a Forge forum post about block rendering. I added this property to my item's model JSON — even though it's typically only used for blocks: { "parent": "item/generated", "textures": { "layer0": "farbeyond:item/rocket_item" }, "render_type": "minecraft:cutout" } Boom. That single line forced the item to render using a proper opaque (cutout) layer, removing all the unwanted transparency and clipping behavior in first person. 🙌 Credit: I originally found the "render_type" trick mentioned here, in a block rendering context: 👉 https://forums.minecraftforge.net/topic/149644-1201-help-with-transparent-blocks/ Even though it was meant for blocks, I thought, why not try it on an item? And it worked! Big thanks to the poster — this fix wouldn’t have happened without that tip. Hopefully this helps anyone else stuck on a weird rendering bug like I was. This isn’t a common item solution, so feel free to share it further. I’d love to know if it works for you too.
    • Use Java 21 instead of Java 24   Also make a test without modernfix
    • Ive been on this world for 2 days now, my computer blue screens pretty often so maybe that has something to do with it. maybe just incompatible mods like a lot of people so im hoping someone more knowledgeable can help me find what i need to get rid of. thank you! paste bin
    • Should probably say that i am running minecraft 1.21.1 and with quite a lot of mods (many of which im unsure should even be on the server side)
  • Topics

×
×
  • Create New...

Important Information

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