zh_cn:tutorial:callbacks
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| zh_cn:tutorial:callbacks [2021/09/07 03:31] – created solidblock | zh_cn:tutorial:callbacks [2023/05/04 11:01] (current) – [实例] solidblock | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ===== 事件 ===== | ===== 事件 ===== | ||
| - | Events are represented by instances of '' | + | 事件是用存储并调用回调的 |
| ===== 回调 ===== | ===== 回调 ===== | ||
| - | Each event has a corresponding callback interface, conventionally named '' | + | 每个事件都有对应的回调接口,通常命名为 |
| ==== Fabric API 中的回调接口 ==== | ==== Fabric API 中的回调接口 ==== | ||
| - | All event callback interfaces provided by Fabric API can be found in the '' | + | Fabric API 提供的所有事件回调接口可以在 |
| - | A partial list of existing callbacks is provided at the bottom of this tutorial. | + | |
| ==== 自定义回调 ==== | ==== 自定义回调 ==== | ||
| - | Although there are plenty of events already provided by Fabric API, you can still make your own events. Please refer to [[tutorial: | + | 虽然 |
| ===== 实例 ====== | ===== 实例 ====== | ||
| - | This example registers an '' | + | 此例注册一个 |
| < | < | ||
| - | public class ExampleMod implements ModInitializer | + | public class ExampleMod implements ModInitializer { |
| - | { | + | |
| [...] | [...] | ||
| | | ||
| @Override | @Override | ||
| - | public void onInitialize() | + | public void onInitialize() { |
| - | | + | AttackBlockCallback.EVENT.register((player, |
| - | AttackBlockCallback.EVENT.register((player, | + | |
| - | | + | |
| class_2680 state = world.method_8320(pos); | class_2680 state = world.method_8320(pos); | ||
| - | /* Manual spectator check is necessary because | + | /* 手动的旁观者检查是必要的,因为 |
| - | fire before the spectator check */ | + | |
| if (state.method_29291() && !player.method_7325() && | if (state.method_29291() && !player.method_7325() && | ||
| - | player.method_6047().method_7960()) | + | player.method_6047().method_7960()) { |
| - | | + | |
| player.method_5643(class_1282.field_5869, | player.method_5643(class_1282.field_5869, | ||
| } | } | ||
| Line 46: | Line 37: | ||
| ===== Fabric API 事件 ====== | ===== Fabric API 事件 ====== | ||
| === 玩家交互事件 === | === 玩家交互事件 === | ||
| - | Player: | + | 玩家:[[https:// |
| 玩家(客户端):[[https:// | 玩家(客户端):[[https:// | ||
zh_cn/tutorial/callbacks.1630985472.txt.gz · Last modified: 2021/09/07 03:31 by solidblock