English
❔ 了解更多详情
Unnamed Common Library (UCL) 是我尝试打造的一款简洁、实用(且尚未完全展现)的强大配置库。其目标是成为通用型工具,无论您开发的是何种模组或拥有何种偏好,都可以始终使用它。该库显然并非设计为独立使用的;若您单独使用它,它至多只能作为展示其能力的示例和测试。
? 为什么您应该喜欢它
- 极其容易实现和使用
- 可选的配置界面集成
- 支持 JSON、TOML 和 YAML
?? 面向开发者
安装
将仓库添加到您的 build.gradle(.kts) 中:
repositories {
maven {
url = "https://maven.pkg.github.com/aurorarissime/unnamed-common-library"
}
}
并在您的 buildscript 中添加依赖(Fabric 使用 modImplementation,NeoForge 使用 implementation):
dependencies {
(mod)Implementation("from.discorde:ucl:${ucl_version}+${minecraft_version}-fabric")
}
用法
1. 创建您的配置模型
MyModConfig.java
import from.discorde.ucl.common.config.annotations.*;
@Configuration(
name = "mymod"
)
public class MyModConfig {
@Comment("启用这个超棒的功能")
public boolean awesomeFeature = true;
@Comment("最大功率等级 (0-100)")
public int maxPower = 50;
@Comment("向玩家显示的欢迎消息")
public String welcomeMessage = "Hello!";
}
2. 在您的模组初始化器中加载配置
MyMod.java
public class MyMod implements ModInitializer {
// 包装类会在编译时自动生成
public static final MyModConfigWrapper CONFIG = MyModConfigWrapper.createAndLoad();
@Override
public void onInitialize() {
if (CONFIG.awesomeFeature) {
System.out.println("超棒功能已启用!");
}
}
}
参考文档
注解
@Configuration
将此注解添加在您配置类的正上方
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
name |
String |
必填 | 配置文件或文件夹名称 |
location |
ConfigurationLocation |
SUBDIRECTORY |
保存配置的位置 |
format |
ConfigurationFormat |
JSON5 |
要使用的文件格式 |
screen |
boolean |
true |
生成 YACL 配置界面 |
@Comment
将此注解添加在任意字段上方,以在配置文件中包含注释
@Comment("此注释将出现在配置文件中该字段的上方")
public boolean myOption = true;
枚举
ConfigurationLocation
| 值 | 描述 |
|---|---|
ROOT |
直接保存在配置文件夹中,文件名为 {name}.{ext} |
SUBDIRECTORY |
保存在子文件夹中,文件名为 {name}/configuration.{ext} |
ConfigurationFormat
| 值 | 扩展名 | 描述 |
|---|---|---|
JSON5 |
.json5 |
支持注释、尾随逗数和未加引号键的 JSON |
TOML |
.toml |
Tom's Obvious Minimal Language |
YAML |
.yaml |
YAML Ain't Markup Language |
配置界面集成
如果您的 @Configuration 注解中设置了 screen = true(默认值),并且安装了 YetAnotherConfigLib (YACL),则会自动生成一个配置界面,并通过 Mod Menu 访问。
若要禁用配置界面,只需在 @Configuration 注解中将 screen 参数设置为 false 即可。
祝您使用愉快 ?
English
❔ Tell me more about it
Unnamed Common Library (UCL) is my attempt at making a simple, useful, (yet to be) powerful configuration library. Its goal is to be general purpose so that no matter the mod you build or your preferences, you can always use it. This library is obviously not meant to be used on its own,if you do so it will at most serve as an example and a test for its capabilities.
? Why you should like it
- Very easy to implement and use
- Optional configuration screen integrations
- JSON, TOML, and YAML support
?? For developers
Installation
Add the repository to your build.gradle(.kts):
repositories {
maven {
url = "https://maven.pkg.github.com/aurorarissime/unnamed-common-library"
}
}
And in your buildscript, add the dependency (modImplementation for Fabric, implementation for NeoForge):
dependencies {
(mod)Implementation("from.discorde:ucl:${ucl_version}+${minecraft_version}-fabric")
}
Usage
1. Create your configuration model
MyModConfig.java
import from.discorde.ucl.common.config.annotations.*;
@Configuration(
name = "mymod"
)
public class MyModConfig {
@Comment("Enable the awesome feature")
public boolean awesomeFeature = true;
@Comment("Maximum power level (0-100)")
public int maxPower = 50;
@Comment("Welcome message displayed to players")
public String welcomeMessage = "Hello!";
}
2. Load the configuration in your mod initialiser
MyMod.java
public class MyMod implements ModInitializer {
// The wrapper class is auto-generated at compile time
public static final MyModConfigWrapper CONFIG = MyModConfigWrapper.createAndLoad();
@Override
public void onInitialize() {
if (CONFIG.awesomeFeature) {
System.out.println("Awesome feature is enabled!");
}
}
}
References
Annotations
@Configuration
Add this annotation right above your config class
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
String |
required | Config file or folder name |
location |
ConfigurationLocation |
SUBDIRECTORY |
Where to save the config |
format |
ConfigurationFormat |
JSON5 |
File format to use |
screen |
boolean |
true |
Generate YACL config screen |
@Comment
Add this annotation above any field to include a comment in the config file
@Comment("This comment will appear above the field in the config file")
public boolean myOption = true;
Enums
ConfigurationLocation
| Value | Description |
|---|---|
ROOT |
Save directly in the config folder as {name}.{ext} |
SUBDIRECTORY |
Save in a subfolder as {name}/configuration.{ext} |
ConfigurationFormat
| Value | Extension | Description |
|---|---|---|
JSON5 |
.json5 |
JSON with comments, trailing commas, and unquoted keys |
TOML |
.toml |
Tom's Obvious Minimal Language |
YAML |
.yaml |
YAML Ain't Markup Language |
Configuration screens integration
If screen = true (default) in your @Configuration annotation and YetAnotherConfigLib (YACL) is installed, a configuration screen will be auto-generated and accessible through Mod Menu.
To disable the config screen, just set the screen parameter to false in the @Configuration annotation.
Enjoy ?
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unnamed Common Library (UCL)
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
更改了内部库,添加了 YAML 支持并更新了 Neoforge 版本。
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
适用于 MC 1.18+ 的 Effekseer 加载器
评论 0
登录后参与评分
还没有评论,来抢沙发吧