User Tools

Site Tools


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
tutorial:callbacks [2021/07/14 23:31] – Flesh out draft into something more useful daomephstatutorial:callbacks [2023/05/04 11:01] (current) – [Practice] solidblock
Line 18: Line 18:
  
 ===== Practice ====== ===== Practice ======
-This example registers an ''AttackBlockCallback'' to damage players when they hit blocks 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.+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.
  
 <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);
             /* Manual spectator check is necessary because AttackBlockCallbacks             /* Manual spectator check is necessary because AttackBlockCallbacks
                fire before the spectator check */                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, 1.0F);                 player.method_5643(class_1282.field_5869, 1.0F);
             }              } 
Line 44: Line 40:
 </yarncode> </yarncode>
  
 +===== Fabric API Events ======
 === Player Interaction Events === === Player Interaction Events ===
 Player: [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java|AttackBlockCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java|AttackEntityCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java|UseBlockCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java|UseEntityCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java|UseItemCallback]] Player: [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/AttackBlockCallback.java|AttackBlockCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/AttackEntityCallback.java|AttackEntityCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseBlockCallback.java|UseBlockCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseEntityCallback.java|UseEntityCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-interaction-v0/src/main/java/net/fabricmc/fabric/api/event/player/UseItemCallback.java|UseItemCallback]]
tutorial/callbacks.txt · Last modified: 2023/05/04 11:01 by solidblock