TLA Api
TLA api 是 Minecraft 配方查看器 API 的抽象层。 它允许模组开发者只需编写一次配方查看器的集成代码,即可兼容多种配方查看器。 目前支持的配方查看器有:EMI 和 REI。
用法
Gradle
TLA api 可通过 JitPack 获取。在 build.gradle 中添加以下内容以使用它:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
modImplementation "com.github.mattidragon:TlaApi:${tla_api_version}"
include "com.github.mattidragon:TlaApi:${tla_api_version}"
}
入口点 (Entrypoint)
要使用该 API,你需要实现 TlaApiPlugin 接口,并将你的实现添加到 tla-api 入口点中。
请注意,整个 API 仅适用于客户端。如果你使用了分离的源码集(split source sets),
则需要在客户端源码集中实现该 API。
public class MyTlaPlugin implements TlaApiPlugin {
@Override
public void register(PluginContext context) {
// 在此处注册你的 API
}
}
{
"entrypoints": {
"tla-api": [
"my.package.MyTlaPlugin"
]
}
}
注册内容
设置好入口点后,你就可以开始注册内容了。 整个 API 都通过 Javadoc 进行了文档说明,因此你可以使用 IDE 来探索该 API。 API 的设计主要基于 EMI,但我为了适配 REI 做了一些修改。
注意事项
虽然 TLA API 抽象了一切,但你仍需自行验证代码是否在两种配方查看器上都能正常工作。 例如,你仍然需要为 EMI 翻译所有的标签(tags)。某些小部件的渲染方式也可能略有不同。
在使用该 API 时,建议关注以下注解。 它们有助于解释如何正确使用该 API。
@ApiStatus.Internal: 表示这部分代码不打算供模组开发者使用。@ImplementationOnly: 表示这部分代码仅用于配方查看器的 API 实现部分。 除非你在创建自己的配方查看器集成,否则不应使用这些 API 部分。@PluginOnly: 表示这部分代码仅由插件使用,而非配方查看器的 API 实现。@ImplementationsExtend: 表示该接口由 API 的实现部分所实现,插件通常不应实现它。@PluginsExtend: 表示该接口由插件实现,而 API 的实现部分通常不应实现它。
常见问题
Q: 这是否允许仅支持单一查看器的模组在两者上都能工作?
A: 不可以。此 API 只是让模组开发者更容易同时支持这两种查看器。
Q: 为什么这个 API 仅适用于客户端?
A: EMI 的整个 API 都是仅适用于客户端的。REI 虽然有服务端 API,但不包含 TLA 所使用的任何功能。
Q: 有示例吗?
A: 有的,你可以在这里找到测试模组。 它做了一些通常不会做的操作,但总体上很好地展示了该 API 的用法。
TLA Api
TLA api is an abstraction layer over recipe viewer apis for minecraft. It allows mod developers to write their recipe viewer integration once and have it work with multiple recipe viewers. Currently supported recipe viewers are: EMI and REI
Usage
Gradle
TLA api is available on jitpack. Add the following to your build.gradle to use it:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
modImplementation "com.github.mattidragon:TlaApi:${tla_api_version}"
include "com.github.mattidragon:TlaApi:${tla_api_version}"
}
Entrypoint
To use the api you need to implement the TlaApiPlugin interface and add your implementation to the tla-api entrypoint.
Note that the entire api is client side only. If you are using split source sets,
you need to implement the api in the client source set.
public class MyTlaPlugin implements TlaApiPlugin {
@Override
public void register(PluginContext context) {
// Register your api here
}
}
{
"entrypoints": {
"tla-api": [
"my.package.MyTlaPlugin"
]
}
}
Registering Content
Once you've set up your entrypoint you can begin registering content. The entire api is documented using javadocs, so you can use your IDE to explore the api. The api design is mostly based on EMIs, but I've had to make some changes to accommodate REI.
Things to Consider
While the TLA api abstracts everything, you will still need to verify yourself that your code works with both recipe viewers. For example, you still need to translate all of your tags for EMI. Some widgets might also render slightly differently.
A useful thing to look for while using the api are the following annotations. They help with explaining how the api should be used.
@ApiStatus.Internal: This means that the part of code is not meant to be used by mod developers.@ImplementationOnly: This means that the part of code is only meant to be used by the implementation of the api for recipe viewers. Unless you are creating your own recipe viewer integration, you should not use these parts of the api.@PluginOnly: This means that the part of code is only meant to be by plugins and not by the implementation of the api for recipe viewers.@ImplementationsExtend: This indicates that the interface is implemented by the implementations of the api and plugins generally shouldn't implement it.@PluginsExtend: This indicates that the interface is implemented by plugins and the implementations of the api generally shouldn't implement it.
Questions
Q: Does this allow mods that only support one viewer to work on both?
A: No. This api just makes it easier for mod developers to support both viewers.
Q: Why is this api client side only?
A: EMIs entire api is client side only. REI has a server side api, but it doesn't contain any features that TLA uses.
Q: Are there any examples?
A: Yes, you can find the test mod here. It does a few things you wouldn't normally do, but generally does a good job of showing off the api.
下载 TLA Api
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 TLA Api
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 TLA Api
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 TLA Api
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 TLA Api
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 TLA Api
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
- 添加对自定义物品比较的支持
- 修复在开发环境外使用自定义小部件的配方无法正常工作的问题
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
适用于 MC 1.18+ 的 Effekseer 加载器
评论 0
登录后参与评分
还没有评论,来抢沙发吧