SuperMartijn642's Config Lib

SuperMartijn642's Config Lib

Config Lib 让处理配置文件变得稍微简单一些。

SuperMartijn642's Config Lib

SuperMartijn642's Config Lib 允许你 一次性定义配置,随后它会 自动处理世界加载之间的值重载、与客户端同步值,以及 为仅客户端或仅服务端生成值。

Seperator

创建配置:

配置通过 ModConfigBuilder 创建。

只需使用 #ModConfigBuilder() 创建一个新实例。

 ModConfigBuilder builder = new ModConfigBuilder();

可以使用 ModConfigBuilder#define 向配置中添加值,该方法接受一个名称和一个默认值。

对于整数和双精度浮点数值,还需要提供最小值和最大值。

Test code block;

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 );
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 );

值也可以放入分类中。

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。

Seperator

示例模组:

关于如何使用 Config Lib 的具体示例,请查看 the example mod。
Seperator

Discord

如需了解未来内容、即将推出的模组以及参与讨论,欢迎加入 SuperMartijn642 的 Discord 服务器!

Seperator