User Tools

Site Tools


tutorial:events

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:events [2020/06/09 23:16] – formatting changes draylartutorial:events [2025/12/29 07:00] (current) gauntrecluse
Line 1: Line 1:
 +~~REDIRECT>https://docs.fabricmc.net/develop/events#custom-events~~
 +
 ====== Custom Events ====== ====== Custom Events ======
 Fabric API provides a system that allows mods to react to events that occur in the game. Events are hooks that satisfy common use cases and/or provide enhanced compatibility and performance between mods that hook into the same areas of the code. The use of events often substitutes the use of mixins. Fabric API provides events for important areas in the Minecraft codebase that multiple modders may be interested in hooking into. Some areas do not have hooks, so you can opt to use a mixin, or create your own event. Fabric API provides a system that allows mods to react to events that occur in the game. Events are hooks that satisfy common use cases and/or provide enhanced compatibility and performance between mods that hook into the same areas of the code. The use of events often substitutes the use of mixins. Fabric API provides events for important areas in the Minecraft codebase that multiple modders may be interested in hooking into. Some areas do not have hooks, so you can opt to use a mixin, or create your own event.
Line 37: Line 39:
 <code java [enable_line_numbers="false"]> <code java [enable_line_numbers="false"]>
 (listeners) -> (player, sheep) -> { (listeners) -> (player, sheep) -> {
-    for (SheepShearCallback event : listeners) {+    for (SheepShearCallback listener : listeners) {
 </code> </code>
 We then call our method (in this case, ''interact'') on the listener to get its response: We then call our method (in this case, ''interact'') on the listener to get its response:
 <code java [enable_line_numbers="false"]> <code java [enable_line_numbers="false"]>
-ActionResult result = event.interact(player, sheep);+ActionResult result = listener.interact(player, sheep);
 </code> </code>
 If the listener says we have to cancel (''ActionResult.FAIL'') or fully finish (''ActionResult.SUCCESS''), the callback returns the result and finishes the loop. ''ActionResult.PASS'' moves on to the next listener, and in most cases should result in success if there are no more listeners registered: If the listener says we have to cancel (''ActionResult.FAIL'') or fully finish (''ActionResult.SUCCESS''), the callback returns the result and finishes the loop. ''ActionResult.PASS'' moves on to the next listener, and in most cases should result in success if there are no more listeners registered:
tutorial/events.1591744571.txt.gz · Last modified: 2020/06/09 23:16 by draylar