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
zh_cn:tutorial:callbacks [2021/10/23 02:04] – external edit 127.0.0.1zh_cn:tutorial:callbacks [2023/05/04 11:01] (current) – [实例] solidblock
Line 17: Line 17:
 此例注册一个 ''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。 此例注册一个 ''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 {
-{+
     [...]     [...]
          
     @Override     @Override
-    public void onInitialize()  +    public void onInitialize() { 
-    +        AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> {
-        AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) ->  +
-        {+
             class_2680 state = world.method_8320(pos);             class_2680 state = world.method_8320(pos);
             /* 手动的旁观者检查是必要的,因为 AttackBlockCallbacks 会在旁观者检查之前应用 */             /* 手动的旁观者检查是必要的,因为 AttackBlockCallbacks 会在旁观者检查之前应用 */
             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, 1.0F);                 player.method_5643(class_1282.field_5869, 1.0F);
             }              } 
zh_cn/tutorial/callbacks.1634954685.txt.gz · Last modified: 2021/10/23 02:04 by 127.0.0.1