跳到正文

a0fefd’s ConfigLib

作者:a0fefd

A configuration library for mods. Adds an interface to add config options and a gui to interface with them.

收藏

截图

介绍

中文介绍正在准备中,下面暂时显示原文。

ConfigLib

A lightweight config library for Fabric mods. Describe your options as plain Java objects and get a working in-game config screen, a / command to open it, and JSON persistence, all without hand-rolling a GUI.

Features

  • In-game config screen: tabbed by category, with sub-category headings to group related options within a tab.
  • Seven option types: BOOL, NUM (int and float unified), STR, ENUM (any Java enum), LIST, TUPLE, and BUTTON.
  • LIST and TUPLE render as an expanding set of entry boxes rather than a single string field, and can be restricted to a specific element type. Min/max clamping applies per-entry (e.g. clamping each component of an RGB value to 0-255), not just to a single NUM.
  • BUTTON runs a callback instead of holding a value, for actions that don’t belong in the saved config.
  • Auto-registered command: / opens the screen, no extra setup needed. ConfigCommand.registerWithAlternatives can register additional command aliases that open the same screen.
  • JSON persistence: options round-trip to /.json. A corrupted or outdated file falls back to defaults instead of crashing the game. BUTTON options are skipped since they hold no value.

How to install

Add these to each section of file build.gradle

repositories {
	mavenCentral()
	maven { url = "https://raw.githubusercontent.com/a0fefd/ConfigLib/mvn-repo/" }
}
dependencies {
	implementation "com.a0fefd:configlib:<version>"
}

Replace <version> with your target version.

Usage

Config config = new Config("mymod", null);

config.builder.add(new ConfigOption<>(
        "example_toggle",
        "General",
        true,
        Boolean.class,
        ConfigOptionType.BOOL
));

config.load();
ConfigCommand.register(config);

That is enough to get a working /mymod command opening a config screen with one toggle in it. Add more ConfigOptions for more settings, and use the category and subCategory fields to organize a larger config into tabs and sections.

Requirements

  • Minecraft 26.1.2
  • Fabric Loader 0.19.3 or newer
  • Fabric API
  • Java 25 or newer

常见问题

a0fefd’s ConfigLib 支持哪些 Minecraft 版本?

a0fefd’s ConfigLib 支持 Minecraft Java 版 26.1.2,可用的加载器:Fabric。下载时注意选择和你游戏版本一致的文件。

a0fefd’s ConfigLib 怎么安装?

先用 PCL2 或 HMCL 启动器安装对应版本的 Fabric,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。运行环境:客户端 / 服务端。

评论

登录后评论和评分

a0fefd 的其他作品

查看全部 →