User Tools

Site Tools


tutorial:callbacks

Differences

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

Link to this comparison view

Next revisionBoth sides next revision
tutorial:callbacks [2020/02/17 09:29] – created mkpolitutorial:callbacks [2020/02/17 18:26] – accept suggestions from @JamiesWhiteShirt et al. at Discord (renaming) & Add events mkpoli
Line 1: Line 1:
-====== Register a Callback Listener for Events (DRAFT) ======+====== Register a Callback on an existing Event (DRAFT) ====== 
 +In this tutorial, you are going to achieve: 
 +  - Understand Events and Callbacks 
 +  - Be able to register a Callback on an existing Event
  
-===== Callbacks Classes ===== +===== Callback Interfaces ===== 
-Callbacks Classes are a series of Classes which named [Eventname]Callback is able to register a callback listener function to the specific event.+There is a series of interfaces named [EventName]Callback. They will handle the events (get called by mixins), invoke callbacks which are registered on mod initialization.
  
-==== Callbacks in Fabric API ====+==== Callback Interfaces in Fabric API ====
 Event Callbacks provided by Fabric API can be found in ''net.fabricmc.fabric.api.event'' package. Event Callbacks provided by Fabric API can be found in ''net.fabricmc.fabric.api.event'' package.
  
-list of existing callbacks +Here is a partial list of existing callbacks.
  
 === Player Interactive Events === === Player Interactive Events ===
Line 16: Line 18:
  
 === Registry Events === === Registry Events ===
-<!-- TODOAdd Events -->+[[https://github.com/FabricMC/fabric/blob/1.15/fabric-object-builders-v0/src/main/java/net/fabricmc/fabric/api/event/registry/BlockConstructedCallback.java|BlockConstructedCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-object-builders-v0/src/main/java/net/fabricmc/fabric/api/event/registry/ItemConstructedCallback.java|ItemConstructedCallback]]
  
-=== Looting Events === +[[https://github.com/FabricMC/fabric/blob/1.15/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/api/event/registry/RegistryEntryAddedCallback.java|RegistryEntryAddedCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/api/event/registry/RegistryEntryRemovedCallback.java|RegistryEntryRemovedCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/api/event/registry/RegistryIdRemapCallback.java|RegistryIdRemapCallback]]
-<!-- TODOAdd Events -->+
  
 === Looting Events === === Looting Events ===
-<!-- TODOAdd Events --+[[https://github.com/FabricMC/fabric/blob/1.15/fabric-loot-tables-v1/src/main/java/net/fabricmc/fabric/api/loot/v1/event/LootTableLoadingCallback.java|LootTableLoadingCallback]]
- +
-=== Render Events === +
-<!-- TODO: Add Events -->+
  
 There is an example using ''LootTableLoadingCallback'' you can find [[tutorial:adding_to_loot_tables|here]]. There is an example using ''LootTableLoadingCallback'' you can find [[tutorial:adding_to_loot_tables|here]].
  
 +=== World Events ===
 +[[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-lifecycle-v0/src/main/java/net/fabricmc/fabric/api/event/world/WorldTickCallback.java|WorldTickCallback]]
  
 +=== Server Events ===
 +[[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-lifecycle-v0/src/main/java/net/fabricmc/fabric/api/event/server/ServerStartCallback.java|ServerStartCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-lifecycle-v0/src/main/java/net/fabricmc/fabric/api/event/server/ServerStopCallback.java|ServerStopCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-events-lifecycle-v0/src/main/java/net/fabricmc/fabric/api/event/server/ServerTickCallback.java|ServerTickCallback]]
 +
 +=== Network Events ===
 +[[https://github.com/FabricMC/fabric/blob/1.15/fabric-networking-v0/src/main/java/net/fabricmc/fabric/api/event/network/C2SPacketTypeCallback.java|C2SPacketTypeCallback]] / [[https://github.com/FabricMC/fabric/blob/1.15/fabric-networking-v0/src/main/java/net/fabricmc/fabric/api/event/network/S2CPacketTypeCallback.java|S2CPacketTypeCallback]]
  
 ==== Custom Callbacks ==== ==== Custom Callbacks ====
-Although there is plenty of Callbacks provided already by Fabric API, you can still make your own API for your goal. Please refer to [[tutorial:events]].+Although there are plenty of events already provided by Fabric API, you can still make your own events. Please refer to [[tutorial:events]].
  
 +===== Practice ======
 +<!-- TODO: Add explaination -->
  
-===== Practice ===== 
 Let's see Take ''AttackBlockCallback'' as an example for how register a listener Let's see Take ''AttackBlockCallback'' as an example for how register a listener
 +
 +Basically, we are going to ... (an event listener) callback to listen the event.
  
 Since there is not more a method that is able to be called on a block clicked, you may want to. If you want to make a ; Since there is not more a method that is able to be called on a block clicked, you may want to. If you want to make a ;
  
-You can interrupt and stop continuing by sending ActionResult.SUCCESS; 
  
 +As stated in javadoc of ''AttackBlockCallback'', this event accepts ; You can interrupt and stop continuing by sending ActionResult.SUCCESS;
  
-As stated in javadoc of ''AttackBlockCallback'' +<code java>
- +
-<code>+
 /** /**
  * Callback for left-clicking ("attacking") a block.  * Callback for left-clicking ("attacking") a block.
Line 58: Line 64:
  */  */
 </code> </code>
 +
 +<!-- TODO: Really do sth. -->
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 78: Line 86:
 } }
 </code> </code>
 +
 +<!-- TODO: An image of the effect of something have done -->
  
tutorial/callbacks.txt · Last modified: 2023/05/04 11:01 by solidblock