Configory
为 Minecraft 模组提供基于约定的配置方案。
Configory 是一个轻量级的 Java 配置库,它在调用处让模组配置变得简单,同时在代码需要类型安全的地方保留这一特性。只需定义一次值——包括其类型、默认值和约束条件——即可在所有地方安全地使用它。
public static final ConfigKey<Float> SPEED_MULTIPLIER =
config.defineFloat("core.speed_multiplier", 1.0f)
.range(0.1f, 10.0f)
.describe("全局速度乘数。")
.register();
float speed = getConfig(SPEED_MULTIPLIER);
setConfig(SPEED_MULTIPLIER, 3.0f).save();
需要用于调试工具或脚本的动态访问?可以通过字符串路径获取相同的配置:
float speed = getConfig("core.speed_multiplier").asFloat();
setConfig("core.speed_multiplier", 3.0f).save();
功能特性
- 类型安全的配置键 — 在编译时确保读写值的类型安全。
- 点号表示法路径 — 将值嵌套在配置的 JSON 文件中,或者保持模组配置为单个扁平文件。
- 流畅的验证机制 — 声明范围与约束条件;拒绝无效的写入操作。
- 生成的命令接口 — 通过模组自身的游戏内命令暴露配置,无需任何 Brigadier 样板代码。
- 基于 JSON 的文件存储 — 人类可读的配置格式,支持显式保存,让你掌控写入时机。
- 按模组隔离 — 每个模组映射到独立的配置文件,清晰分离。
- 轻量级启动约定 — 极简设置即可快速上手。
注意事项
Configory 是一个与加载器无关的库类模组(仅依赖 Gson,目标为 Java 21)。像普通依赖一样对其进行编译,但不要将其打包进你的模组中——应将其作为必需依赖分发,并让玩家单独安装 Configory jar 文件,以便多个模组共享同一份副本。单个 jar 文件可在 Fabric、Forge 和 NeoForge 上加载,并且兼容非常广泛的 Minecraft 版本。
链接
图标:book_scroll_written,作者 Malcolm Riley,CC BY 4.0,已放大处理。
Configory
Convention-based configuration for Minecraft mods.
Configory is a small Java configuration library that makes mod config feel simple at the call site without giving up type safety where your code needs it. Define a value once — with its type, default, and constraints — and use it safely everywhere.
public static final ConfigKey<Float> SPEED_MULTIPLIER =
config.defineFloat("core.speed_multiplier", 1.0f)
.range(0.1f, 10.0f)
.describe("Global speed multiplier.")
.register();
float speed = getConfig(SPEED_MULTIPLIER);
setConfig(SPEED_MULTIPLIER, 3.0f).save();
Need dynamic access for debug tooling or scripts? Reach for the same config by string path:
float speed = getConfig("core.speed_multiplier").asFloat();
setConfig("core.speed_multiplier", 3.0f).save();
Features
- Typed config keys — read and write values with compile-time type safety.
- Dot-notation paths — nest values inside a config's JSON file, or keep a simple mod to a single flat file.
- Fluent validation — declare ranges and constraints once; invalid writes are rejected.
- Generated command surface — expose your config through your mod's own in-game command, with zero Brigadier boilerplate.
- JSON-backed files — human-readable config, with explicit saving so you control when it's written.
- Per-mod isolation — each mod maps to its own config file, cleanly separated.
- Lightweight bootstrap conventions — minimal setup to get going.
Notes
Configory is a loader-agnostic library mod (it depends only on Gson and targets Java 21). Compile against it as a normal dependency, but don't bundle it — ship it as a required dependency and let players install the Configory jar separately, so several mods can share one copy. A single jar loads on Fabric, Forge and NeoForge and it works across a very wide range of Minecraft versions.
Links
- Documentation:
- Source & issues:
Icon: book_scroll_written by Malcolm Riley, CC BY 4.0, upscaled.
评论 0
登录后参与评分
还没有评论,来抢沙发吧