Registed
实现
首先,通过 Gradle 实现 Registed:
使用 Groovy
build.gradle
repositories {
maven { url "https://api.modrinth.com/maven" }
}
dependencies {
modApi "maven.modrinth:registed:$project.registed_version"
}
gradle.properties
registed_version=?
将 ? 替换为 Registed 的最新 标签名称。
使用 Kotlin
build.gradle.kts
repositories {
maven("https://api.modrinth.com/maven")
}
dependencies {
modApi("maven.modrinth:registed:${property("registedVersion")}")
}
gradle.properties
registedVersion=?
将 ? 替换为 Registed 的最新 标签名称。
接下来,在 fabric.mod.json 中将 Registed 引用为依赖项:
fabric.mod.json
{
// 其他内容
"depends": {
"registed": "*"
},
// 其他内容
}
Registed 不应嵌套在你的项目中。你应将 Registed 始终视为一个独立的模组。
用法
要注册一个对象,请执行以下操作:
full.path.to.ClassName.java
@RegistryId("modid")
public class ClassName {
@ho.artisan.registed.annotation.registries.Item
public static final Item ITEM = ...;
}
你必须使用 @RegistryID^@RegistryID_classpath 注解你的注册类,以告知 Registed 使用哪个命名空间。
之后,记得在 fabric.mod.json 中引用此类:
fabric.mod.json
{
// 其他内容
"entrypoints": {
"registed": [
"full.path.to.ClassName"
]
},
// 其他内容
}
Registed 支持 Registries 类^Registries_classpath 中的所有 Registry<?> 类型。你应该将目标注册表类型名称从 UPPER_SNAKE_CASE(全大写蛇形命名法)转换为 CamelCase(驼峰命名法)以找到所需的注解,例如 Registries.LOOT_NBT_PROVIDER_TYPE 对应的注解是 @LootNBTProviderType。
所有可用于注册对象的注解均位于包 ho.artisan.registed.annotation.registries 下。
这些注解只能应用于字段,且你应始终确保你的注册对象是 static 和 final 字段。
默认情况下,注册的 object 将使用其字段名的 snake_case(蛇形命名法)作为其在游戏内的标识符路径,例如字段 MY_EXAMPLE_ITEM 的标识符路径将是 my_example_item。我们建议使用 UPPER_SNAKE_CASE 来命名你的字段,因为它们应该是 static 和 final 的,并且只有在蛇形命名法下,Registed 才会保留下划线。
若要自定义注册对象的游戏内标识符路径,你可以对目标字段应用 @RegistryID^@RegistryID_classpath 注解:
@RegistryID("my_item")
@ho.artisan.registed.annotation.registries.Item
public static final Item ITEM = ...;
@RegistryID[@^RegistryID_classpath] 提供的标识符路径将被直接消耗,不进行任何进一步的处理。
Registed
Implementation
First, implement Registed through gradle:
Using Groovy
build.gradle
repositories {
maven { url "https://api.modrinth.com/maven" }
}
dependencies {
modApi "maven.modrinth:registed:$project.registed_version"
}
gradle.properties
registed_version=?
Replace ? with the latest tag name of Registed.
Using Kotlin
build.gradle.kts
repositories {
maven("https://api.modrinth.com/maven")
}
dependencies {
modApi("maven.modrinth:registed:${property("registedVersion")}")
}
gradle.properties
registedVersion=?
Replace ? with the latest tag name of Registed.
Next, reference Registed into your fabric.mod.json as a dependency:
fabric.mod.json
{
// Other contents
"depends": {
"registed": "*"
},
// Other contents
}
Registed should not be nested in your project. You should always treat Registed as a standalone mod.
Usage
To register an object, do:
full.path.to.ClassName.java
@RegistryId("modid")
public class ClassName {
@ho.artisan.registed.annotation.registries.Item
public static final Item ITEM = ...;
}
You must annotate your registration class with @RegistryID^@RegistryID_classpath to tell Registed which namespace to use.
After that, remember to reference this class in your fabric.mod.json:
fabric.mod.json
{
// Other contents
"entrypoints": {
"registed": [
"full.path.to.ClassName"
]
},
// Other contents
}
Registed supports all Registry<?> types inside class Registries^Registries_classpath. You should convert the target registry type name from UPPER_SNAKE_CASE to CamelCase to find the desired annotation, for example, Registries.LOOT_NBT_PROVIDER_TYPE has a representing annotation @LootNBTProviderType.
All available annotations for registered objects are under package ho.artisan.registed.annotation.registries.
These annotations can only be applied on fields, and you should always make sure your registered objects are static and final fields.
By default, the registered objects will use their field names in snake_case as their in-game identifier paths, for example, field MY_EXAMPLE_ITEM will have the identifier path of my_example_item. We suggest using UPPER_SNAKE_CASE to name your fields, as they should be static and final and only in snake cases will Registed preserve the underscores.
To customize a registered object's in-game identifier path, you can apply annotation @RegistryID^@RegistryID_classpath to the target field:
@RegistryID("my_item")
@ho.artisan.registed.annotation.registries.Item
public static final Item ITEM = ...;
The identifier path provided by @RegistryID[@^RegistryID_classpath] will be consumed as raw without any further processing.
评论 0
登录后参与评分
还没有评论,来抢沙发吧