Tesla
Tesla 是一个专为跨模组通信设计的电力 API。它允许来自不同模组的物品、方块和实体通过 Tesla 电力网络相互交互。
警告:Alpha 和 Beta 版本仅供模组作者和测试人员使用。支持 Tesla 的模组应仅针对正式发行版(Full Releases)!使用 Alpha 构建可能会导致依赖它的模组崩溃!
本项目由 Nodecraft 赞助。使用代码 DARKHAX 可在您的第一个月服务中获得 30% 的折扣!
入门指南
使用 Tesla API 的最佳方式是通过 Forge 的能力系统 (Capability system)。其理念非常简单:能力是处理特定类型 Tesla 相关逻辑的接口实现。这些能力可以附加到受支持的对象上(Tile Entity、ItemStack 和 Entity)。当能力被附加后,该对象将能够访问所提供的 Tesla 逻辑,并且对其他启用 Tesla 的对象可见。你可以在此处查看基本的能力实现这里,以及一个 Tile Entity 示例 这里。还有一个物品示例 这里。
常见问题解答
人们可以去哪里讨论 Tesla API?
有一个公开的 Discord 服务器,可以在 这里找到。
Tesla 与其他电力 API 有何不同?
Tesla API 的功能与其他电力 API 非常相似,但在设计上有几处选择使其更加灵活。其中一项选择是使用 Forge 的能力系统,这使得几乎任何对象都可以添加 Tesla 支持。利用该系统,模组甚至可以在不使用任何粗糙 hacks 的情况下为原版熔炉添加 Tesla 支持。另一项决定是使用 long 类型而非 int 类型。这一改变使得模组可以轻松处理更大的数值。
为什么你要制作这个 API?
这个 API 最初是作为一个有趣的副项目制作的,但收到了其他开发者大量的意外关注。它并非为了消灭其他电力 API 而创建的,也不是为了某种 crusade(圣战)之类的目的。
Tesla 有标准规范吗?
API 本身不强制执行任何标准,但鼓励模组作者遵循以下几点建议:1 Tesla 应等于 1 RF;Tile Entity 不应直接实现能力接口;侧向逻辑(sided logic)应通过能力方法来处理。
Tesla API 应该捆绑到其他模组中吗?
虽然捆绑 API 是一种常见做法,且得到 Forge 的支持,但这是一种非常糟糕的实践。虽然没有什么能阻止其他模组捆绑该 API,但我们强烈不建议这样做,也不会提供官方支持。
如果不能捆绑 API,软依赖(Soft Dependency)是如何工作的?
Forge 提供了多种工具,使得软依赖变得非常简单。首先是 Optional 注解。此注解可以添加到实现接口的任何类上,如果未检测到特定的模组 ID,则该接口可以从类中剥离。这允许现有的容器对象在没有硬依赖的情况下实现 Tesla 的接口。CapabilityInject 注解 对于软依赖也非常有用。你可以将此注解应用于字段,以便在该能力初始化时将其初始化为特定的能力。你也可以将此注解应用于方法,以便在该能力初始化时调用这些方法。你可能会注意到,该注解引用了 Tesla 中的能力类,而在软依赖情况下该类将不存在。由于注解和 JVM 的工作方式,在注解中创建此引用是安全的,不会导致 Class Definition Exception(类定义异常)。
整合包政策
是的,你可以在整合包中使用它。请不要发送消息询问是否可以在你的整合包中使用此内容,我将不会回复此类消息。
Tesla
Tesla is a power API designed for cross mod communication. It allows for Items, Blocks and Entities from various mods to interact with each other over the Tesla power network.
WARNING: Alpha and beta releases are intended for mod authors and testers. Mods that support Tesla should only target full releases! Using an alpha build may crash mods that require it!
This project is sponsored by Nodecraft. Use code DARKHAX for 30% off your first month of service!
Getting Started
The best way to use the Tesla API is through Forge's Capability system. The idea is very simple, capabilities are implementations of an interface that handle a certain type of Tesla related logic. These capabilities can then be attached to supported things (Tile Entity, ItemStack and Entity). When a capability is attached, that thing will have access to the provided tesla logic, and it will be visible to other tesla enabled things. You can see a basic capability implementation here and a tile entity example here. There is also an item example here.
Frequently Asked Questions
Where can people go to discuss the Tesla API?
There is a public discord server which can be found here.
What makes Tesla different from other power API?
The Tesla API functions very similarly to other power API, however there are several design choices made the API much more flexible. One of these choices was the decision to use Forge's capability system, which allows for Tesla support to be added to nearly anything. It would be possible for a mod to add Tesla support to a vanilla furnace with this system, without using any dirty hacks. Another decision was using longs over integers. This change allows for mods to easily work with larger power numbers.
Why did you make this API?
The API was originally made as a fun side project, but received a lot of unexpected attention from other developers. It was not created as a crusade to kill other power API or anything like that.
Are there any standards for Tesla?
The API does not enforce any standard, however there are a few things which mod authors are encouraged to follow. One Tesla should equal 1 RF, tile entities should not directly implement capability interfaces, and sided logic should be handled through the capability methods.
Should the Tesa API be bundled with other mods?
While bundling API is frequently done, and supported by Forge, it is a very bad practice. While there is nothing stopping other mods from bundling the API it is highly discouraged and will not be officially supported.
How does soft dependency work if I can't bundle the API?
Forge provides several tools which make soft dependency really simple. The first is the Optional annotation. This annotation can be added to any class that implements an interface, and if a certain mod ID is not detected, the interface can be stripped from the class. This allows for existing container objects to implement Tesla's interfaces without a hard dependency. The CapabilityInject annotation is also extremely useful for soft dependency. You can use this annotation on a field to have it initialized with a specific capability when said capability is initialized. You can also put this annotation on methods to have then called when the capability is initialized. One thing you might notice is that the annotation takes a reference to the capability class from Tesla, which will be missing under soft dependency. Due to the way annotations and the JVM work, it is safe to make this reference in the annotation. It will not give you a Class Definition exception.
Modpack Policy
Yes, you can use this in a mod pack. Please don't send me messages asking for permission to use this in your mod pack. I will not be responding to such messages.
下载 TESLA
下载 TESLA
下载 TESLA
下载 TESLA
下载 TESLA
下载 TESLA
下载 TESLA
下载 TESLA
下载 TESLA
下载 TESLA
- 添加了波兰语翻译,感谢 Kaperios。 - Tyler Hancock
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
适用于 MC 1.18+ 的 Effekseer 加载器
模组
添加区块认领和玩家组队功能,并与 Xaero's Minimap 和 World Map 集成
评论 0
登录后参与评分
还没有评论,来抢沙发吧