SuperMartijn642's Config Lib

SuperMartijn642's Config Lib

热度 1117854353
最近更新11 个月前
配置库使处理配置文件变得稍微容易一些。 Config Lib makes dealing with config...

SuperMartijn642的配置库 允许你 仅指定一次配置,然后它会自行 在世界加载之间处理值的重新加载与客户端同步值 以及 为仅客户端或仅服务器生成值

创建配置:

使用ModConfigBuilder创建配置。

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

ModConfigBuilder builder = new ModConfigBuilder();

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

对于整数和双精度值,还需要指定最小值和最大值。

测试代码块;

ModConfigBuilder#define返回一个Supplier,应存储该Supplier以便从配置中检索值。

Supplier booleanValue = builder.define( "booleanValue", true );

Supplier integerValue = builder.define( "integerValue", 5, 0, 10 );

Supplier doubleValue = builder.define( "doubleValue", 0.5, 0, 1);

Supplier enumValue = builder.define( "enumValue", ExampleEnum.VALUE_1 );

可以在定义值之前调用ModConfigBuilder#comment(String)为值添加注释。

Supplier valueWithComment = builder.comment( "this is a comment for 'valueWithComment'" ).define( "valueWithComment ", true );

默认情况下,世界加载时会重新加载值。

可以在定义值之前调用ModConfigBuilder#gameRestart()将其更改为仅在Minecraft启动时重新加载值。

Supplier notReloadedValue = builder.comment( "this is value will not be reloaded" ).define( "notReloadedValue", true );

COMMON或SERVER配置中的值默认与客户端同步,要阻止这种情况,请使用ModConfigBuilder#dontSync()。

Supplier notSynchronizedValue = builder.comment( "this is value will not be synchronized" ).define( "notSynchronizedValue", true );

值也可以放入类别中。

ModConfigBuilder#push(String) 推送一个类别,ModConfigBuilder#pop() 弹出一个类别。

builder.push( "special" );

Supplier 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

示例模组:

有关如何使用配置库的具体示例,请查看 示例模组

Discord

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

Patreon

如果你喜欢我的模组,考虑通过捐赠或成为赞助人来支持我。

法律声明

SuperMartijn642的配置库归SuperMartijn642所有,受版权法保护,未经SuperMartijn642直接许可,不得修改或重新上传。

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.

Test code block;

ModConfigBuilder#define returns a Supplier which should be stored to retrieve the value from the config.

   Supplier booleanValue = builder.define( "booleanValue", true );

   Supplier integerValue = builder.define( "integerValue", 5, 0, 10 );

   Supplier doubleValue = builder.define( "doubleValue", 0.5, 0, 1);

   Supplier 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 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 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 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 specialValuebuilder.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, and 1.16

Example Mod:

For a concrete example of how to use Config Lib checkout the example mod.

Discord

For future content, upcoming mods, and discussion, feel free to join the SuperMartijn642 discord server!

Patreon

If you enjoy my mods, consider supporting me with a donation or by becoming a patron.

Legal Stuff

SuperMartijn642's Config Lib is the property of SuperMartijn642 and is protected under copyright law and may not be altered or reuploaded without direct permission from SuperMartijn642.

本站是资源分享站,资源均来自于互联网和用户自发分享,仅供学习和交流使用。如有版权问题,请联系管理员删除。

评论区 (0)

登录 后才能发表评论

暂无评论

快来发表第一条评论吧!