|
|
BetterConfig (BetterConfig)Github |相关wiki |源站链接支持: fabric一个功能强大且易于使用的基于命令的配置库,适用于服务器和客户端。
创建简单的配置
要开始,请创建一个新类。这将是存储所有配置的类。在本示例中,我们将这个类称为 `Configs`。确保此类是 `public` 的!接下来,为您的配置条目创建一个字段。将此字段标记为注释 `@Config`。字段的初始值将用作默认(回退)值。
public class Configs {@Configpublic static String exampleString = \"default\";}
最后,在您的模组的 `onInitialize(Client)` 方法中,注册 `Configs` 类。将 `` 替换为您的模组的id。
new ModConfigBuilder(<mod id>, Configs.class).build();
就是这样!现在您可以通过 `Configs.exampleString` 访问 `exampleString`。您可以通过执行以下命令编辑 `exampleString`。
/(c)config <mod id> exampleString set <string>
这还不是全部!
此模组还支持将 `Collection` 和 `Map` 用作变量类型。这些配置将具有可用的选项 `add`、`put` 和 `remove`。此外,您还可以定义自己的(反)序列化器以创建具有任意类型的配置。要做到这一点,您所要做的就是在构建配置时注册(反)序列化器。例如,要创建一个类型为 `Block` 的变量,您可以执行
new ModConfigBuilder(<mod id>, Configs.class).registerTypeHierarchyWithArgument(Block.class, new BlockAdapter(), new Pair<>(BlockArgumentType::block, BlockArgumentType::getBlock)).build();
其中 `BlockAdapter` 扩展了 `TypeAdapter`,而 `BlockArgumentType` 实现了 `ArgumentType`。查看[这些测试](链接)以获取完整的图片。
此外,您还可以通过创建自己的方法完全更改更新配置值的行为。只需将 `setter`、`adder`、`putter` 或 `remover` 中的一个或多个添加为 `@Config` 注释的属性即可。这样做的一个很好的用途是根据单个值向 `Map` 添加键-值条目。考虑以下配置。
@Config(putter = @Config.Putter(\"none\"), adder = @Config.Adder(\"customMapAdder\"))public static Map<String, String> exampleMapAdder = new HashMap<>(Map.of(\"a\", \"A\", \"b\", \"B\"));public static void customMapAdder(String string) {exampleMapAdder.put(string.toLowerCase(Locale.ROOT), string.toUpperCase(Locale.ROOT));}
对于 putter,值为 `\"none\"` 意味着没有可用的 putter。这样,您可以像往常一样在代码中使用此 `Map`,并使用 `/(c)config exampleMapAdder add` 添加值到其中。有关更多详细信息,请参阅[`@Config`](链接) 的 JavaDocs。
更新方法的参数也可以自定义。
@Config(adder = @Config.Adder(value = \"customTypeAdder\", type = int.class))public static Collection<String> exampleCustomType = new ArrayList<>(List.of(\"%\", \"@\"));public static void customTypeAdder(int codepoint) {exampleCustomType.add(Character.toString(codepoint));}
安装
将 `${version}` 替换为构件版本。
您可以选择使用我的专属 maven 仓库还是 GitHub 的 package 仓库。
我的专属仓库
repositories {maven {url \'https://maven.xpple.dev/maven2\'}}
GitHub packages
repositories {maven {url \'https://maven.pkg.github.com/xpple/BetterConfig\'credentials {username = project.findProperty(\"gpr.user\") ?: System.getenv(\"USERNAME\")password = project.findProperty(\"gpr.key\") ?: System.getenv(\"TOKEN\")}}}
导入:
dependencies {include modImplementation(\'dev.xpple:betterconfig:${version}\')}
来自Modrinth所有游戏版本1.211.20.11.201.19.41.19.3所有类型paperfabricRelease Paper 2.3.0betterconfig-paper-2.3.0.jar下载2.3.0#Release- Greatly improved documentation of `Config` class展开版本: 2.3.0支持游戏: 1.21类型: paperRelease下载次数: 125Release Fabric 2.3.0betterconfig-fabric-2.3.0.jar下载2.3.0#Release- Greatly improved documentation of `Config` class展开版本: 2.3.0支持游戏: 1.21类型:FabricRelease下载次数: 389Release Paper 2.3.1betterconfig-paper-2.3.1.jar下载2.3.1#Release_No relevant changes._展开版本: 2.3.1支持游戏: 1.21类型: paperRelease下载次数: 20Release Fabric 2.3.1betterconfig-fabric-2.3.1.jar下载2.3.1#Release- Replaced `modRuntimeOnly` with `modLocalRuntime` in Fabric Gradle build script展开版本: 2.3.1支持游戏: 1.21类型:FabricRelease下载次数: 39Release Paper 2.2.0betterconfig-paper-2.2.0.jar下载2.2.0#Release- Update JavaDoc to clarify that resetting a config does not use the setter- Allow for custom chat representations of config values ([#16](https://github.com/xpple/BetterConfig/pull/16))展开版本: 2.2.0支持游戏: 1.21类型: paperRelease下载次数: 24Release Fabric 2.2.0betterconfig-fabric-2.2.0.jar下载2.2.0#Release- Update JavaDoc to clarify that resetting a config does not use the setter- Allow for custom chat representations of config values ([#16](https://github.com/xpple/BetterConfig/pull/16))展开版本: 2.2.0支持游戏: 1.21类型:FabricRelease下载次数: 32Release Paper 2.1.3betterconfig-paper-2.1.3.jar下载2.1.3#Release_No relevant changes._展开版本: 2.1.3支持游戏: 1.21类型: paperRelease下载次数: 28Release Fabric 2.1.3betterconfig-fabric-2.1.3.jar下载2.1.3#Release- Fixed a mixin bug causing a crash with some mods展开版本: 2.1.3支持游戏: 1.21类型:FabricRelease下载次数: 42Release Paper 2.1.2betterconfig-paper-2.1.2.jar下载2.1.2#Release- Added the sources JAR to the publication展开版本: 2.1.2支持游戏: 1.21类型: paperRelease下载次数: 63Release Fabric 2.1.2betterconfig-fabric-2.1.2.jar下载2.1.2#Release- Added the sources JAR to the publication展开版本: 2.1.2支持游戏: 1.21类型:FabricRelease下载次数: 182Release Paper 2.1.1betterconfig-paper-2.1.1.jar下载2.1.1#Release- Fixed a bug with `ModConfig#resetTemporaryConfigs` that could cause a bug when a config is both `temporary` and `readOnly`展开版本: 2.1.1支持游戏: 1.21类型: paperRelease下载次数: 40Release Fabric 2.1.1betterconfig-fabric-2.1.1.jar下载2.1.1#Release- Fixed a bug with `ModConfig#resetTemporaryConfigs` that could cause a bug when a config is both `temporary` and `readOnly`展开版本: 2.1.1支持游戏: 1.21类型:FabricRelease下载次数: 37Release Paper 2.1.0betterconfig-paper-2.1.0.jar下载2.1.0#ReleaseThis release introduces two new features and some bug fixes!- Added the `onChange` config attribute ([#10](https://github.com/xpple/BetterConfig/pull/10)). You can now register a function that is called whenever a specific config is updated. For example:```java@Config(onChange = \"onChange\")public static List<String> exampleOnChange = new ArrayList<>(List.of(\"xpple, earthcomputer\"));private static void onChange(List<String> oldValue, List<String> newValue) {LOGGER.info(\"exampleOnChange was updated | old: {}, new: {}\", oldValue, newValue);}```- Added global change hook ([#11](https://github.com/xpple/BetterConfig/pull/11)). This allows you to register a global function that is called whenever _any_ config is updated. For example:```javanew ModConfigBuilder<>(\"<mod id>\", Configs.class).registerGlobalChangeHook(event -> BetterConfigCommon.LOGGER.info(\"{} was updated | old: {}, new: {}\", event.config(), event.oldValue(), event.newValue())).build();```- Added Tatar translations ([#8](https://github.com/xpple/BetterConfig/pull/8) by Amirhan-Taipovjan-Greatest-I)展开版本: 2.1.0支持游戏: 1.21类型: paperRelease下载次数: 61Release Fabric 2.1.0betterconfig-fabric-2.1.0.jar下载2.1.0#ReleaseThis release introduces two new features and some bug fixes!- Added the `onChange` config attribute ([#10](https://github.com/xpple/BetterConfig/pull/10)). You can now register a function that is called whenever a specific config is updated. For example:```java@Config(onChange = \"onChange\")public static List<String> exampleOnChange = new ArrayList<>(List.of(\"xpple, earthcomputer\"));private static void onChange(List<String> oldValue, List<String> newValue) {LOGGER.info(\"exampleOnChange was updated | old: {}, new: {}\", oldValue, newValue);}```- Added global change hook ([#11](https://github.com/xpple/BetterConfig/pull/11)). This allows you to register a global function that is called whenever _any_ config is updated. For example:```javanew ModConfigBuilder<>(\"<mod id>\", Configs.class).registerGlobalChangeHook(event -> BetterConfigCommon.LOGGER.info(\"{} was updated | old: {}, new: {}\", event.config(), event.oldValue(), event.newValue())).build();```- Added Tatar translations ([#8](https://github.com/xpple/BetterConfig/pull/8) by Amirhan-Taipovjan-Greatest-I)展开版本: 2.1.0支持游戏: 1.21类型:FabricRelease下载次数: 122Release Paper 2.0betterconfig-paper-2.0.jar下载2.0#Release- Added support for Paper serversDepending on your setup, you might have to adjust how the config is initialised:- Fabric clients:```javanew ModConfigBuilder<FabricClientCommandSource, CommandBuildContext>(<mod id>, Configs.class)// ....build();```- Fabric servers:```javanew ModConfigBuilder<CommandSourceStack, CommandBuildContext>(<mod id>, Configs.class)// ....build();```- Paper servers:```javanew ModConfigBuilder<>(<plugin name>, Configs.class)// ....build();```- Added support for server-sided custom argument types- Fabric:```javadev.xpple.betterconfig.util.WrappedArgumentType```- Paper:```javaio.papermc.paper.command.brigadier.argument.CustomArgumentType```- Fixed bug where the `reset` subcommand would be available for readonly configs展开版本: 2.0支持游戏: 1.21类型: paperRelease下载次数: 60Release Fabric 2.0betterconfig-fabric-2.0.jar下载2.0#Release- Added support for Paper serversDepending on your setup, you might have to adjust how the config is initialised:- Fabric clients:```javanew ModConfigBuilder<FabricClientCommandSource, CommandBuildContext>(<mod id>, Configs.class)// ....build();```- Fabric servers:```javanew ModConfigBuilder<CommandSourceStack, CommandBuildContext>(<mod id>, Configs.class)// ....build();```- Paper servers:```javanew ModConfigBuilder<>(<plugin name>, Configs.class)// ....build();```- Added support for server-sided custom argument types- Fabric:```javadev.xpple.betterconfig.util.WrappedArgumentType```- Paper:```javaio.papermc.paper.command.brigadier.argument.CustomArgumentType```- Fixed bug where the `reset` subcommand would be available for readonly configs展开版本: 2.0支持游戏: 1.21类型:FabricRelease下载次数: 124Release Paper 1.3-multi-platformbetterconfig-paper-1.3-multi-platform.jar下载1.3-multi-platform#Release- Added support for Paper servers (details will follow in the stable release)展开版本: 1.3-multi-platform支持游戏: 1.21类型: paperRelease下载次数: 61Release Fabric 1.3-multi-platformbetterconfig-fabric-1.3-multi-platform.jar下载1.3-multi-platform#Release- Added support for Paper servers (details will follow in the stable release)展开版本: 1.3-multi-platform支持游戏: 1.21类型:FabricRelease下载次数: 55Release 1.3betterconfig-1.3.jar下载1.3#Release- Updated to Minecraft 1.21- Fixed resetting some configs by using deep copied value展开版本: 1.3支持游戏: 1.21类型:FabricRelease下载次数: 527Release 1.2.1betterconfig-1.2.1.jar下载1.2.1#Release- Added boolean argument type back to default arguments展开版本: 1.2.1支持游戏: 1.20.1类型:FabricRelease下载次数: 1,172Release 1.2.0betterconfig-1.2.0.jar下载1.2.0#Release- Made non-api packages no longer visible- Rewrote argument registrationConsider the below example to see how things have changed.```diff- .registerTypeWithArgument(Block.class, new BlockAdapter(), new Pair<>(BlockArgumentType::block, BlockArgumentType::getBlock))+ .registerType(Block.class, new BlockAdapter(), BlockArgumentType::block)```展开版本: 1.2.0支持游戏: 1.20.1类型:FabricRelease下载次数: 85Release 1.1.7betterconfig-1.1.7.jar下载1.1.7#Release- Fixed enum parsing when enum overrides `toString`- Prioritised custom arguments/suggestors over enum check- Fixed crashing on startup when the config is corrupted展开版本: 1.1.7支持游戏: 1.20.1类型:FabricRelease下载次数: 93Release 1.1.6betterconfig-1.1.6.jar下载1.1.6#Release- Added comments- Prevented getting a config being broadcasted on servers- Fixed keys being improperly printed when putting to a map展开版本: 1.1.6支持游戏: 1.20.1类型:FabricRelease下载次数: 66Release 1.1.5betterconfig-1.1.5.jar下载1.1.5#Release- Changed string type to greedy phrase for suggestor based argument types- Fixed config directory not being created on initialisation展开版本: 1.1.5支持游戏: 1.20.1类型:FabricRelease下载次数: 236Release 1.1.4betterconfig-1.1.4.jar下载1.1.4#Release- Disallowed final fields reasons- Allowed custom updaters to be private- Provided (English) fallback translations for servers展开版本: 1.1.4支持游戏: 1.20.1类型:FabricRelease下载次数: 72Release 1.1.3betterconfig-1.1.3.jar下载1.1.3#Release- Fixed config not saving after resetting展开版本: 1.1.3支持游戏: 1.20.1类型:FabricRelease下载次数: 83Release 1.1.2betterconfig-1.1.2.jar下载1.1.2#Release- Made sure config is always saved after first read展开版本: 1.1.2支持游戏: 1.20.1类型:FabricRelease下载次数: 100Release 1.1.1betterconfig-1.1.1.jar下载1.1.1#Release- Added conditions展开版本: 1.1.1支持游戏: 1.20类型:FabricRelease下载次数: 298Release 1.1betterconfig-1.1.jar下载1.1#Release- Updated to Minecraft 1.20展开版本: 1.1支持游戏: 1.20类型:FabricRelease下载次数: 63Release 1.0.7betterconfig-1.0.7.jar下载1.0.7#Release- Added `reset` and `resetTemporaryConfigs` methods to the API展开版本: 1.0.7支持游戏: 1.19.4类型:FabricRelease下载次数: 471Release 1.0.6betterconfig-1.0.6.jar下载1.0.6#Release- Allowed `private` fields in the configs class- Allowed fields to be `final` for initialisation- Added reset subcommand展开版本: 1.0.6支持游戏: 1.19.4类型:FabricRelease下载次数: 62Release 1.0.5betterconfig-1.0.5.jar下载1.0.5#Release- Updated to Minecraft 1.19.4- Fix permissions for clients展开版本: 1.0.5支持游戏: 1.19.4类型:FabricRelease下载次数: 97Release 1.0.4betterconfig-1.0.4.jar下载1.0.4#Release- Added feature to disable modifications to a config through commands (`readOnly = true`)- Added feature to prevent loading and saving a config to a file (`temporary = true`)展开版本: 1.0.4支持游戏: 1.19.3类型:FabricRelease下载次数: 146Release 1.0.3betterconfig-1.0.3.jar下载1.0.3#Release- Added support for enums展开版本: 1.0.3支持游戏: 1.19.3类型:FabricRelease下载次数: 64Release 1.0.2betterconfig-1.0.2.jar下载1.0.2#Release- Implemented custom type parameters for update methods展开版本: 1.0.2支持游戏: 1.19.3类型:FabricRelease下载次数: 78Release 1.0.1betterconfig-1.0.1.jar下载1.0.1#Release- Fix unstable warning due to class being marked with `@ApiStatus.Internal`.展开版本: 1.0.1支持游戏: 1.19.3类型:FabricRelease下载次数: 78Release 1.0.0betterconfig-1.0.0.jar下载1.0.0#ReleaseInitial release.展开版本: 1.0.0支持游戏: 1.19.3类型:FabricRelease下载次数: 70全部版本
markdown_parsed
文章类型:收录
layui.use([\'form\'], function(){
var form = layui.form;
});
BetterConfig |
楼主
2025-8-10 16:51:39
回复(0)
收起回复
|