Cloth Config API (Fabric/Forge/NeoForge)

Cloth Config API (Fabric/Forge/NeoForge)

169M Downloads

[FORGE] [1.17.1] java.lang.reflect.InvocationTargetException when using Custom Object in Config

Charismara opened this issue ยท 0 comments

commented

Hello there,

I'm trying to add a Block field to my Config but i always crash with that report: https://mcpaste.io/8c0f39226e257735

I'm registering my Type Provider here:

public static void registerConfigGUI(FMLClientSetupEvent e) {
        GuiRegistry registry = AutoConfig.getGuiRegistry(OtherLivingBeingsConfig.class);
        registry.registerTypeProvider((translationKey, configField, blockObject, defaultBlockObject, guiRegistryAccess) -> {
            Block fieldValue = Utils.getUnsafely(configField, blockObject);

            TextFieldBuilder blockEntry = ENTRY_BUILDER.startTextField(new TranslatableComponent(translationKey), fieldValue.getRegistryName().toString())
                    .setDefaultValue(() -> {
                        Block block = Utils.getUnsafely(configField, defaultBlockObject);
                        return block.getRegistryName().toString();
                    })
                    .setSaveConsumer(s -> Utils.setUnsafely(configField, blockObject, GameRegistry.findRegistry(Block.class).getValue(new ResourceLocation(s))))
                    .setErrorSupplier(s -> {
                        OtherLivingBeings.getLogger().fatal("Config Error:\n {}", s);
                        return Optional.empty();
                    });
            if (configField.isAnnotationPresent(ConfigEntry.Gui.RequiresRestart.class)) {
                blockEntry.requireRestart();
            }
            return Collections.singletonList(blockEntry.build());
        }, Block.class);
    }

i got no idea how to make that thing to work.