跳到正文

Dial

作者:awruff

一款轻量级 Minecraft 模组配置前置库。

收藏

截图

介绍

介绍由机器翻译自 Modrinth 原页面,仅供参考。

Dial

一个轻量级的 Minecraft 模组配置库。只需几行代码声明选项,Dial 就会为你保存配置并生成设置界面。

为什么选择 Dial?

  • 你无需编写序列化代码,也不用手动构建界面。
  • 同一份代码可在所有受支持的版本和加载器上运行,因此只需编写一次配置,升级适配时也能继续使用。
  • 支持从 Beta 1.7.3 到最新版本。
  • 可选的 Kotlin 模块提供构建器 DSL 和属性委托。
  • Dial 配置也可以显示在 OneConfig 中。

支持的版本

| Minecraft | Fabric | Forge | NeoForge | Ornithe |
|————|——–|——-|———-|———|
| 26.4 | ✓ | | | |
| 26.3 | ✓ | | | |
| 26.1.2 | ✓ | | ✓ | |
| 1.21.1 | ✓ | | ✓ | |
| 1.20.1 | ✓ | ✓ | | |
| 1.18.2 | ✓ | ✓ | | |
| 1.16.5 | ✓ | ✓ | | |
| 1.12.2 | | ✓ | | |
| 1.8.9 | | ✓ | | ✓ |
| 1.7.10 | | ✓ | | |
| Beta 1.7.3 | | | | ✓ |

玩家使用

将 Dial 与任何需要它的模组一同安装即可。

开发者使用

Java

public final class MyMod {
    public static final Config CONFIG = Dial.config("mymod", "My Mod");

    public static final BooleanOption ENABLED = CONFIG.toggle("enabled", true)
        .description("Turn the mod on or off.");
    public static final EnumOption<Corner> CORNER = CONFIG.cycle("corner", Corner.TOP_LEFT)
        .description("Which corner of the screen to draw in.");
    public static final SliderOption OPACITY = CONFIG.slider("opacity", 40, 0, 100, 5).suffix("%")
        .description("Background opacity.");
    public static final TextOption FORMAT = CONFIG.text("format", "{fps} FPS").maxLength(64)
        .description("The text to show.");
}

使用 ENABLED.get() 读取选项值,通过 set(...) 修改选项,并使用 Dial.open(CONFIG) 打开设置界面。使用 onChange(...) 响应玩家对选项的修改。

较大型的模组可以将选项分组到不同类别中。设置界面会为每个类别提供一个按钮,点击后打开其专属页面;类别还可以嵌套:

public static final Category ITEMS = CONFIG.category("items").description("How held items look.");
public static final BooleanOption BLOCK_HITTING = ITEMS.toggle("block_hitting", true);
public static final BooleanOption ALWAYS_SWING = ITEMS.category("swing").toggle("always_swing", false);

类别只会影响界面显示方式。所有选项仍保存在同一个配置文件中,因此整个配置中的选项 ID 必须唯一。

Kotlin

object MyMod {
    val config = dial("mymod", "My Mod")

    val enabled by config.toggle("enabled", true)
        .description("Turn the mod on or off.")
    val corner by config.cycle("corner", Corner.TOP_LEFT)
        .description("Which corner of the screen to draw in.")
    val opacity by config.slider("opacity", 40.0, 0.0..100.0, 5.0).suffix("%")
        .description("Background opacity.")
    val format by config.text("format", "{fps} FPS").maxLength(64)
        .description("The text to show.")
}

一个完整可用的 FPS HUD 示例,位于 example/。

许可协议

Dial 根据 Apache-2.0 许可协议授权。你可以在任何项目中使用、修改和分发它,包括商业项目,且无需支付版税。

常见问题

Dial 支持哪些 Minecraft 版本?

Dial 支持 Minecraft Java 版 1.7.10–26.3,共 14 个版本,可用的加载器:Fabric / Forge / NeoForge。下载时注意选择和你游戏版本一致的文件。

Dial 怎么安装?

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

评论

登录后评论和评分

awruff 的其他作品

查看全部 →