SuperMartijn642's Config Lib 允许你仅指定一次配置,随后它将自动处理世界加载之间的数值重载、与客户端同步数值,并自行生成仅适用于客户端或服务端的数值。
创建配置:
配置使用 ModConfigBuilder 创建。
只需使用 #ModConfigBuilder() 创建一个新实例即可。
ModConfigBuilder builder = new ModConfigBuilder();
可以使用 ModConfigBuilder#define 向配置中添加值,该方法需要传入名称和默认值。
对于整数(Integer)和双精度浮点数(Double)类型的值,还需要提供最小值和最大值。
ModConfigBuilder#define 返回一个 Supplier,应将其存储以便从配置中获取该值。
Supplier<Boolean> booleanValue = builder.define( "booleanValue", true );
Supplier<Integer> integerValue = builder.define( "integerValue", 5, 0, 10 );
Supplier<Double> doubleValue = builder.define( "doubleValue", 0.5, 0, 1);
Supplier<ExampleEnum> enumValue = builder.define( "enumValue", ExampleEnum.VALUE_1 );
可以在定义值之前调用 ModConfigBuilder#comment(String) 来为值添加注释。
Supplier<Boolean> valueWithComment = builder.comment( "this is a comment for 'valueWithComment'" ).define( "valueWithComment ", true );
默认情况下,值会在世界加载时重新加载。
可以通过在定义值之前调用 ModConfigBuilder#gameRestart() 将其更改为仅在 Minecraft 启动时重新加载。
Supplier<Boolean> notReloadedValue = builder.comment( "this is value will not be reloaded" ).define( "notReloadedValue", true );
COMMON 或 SERVER 配置中的值默认会与客户端同步,如需阻止此行为,请使用 ModConfigBuilder#dontSync()。
Supplier<Boolean> notSynchronizedValue = builder.comment( "this is value will not be synchronized" ).define( "notSynchronizedValue", true );
还可以将值放入分类中。
ModConfigBuilder#push(String) 用于压入一个分类,ModConfigBuilder#pop() 用于弹出分类。
builder.push( "special" );
Supplier<Boolean> specialValue = builder.comment( "this value is in the 'special' category" ).define( "specialValue", true );
builder.pop();
可以使用 ModConfigBuilder#categoryComment(String) 为当前活动的分类添加注释。
builder.push( "client" ).categoryComment( "this, is a comment for the 'client' category" );
定义所有值后,必须调用 ModConfigBuilder#build() 来完成配置。
builder.build();
现在,配置中的值将自动重新加载和同步,并且可以使用存储的 Supplier 实例来获取这些值。
这适用于所有可用版本,包括 Minecraft 1.12、1.14、1.15、1.16、1.17、1.18 和 1.19。
示例模组:
有关如何使用 Config Lib 的具体示例,请查看 示例模组。
常见问题解答
我可以在我的整合包中使用你的模组吗?
是的,欢迎在你的整合包中使用我的模组。
Discord
如需了解后续内容、即将推出的模组以及参与讨论,欢迎加入 SuperMartijn642 的 Discord 服务器!
SuperMartijn642's Config Lib allows you to specify a config once and it then handles reloading values between world loads, syncing values with clients, and generating values for client- or server-only on its own.
Creating a config:
A config is created using a ModConfigBuilder.
Simply create a new instance using #ModConfigBuilder().
ModConfigBuilder builder = new ModConfigBuilder();
A value can be added to the config with ModConfigBuilder#define which takes a name and a default value.
For integer and double values a minimum and maximum value are also required.
ModConfigBuilder#define returns a Supplier which should be stored to retrieve the value from the config.
Supplier<Boolean> booleanValue = builder.define( "booleanValue", true );
Supplier<Integer> integerValue = builder.define( "integerValue", 5, 0, 10 );
Supplier<Double> doubleValue = builder.define( "doubleValue", 0.5, 0, 1);
Supplier<ExampleEnum> enumValue = builder.define( "enumValue", ExampleEnum.VALUE_1 );
A comment can be added to a value by calling ModConfigBuilder#comment(String) before defining the value.
Supplier<Boolean> valueWithComment = builder.comment( "this is a comment for 'valueWithComment'" ).define( "valueWithComment ", true );
By default values are reloaded when world is loaded.
This can be changed to only reload a value when Minecraft launches by calling ModConfigBuilder#gameRestart() before defining the value.
Supplier<Boolean> notReloadedValue = builder.comment( "this is value will not be reloaded" ).define( "notReloadedValue", true );
Values in COMMON or SERVER configs are synchronized with clients by default, to prevent this use ModConfigBuilder#dontSync().
Supplier<Boolean> notSynchronizedValue = builder.comment( "this is value will not be synchronized" ).define( "notSynchronizedValue", true );
Values can also be put into categories.
ModConfigBuilder#push(String) pushes a category and ModConfigBuilder#pop() pops a category.
builder.push( "special" );
Supplier<Boolean> specialValue = builder.comment( "this value is in the 'special' category" ).define( "specialValue", true );
builder.pop();
A comment can be added to the active category using ModConfigBuilder#categoryComment(String).
builder.push( "client" ).categoryComment( "this, is a comment for the 'client' category" );
After defining all values ModConfigBuilder#build() must be called to finish the config.
builder.build();
Now the values in your config will reloaded and synced automatically and the values can be retrieved using the stored Supplier instances.
This will work for all available versions, that includes Minecraft 1.12, 1.14, 1.15, 1.16, 1.17, 1.18, and 1.19.
Example Mod:
For a concrete example of how to use Config Lib checkout the example mod.
FAQ
Can I use your mod in my modpack?
Yes, feel free to use my mod in your modpack
Discord
For future content, upcoming mods, and discussion, feel free to join the SuperMartijn642 discord server!
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 SuperMartijn642's Config Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
SuperMartijn642 的配置库 1.1.8a
- 修复了“读取包元数据时出错”的警告
更新到 Minecraft 26.3
更新到 Minecraft 26.2
更新到 Minecraft 26.1
SuperMartijn642 的配置库 1.1.8
- SuperMartijn642 的配置库针对 Minecraft 1.21 的首次发布
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
适用于 MC 1.18+ 的 Effekseer 加载器
模组
那是什么?一个 Waila/Hwyla 的分支。
评论 0
登录后参与评分
还没有评论,来抢沙发吧