tutorial:callbacks
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tutorial:callbacks [2020/02/17 09:29] – created mkpoli | tutorial:callbacks [2025/12/05 16:42] (current) – redirect to docs cassiancc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ~~REDIRECT> |
| + | ====== | ||
| + | In this tutorial you will learn to: | ||
| + | - Understand Events and Callbacks | ||
| + | - Register a callback for an existing Event | ||
| - | ===== Callbacks Classes | + | ===== Events |
| - | Callbacks Classes | + | Events |
| - | ==== Callbacks | + | ===== Callbacks |
| - | Event Callbacks | + | Each event has a corresponding callback interface, conventionally named '' |
| - | A list of existing callbacks | + | ==== Callback Interfaces in Fabric API ==== |
| + | All event callback interfaces provided by Fabric API can be found in the '' | ||
| + | A partial | ||
| + | ==== Custom Callbacks ==== | ||
| + | Although there are plenty of events already provided by Fabric API, you can still make your own events. Please refer to [[tutorial: | ||
| + | |||
| + | ===== Practice ====== | ||
| + | This example registers an '' | ||
| - | === Player | + | < |
| + | public class ExampleMod implements ModInitializer { | ||
| + | [...] | ||
| + | |||
| + | @Override | ||
| + | public void onInitialize() { | ||
| + | AttackBlockCallback.EVENT.register((player, | ||
| + | class_2680 state = world.method_8320(pos); | ||
| + | /* Manual spectator check is necessary because AttackBlockCallbacks | ||
| + | fire before the spectator check */ | ||
| + | if (state.method_29291() && !player.method_7325() && | ||
| + | player.method_6047().method_7960()) { | ||
| + | player.method_5643(class_1282.field_5869, | ||
| + | } | ||
| + | return class_1269.field_5811; | ||
| + | }); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Fabric API Events ====== | ||
| + | === Player | ||
| Player: [[https:// | Player: [[https:// | ||
| Line 16: | Line 48: | ||
| === Registry Events === | === Registry Events === | ||
| - | <!-- TODO: Add Events | + | [[https:// |
| - | === Looting Events === | + | [[https:// |
| - | <!-- TODO: Add Events | + | |
| === Looting Events === | === Looting Events === | ||
| - | <!-- TODO: Add Events --> | + | [[https:// |
| - | === Render Events === | + | There is an example of using '' |
| - | <!-- TODO: Add Events --> | + | |
| - | There is an example using '' | + | === World Events === |
| + | [[https:// | ||
| + | === Server Events === | ||
| + | [[https:// | ||
| + | === Network Events === | ||
| + | [[https:// | ||
| - | ==== Custom Callbacks ==== | + | See [[tutorial:event_index|Event Index]] for a more complete |
| - | 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]]. | + | |
| - | + | ||
| - | + | ||
| - | ===== Practice ===== | + | |
| - | Let's see Take '' | + | |
| - | + | ||
| - | 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 | + | |
| - | + | ||
| - | + | ||
| - | As stated in javadoc of '' | + | |
| - | + | ||
| - | < | + | |
| - | /** | + | |
| - | * Callback for left-clicking (" | + | |
| - | * Is hooked in before the spectator check, so make sure to check for the player' | + | |
| - | * | + | |
| - | * < | + | |
| - | * < | + | |
| - | * < | + | |
| - | * < | + | |
| - | * | + | |
| - | * < | + | |
| - | */ | + | |
| - | </ | + | |
| - | + | ||
| - | <code java [enable_line_numbers=" | + | |
| - | public class ExampleMod implements ModInitializer | + | |
| - | { | + | |
| - | [...] | + | |
| - | + | ||
| - | @Override | + | |
| - | public void onInitialize() { | + | |
| - | AttackBlockCallback.EVENT.register((player, | + | |
| - | // Do sth... | + | |
| - | if ([condition]) { | + | |
| - | return ActionResult.SUCCESS; | + | |
| - | } else { | + | |
| - | return ActionResult.PASS; | + | |
| - | } | + | |
| - | + | ||
| - | }) | + | |
| - | } | + | |
| - | } | + | |
| - | </ | + | |
tutorial/callbacks.1581931741.txt.gz · Last modified: 2020/02/17 09:29 by mkpoli