Skip to content

Better Config System

Anoop Singh edited this page Dec 16, 2025 · 4 revisions

Better Config System

BetterLib provides an easy-to-use and dynamic configuration system for Minecraft mods built with Forge, NeoForge, and Fabric.
It allows developers to define config fields using annotations, automatically generate GUI screens, and handle file saving/loading β€” all with minimal boilerplate code.


πŸ“˜ Features

  • 🧱 Annotation-based config definition
    Use @Config and @ConfigEntry to mark config classes and fields.

  • βš™οΈ Automatic file saving/loading
    Config data is automatically serialized to and from JSON.

  • πŸͺŸ In-game GUI editor
    A fully customizable GUI screen lets players easily modify config values.

  • πŸ”„ Live updates
    Changes are saved instantly and can trigger callbacks if needed.

  • πŸ” Multi-loader support
    Works on Forge, NeoForge, and Fabric with the same config classes.


πŸ“¦ Setup Example (Common)

1. Create a Config Class

package com.reggarf.mods.better_lib.example;

import com.reggarf.mods.better_lib.config.annotation.Config; import com.reggarf.mods.better_lib.config.annotation.ConfigEntry;

@Config(fileName = "Demo_config") public class DemoConfig {

@ConfigEntry(category = "general", name = "Enable Feature")
public boolean enableFeature = true;

@ConfigEntry(category = "visual", name = "Render Distance")
public int renderDistance = 12;

@ConfigEntry(category = "performance", name = "Max FPS")
public int maxFps = 120;

}

Each field will automatically appear in the config GUI with proper labels and categories.


βš™οΈ Forge / NeoForge Setup

Register the Config

@Mod(Demo.MODID)
public class Demo {
public static final String MODID = "demo";
public static DemoConfig CONFIG;

public Demo(IEventBus modEventBus, ModContainer modContainer) {
    CONFIG = BetterConfigManager.register(DemoConfig.class);
}

@Mod.EventBusSubscriber(
    modid = MODID,
    bus = Mod.EventBusSubscriber.Bus.MOD,
    value = Dist.CLIENT
)
public static class ClientModEvents {

    @SubscribeEvent
    public static void onClientSetup(FMLClientSetupEvent event) {
        event.enqueueWork(() -> {
            ConfigScreenHandler.register(
                MODID,
                parent -> BetterConfigScreenFactory.from(
                    DemoConfig.class,
                    CONFIG,
                    parent
                )
            );
        });
    }
}

}

What this does

  • Loads Demo_config.json

  • Saves changes automatically

  • Registers a GUI config screen

  • Adds a Config button in the Mods menu


🧡 Fabric Setup (Fabric + Mod Menu)

On Fabric, config screens are integrated via Mod Menu.
No ClientModInitializer or manual registration is required.


πŸ“¦ Requirements

modImplementation "com.terraformersmc:modmenu:${modmenu_version}"

1. Register the Config (Common Init)

public class DemoFabric implements ModInitializer {
public static DemoConfig CONFIG;

@Override
public void onInitialize() {
    CONFIG = BetterConfigManager.register(DemoConfig.class);
}

}


2. Mod Menu Integration (Fabric-only)

package com.reggarf.mods.demo.fabric;

import com.reggarf.mods.demo.DemoFabric; import com.reggarf.mods.better_lib.config.DemoConfig; import com.reggarf.mods.better_lib.config.gui.BetterConfigScreenFactory; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT) public class DemoMenuIntegration implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
    return parent ->
            BetterConfigScreenFactory.from(
                    DemoConfig.class,
                    DemoFabric.CONFIG,
                    parent
            );
}

}


3. fabric.mod.json

{
"entrypoints": {
"main": [
"com.reggarf.mods.demo.DemoFabric"
],
"modmenu": [
"com.reggarf.mods.demo.fabric.DemoMenuIntegration"
]
},
"depends": {
"modmenu": "*"
}
}

βœ… The Config button appears automatically in Mod Menu
βœ… Runs client-only
βœ… Safe on dedicated servers


πŸͺŸ Opening the Config Screen Manually

You can open the config GUI anywhere in your code:

Minecraft.getInstance().setScreen(
BetterConfigScreenFactory.from(
DemoConfig.class,
DemoFabric.CONFIG,
Minecraft.getInstance().screen
)
);

πŸ“ Config File Location

.minecraft/config/Demo_config.json

Example generated file:

{
"enableFeature": true,
"renderDistance": 12,
"maxFps": 120
}

🧠 Tips

  • Use category to group options

  • Nested config classes are supported

  • Supports booleans, numbers, strings, enums, and lists

  • Same config classes work across all loaders


πŸ” Loader Comparison

Feature Forge / NeoForge Fabric
Config registration Event-based Common init
Config GUI Extension point Mod Menu
Client setup Required ❌ Not required
Server safe βœ… βœ…

🧩 Planned Features

  • Reset-to-default buttons

  • Tooltips per entry

  • Server/client config sync

  • Config versioning & migration


πŸ“Œ Notes

If Mod Menu is not installed on Fabric, the config GUI will simply not appear β€” configs will still load and save correctly.