Configuration

Configuration

2M Downloads

[1.18.2-DEV] java.lang.IllegalArgumentException: Config class must be annotated with '@Config' annotation

CobaltTheProtogen opened this issue ยท 10 comments

commented

Hello, so I am trying to use Configuration to make configs for my mod and I've ran into a problem. This is my config class:

package us.blueeyemods.uem.config;

import dev.toma.configuration.config.Config;
import dev.toma.configuration.config.Configurable;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import us.blueeyemods.uem.Main;

@Config(id = "blueeyemods/" + Main.MODID + "/common")
public class ModConfig {
        @Configurable
        public static Enchantment.Rarity ENCHANTMENT_RARITY = Enchantment.Rarity.RARE;
        @Configurable
        public static EnchantmentCategory ENCHANTMENT_CATEGORY = EnchantmentCategory.BREAKABLE;
        @Configurable
        public static EquipmentSlot[] EQUIPMENT_SLOTS = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND};
        @Configurable
        public static int MAXIMUM_ENCHANTMENT_LEVEL = 1;
        @Configurable
        public static boolean TREASURE_ONLY = true;
        @Configurable
        public static boolean DISCOVERABLE = true;
        @Configurable
        public static boolean TRADEABLE = true;
        @Configurable
        public static boolean IS_ALLOWED_ON_BOOKS = true;
        @Configurable
        public static boolean IS_CURSE = false;

    }
This config throws the error mentioned in the title of this post. How do I fix it? Or is this a bug with the current version of the mod for 1.18.2? I'm using version 2.1.0 btw. Any help would be appreciated.
commented

Oh, I see it. You have imported wrong ModConfig class in your main class. You used file from ForgeModLoader instead of your config class

commented

Ah, thank you. One more question, how do I use the config where I need to use it? My mixins apparently require static fields which I can't use and uh...EquipmentSlots array doesn't show up in my config for some reason.

commented

You need to access your config via the static field in your Main class. For example

int value = Main.config.value;
commented

Hi, I'm going to need some extra information in order to figure this out. How are you registering the config? I have been able to create config on the 1.18.2 version without any issues.

I have also noticed issue with your config example - our config is instance based, meaning that you cannot use static variables, but all needs to be done on instance level, for example instead of using

@Configurable
public static int NUMBER = 1;

you would use

@Configurable
public int NUMBER = 1;

otherwise the values won't be actually registered. All you need to do is store the config variable somewhere during registration and then just access it as needed.

If you're looking for some examples:
Registration + instance obtaining
Config file for example

commented

Hi, thank you for responding so quickly. So, here's the thing, I have it registered like this under my Main Class:

    public Main() {
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        MinecraftForge.EVENT_BUS.register(this);
        config = Configuration.registerConfig(ModConfig.class, ConfigFormats.json()).getConfigInstance();
    }
commented

That seems to be correct. Do you have GitHub repository for this project? I would try to debug the issue directly.

commented
commented

The equipment slots don't show up in my config though.

commented

Enum arrays are not currently supported data type. I will consider adding it, however no promises. You can find list of supported data types HERE

commented

Enum arrays are supported data type in version 2.2.0 which has just been released (Forge only for now). You can use that