Skip to content

Better Config System

Anoop Singh edited this page Nov 10, 2025 · 4 revisions

Better Config System

BetterLib provides an easy-to-use and dynamic configuration system for Minecraft mods built with NeoForge or Forge. 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 full customizable GUI screen lets players easily modify config values.
  • 🔄 Live updates Changes are saved instantly and can trigger callbacks if needed.

📦 Setup Example

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;
}

This defines your mod’s config fields. Each field will automatically appear in the config GUI with proper labels and categories.


2. Register the Config in Your Main Mod Class

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

    public Better_lib(IEventBus modEventBus, ModContainer modContainer) {
        NeoForge.EVENT_BUS.register(this);

        // Register your config
        CONFIG = BetterConfigManager.register(DemoConfig.class);
    }

     //config screen register
    @EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
    public static class ClientModEvents {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event) {
            event.enqueueWork(() -> {
                ConfigScreenHandler.register("better_lib", parent ->
                        BetterConfigScreenFactory.from(DemoConfig.class, CONFIG, parent)
                );
            });
        }
    }
}

✅ This automatically:

  • Loads Demo_config.json from the config folder.
  • Registers an editable GUI screen accessible via ModMenu or your own buttons.

3. Opening the Config Screen

You can open the config GUI manually anywhere in your mod:

Minecraft.getInstance().setScreen(
    BetterConfigScreenFactory.from(ExampleConfig.class, Better_lib.CONFIG, Minecraft.getInstance().screen)
);

⚡ File Structure

.minecraft/config/Demo_config.json

Demo generated JSON:

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

🧠 Tips

  • You can group config entries with the category value.
  • Nested classes are supported for better organization.
  • Supports booleans, numbers, strings, enums, and lists.

🧩 Future Features

  • Default value reset buttons
  • Tooltips per entry
  • Server/client sync
  • Config versioning and migration

Clone this wiki locally