搜索历史
清空
暂无搜索历史
论坛热搜
1
Jenny — 有趣的模拟女友模组|珍妮模组
热
3
上古老物 冒险者传说 by WhiteSword
新
5
洛心斗罗-福利|公会据点战|武魂||抽奖|最终版
2
乌托邦探险之旅3.2
热
4
幻虚斗罗V1.5
6
水星迫降——在未知的世界中挣扎
登陆 注册 QQ登陆
快捷导航
查看: 25|回复: 0

[模组分享] 配置文件的Fabric Yaml Configuration(Fabric Yaml Configuration)-MOD模组

[复制链接]

5257

主题

53

回帖

6535

积分

龙❁妻

Rank: 8Rank: 8

经验
6535 EP
金粒
1185 粒
绿宝石
20 块
爱心
0 点
发表于 2025-8-10 17:41:05 | 显示全部楼层 |阅读模式
配置文件的Fabric Yaml Configuration(Fabric Yaml Configuration)Github |相关wiki |源站链接支持: fabric这个模组允许你使用yaml配置文件作为你的模组的配置。

Fabric Yaml Configuration模组允许您使用yaml配置文件作为模组的配置,同时已经包含了snakeyaml库。

FabricConfiguration方法

java

// 设置最终配置文件的路径

setFile(File file)

setFile(String file)

// 将原始配置文件的流设置为默认配置

// 通常原始配置文件位于模组资源中。

setDefault(InputStream defaultConfigurationFile)

// 初始化配置

intialize()

// 将配置保存到文件中

saveConfiguration()

// 从文件重新加载配置

// 在模组运行期间需要更新配置时需要使用。

relaodConfiguration()

简单配置示例

assets/example-mod/config/example-mod.yml

yaml

测试分支

test:

  integer: 1

  double: 1.1

  string: \'test\'

  list:

    - \'test-1\'

    - \'test-2\'

    - \'test-3\'

  section:

    test: \'test\'

java

public class ExampleMod implements ModInitializer {

    public static final Logger LOGGER = LogManager.getLogger();

    public FabricConfiguration configuration = new FabricConfiguration();

    @Override

    public void onInitialize() {

        // 从模组资源中获取默认配置文件

        InputStream defaultConfigurationFile = ExampleMod.class.getResourceAsStream(\"/assets/example-mod/config/example-mod.yml\");

        // 将默认配置文件设置为配置

        configuration.setDefault(defaultConfigurationFile);

        // 设置配置文件路径

        configuration.setFile(\"config/example-mod.yml\");

        // 初始化配置(如果文件存在则加载,否则生成配置)

        try {

            configuration.initialize();

        } catch (IOException e) {

            LOGGER.error(\"无法生成配置文件\", e);

        } catch (InvalidConfigurationException e) {

            LOGGER.error(\"无法加载配置文件\", e);

        }

    }

}

示例代码(保存和从配置中获取ItemStack)

java

ItemStack exampleItemStack = new ItemStack(Items.BEDROCK);

NbtCompound itemStackNbt = exampleItemStack.writeNbt(new NbtCompound());

configuration.set(\"item-stack\", NbtHelper.toNbtProviderString(itemStackNbt));

try {

    configuration.saveConfiguration();

} catch (IOException e) {

    LOGGER.error(\"无法保存配置\", e);

}

ItemStack itemStack = null;

try {

    itemStack = ItemStack.fromNbt(NbtHelper.fromNbtProviderString(configuration.getString(\"item-stack\")));

} catch (CommandSyntaxException e) {

    LOGGER.error(\"无法从配置中加载ItemStack\", e);

}

来自Modrinth所有游戏版本1.20.11.20.21.20.31.20.41.20.51.20.61.211.21.11.21.21.21.31.21.41.21.5所有类型fabricFabric Yaml Configuration 1.0.1fabric-yaml-configuration-1.0.1.jar下载1.0.1#ReleaseUpdate to 1.20.2 minecraft version展开版本: 1.0.1支持游戏: 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6, 1.21, 1.21.1, 1.21.2, 1.21.3, 1.21.4, 1.21.5类型:FabricRelease下载次数: 209fabric-yaml-configuration 1.0.0fabric-yaml-configuration-1.0.0.jar下载1.0.0#Release展开版本: 1.0.0支持游戏: 1.20.1类型:FabricRelease下载次数: 192全部版本

markdown_parsed

文章类型:收录

layui.use([\'form\'], function(){
var form = layui.form;
});

游客,如果您要查看本帖隐藏内容请回复
配置文件的Fabric Yaml Configuration(Fabric Yaml Configuration)-MOD模组
楼主 2025-8-10 17:41:05 回复 收起回复
小僵尸论坛感谢有你~
回复 论坛版权

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 手机动态码快速登录

本版积分规则



介绍

我的世界(Minecraft)小僵尸论坛
收录了来自各地的我的世界(MC)爱好者们的各种资源

须知: 切勿滥用举报,任何与举报相关的信息必须属实!

"Minecraft"以及"我的世界"为Mojang Synergies AB的商标 本站与Mojang以及微软公司没有从属关系

官方

新浪微博 腾讯微博 微信公众号 投稿规则 版权声明 捐助我们

官方QQ①群: 291907844 (点击加群)
官方QQ②群: 421312192
官方QQ③群: 528726532

我的世界(Minecraft)小僵尸论坛

新会员

QQ|Archiver|手机版|小黑屋|Minecraft(我的世界)小僵尸论坛 |网站地图

GMT+8, 2026-4-8 09:23 , Processed in 0.320645 second(s), 148 queries .

快速回复 返回顶部 返回列表