tutorial:callbacks
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:callbacks [2020/02/17 18:26] – accept suggestions from @JamiesWhiteShirt et al. at Discord (renaming) & Add events mkpoli | tutorial:callbacks [2024/12/18 19:41] (current) – [Fabric API Events] Fix outdated server start/stop events radstevee | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | In this tutorial, you are going to achieve: | + | In this tutorial you will learn to: |
- Understand Events and Callbacks | - Understand Events and Callbacks | ||
- | - Be able to register | + | - Register |
- | ===== Callback Interfaces | + | ===== Events |
- | There is a series | + | Events are represented by instances of '' |
+ | |||
+ | ===== Callbacks ===== | ||
+ | Each event has a corresponding callback interface, conventionally named '' | ||
==== Callback Interfaces in Fabric API ==== | ==== Callback Interfaces in Fabric API ==== | ||
- | Event Callbacks | + | All event callback interfaces |
+ | A partial list of existing callbacks is provided at the bottom of this tutorial. | ||
- | Here is a partial list of existing callbacks. | + | ==== Custom Callbacks ==== |
+ | Although there are plenty | ||
- | === Player | + | ===== Practice ====== |
+ | This example registers an '' | ||
+ | |||
+ | < | ||
+ | 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 25: | Line 54: | ||
[[https:// | [[https:// | ||
- | There is an example using '' | + | There is an example |
=== World Events === | === World Events === | ||
Line 31: | Line 60: | ||
=== Server Events === | === Server Events === | ||
- | [[https:// | + | [[https:// |
=== Network Events === | === Network Events === | ||
[[https:// | [[https:// | ||
- | ==== Custom Callbacks ==== | + | See [[tutorial:event_index|Event Index]] for a more complete |
- | 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 --> | + | |
- | + | ||
- | Let's see Take '' | + | |
- | + | ||
- | 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 ; | + | |
- | + | ||
- | + | ||
- | As stated in javadoc of '' | + | |
- | + | ||
- | <code java> | + | |
- | /** | + | |
- | * Callback for left-clicking (" | + | |
- | * Is hooked in before the spectator check, so make sure to check for the player' | + | |
- | * | + | |
- | * < | + | |
- | * < | + | |
- | * < | + | |
- | * < | + | |
- | * | + | |
- | * < | + | |
- | */ | + | |
- | </ | + | |
- | + | ||
- | <!-- TODO: Really do sth. --> | + | |
- | + | ||
- | <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; | + | |
- | } | + | |
- | + | ||
- | }) | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <!-- TODO: An image of the effect of something have done --> | + |
tutorial/callbacks.1581964016.txt.gz · Last modified: 2020/02/17 18:26 by mkpoli