User Tools

Site Tools


zh_cn:tutorial:callbacks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
zh_cn:tutorial:callbacks [2021/09/17 04:35] – [回调] solidblockzh_cn:tutorial:callbacks [2021/10/23 02:04] – external edit 127.0.0.1
Line 9: Line 9:
 每个事件都有对应的回调接口,通常命名为 ''EventNameCallback''。回调是通过在事件接口调用 ''register()'' 来注册的,调用时需要一个回调接口实例作为参数。 每个事件都有对应的回调接口,通常命名为 ''EventNameCallback''。回调是通过在事件接口调用 ''register()'' 来注册的,调用时需要一个回调接口实例作为参数。
 ==== Fabric API 中的回调接口 ==== ==== Fabric API 中的回调接口 ====
-All event callback interfaces provided by Fabric API can be found in the ''net.fabricmc.fabric.api.event'' package. +Fabric API 提供的所有事件回调接口可以在 ''net.fabricmc.fabric.api.event'' 包中找到。本教程底部提供了部分存在的回调的列表。
-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:events]].+虽然 Fabric API 已经提供了许多事件,你还是可以制作你自己的事件,请参考[[zh_cn:tutorial:events]]
  
 ===== 实例 ====== ===== 实例 ======
-This example registers an ''AttackBlockCallback'' to damage players when they hit blocks that don't drop when hand-mined. It returns ''<yarn class_1269.field_5811>'' as other callbacks should still be called. See the [[https://github.com/FabricMC/fabric/blob/12865e786ce2102d344304a679b70084be84d166/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java#L29-L39|AttackBlockCallback]] JavaDoc in your IDE for the meaning of other values. +此例注册一个 ''AttackBlockCallback'',玩家击打不能徒手挖掘掉落的方块时,会受到伤害。会返回 ''<yarn class_1269.field_5811>'' 因为还需要调用其他的回调。关于其他值的含义,请参考你的 IDE 中 [[https://github.com/FabricMC/fabric/blob/12865e786ce2102d344304a679b70084be84d166/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java#L29-L39|AttackBlockCallback]] 的 JavaDoc
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
 public class ExampleMod implements ModInitializer public class ExampleMod implements ModInitializer
Line 29: Line 27:
         {         {
             class_2680 state = world.method_8320(pos);             class_2680 state = world.method_8320(pos);
-            /* Manual spectator check is necessary because AttackBlockCallbacks +            /* 手动的旁观者检查是必要的,因为 AttackBlockCallbacks 会在旁观者检查之前应用 */
-               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()) 
zh_cn/tutorial/callbacks.txt · Last modified: 2023/05/04 11:01 by solidblock