动态注册表
Dynamic Registries 是一个库模组,允许创建基于数据包的自定义注册表。你可以在代码中定义元素并通过数据包(包括你模组内的数据包)进行配置,但这并非必需;你也可以选择在代码中或仅在数据包中创建元素。在代码中定义的元素同样可以通过数据包进行覆盖。所有元素必须以 JSON 格式编码。
本库基于 此 PR 引入的更改构建。该 PR 可能在 1.18.2 发布前不会被合并,但我已为 1.18.1 需要此功能,因此编写了此模组。出于此原因,本库将不会提供其他 Minecraft 版本的版本。
如何将此库添加到你的模组依赖项中
要将库添加到你的 Gradle 设置中,请将 Modrinth 添加为你的依赖仓库。
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
将上述代码块添加到你的 build.gradle 文件中依赖项块(dependencies block)之上(顺序影响不大,但为了简化说明,我们假设你将其放置在此处)。如果你已经有一个 repositories 块,只需将 maven 块追加到其中即可。
现在定义依赖项本身。将以下行添加到你的 build.gradle 文件中的依赖项块中。撰写本文时最新版本为 0.1.0。请将其替换为当前可用的最新版本。
implementation fg.deobf("maven.modrinth:dynamicregistries:0.1.0")
现在你可以刷新 Gradle 项目以下载依赖项并重新运行 IDE 设置任务(genIntellijRuns、genEclipseRuns 或 genVSCodeRuns)。
你现在可以在开发环境中使用动态注册表,但你应该让 Forge 加载器在加载时检查其依赖项。这需要在你的 mods.toml 文件(位于 src/main/resources/META-INF)中进行更改。在文件末尾添加以下块:
[[dependencies.modid]]
modId = "dynamicregistries"
mandatory = true
versionRange = "[0.0.0,2.0.0)"
ordering = "NONE"
side = "BOTH"
将 modid 替换为你模组的 ID,并根据需要调整版本范围。
鸣谢
dynamic registries
Dynamic registries is a library mod that allows the creation of new data-pack based registries. It's possible to define elements in code and trough data-packs (even the data-pack in your mod), but not necessary; you can also create elements only in code or in data-packs. Elements that were defined in code can also be overwritten from data-packs. Elements must be encoded in JSON.
This library is based on the changes introduced in this PR. This PR probably isn't going to be merged before 1.18.2 gets released, but I needed this feature already for 1.18.1, so I wrote this mod. There won't be versions of this library for other Minecraft version for this reason.
How to add this library to your mods dependencies
To add the library to your gradle setup, add modrinth to your dependency repositories.
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
Add the above codeblock to your build.gradle above your dependencies block (the order doesn't matter that strong, but lets assume that you've placed it there to simplify things a bit). If you already had a repositories block, only append the maven block to it.
We now define the dependency itself. Add the line below to your dependencies block in your build.gradle. Version 0.1.0 was the latest at time of writing. Replace that with the latest currently available version.
implementation fg.deobf("maven.modrinth:dynamicregistries:0.1.0")
You can now refresh your gradle project to download the dependencies and re-run IDE setup tasks (genIntellijRuns, genEclipseRuns or genVSCodeRuns)
You can now use dynamic registries in your development setup, but you should make the forge mod-loader check for it's dependencies when loading. That requires changes in your mods.toml (in src/main/resources/META-INF). Add the following block at the end of the file
[[dependencies.modid]]
modId = "dynamicregistries"
mandatory = true
versionRange = "[0.0.0,2.0.0)"
ordering = "NONE"
side = "BOTH"
Replace modid with the modid of your mod and rearrange the version range if necessary
Credits
- Won-Ton, the author of the PR that was the base for this library
- Mod Icon: flaticon.com
评论 0
登录后参与评分
还没有评论,来抢沙发吧