zh_cn:tutorial:callbacks
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| zh_cn:tutorial:callbacks [2021/09/17 04:35] – [回调] solidblock | zh_cn:tutorial:callbacks [2023/05/04 11:01] (current) – [实例] solidblock | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| 每个事件都有对应的回调接口,通常命名为 '' | 每个事件都有对应的回调接口,通常命名为 '' | ||
| ==== 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, | ||
| } | } | ||
zh_cn/tutorial/callbacks.1631853354.txt.gz · Last modified: 2021/09/17 04:35 by solidblock