Line 5: |
Line 5: |
| Additionally, mods may create their own events and fire them for other mods to listen for, allowing for higher compatibility. | | Additionally, mods may create their own events and fire them for other mods to listen for, allowing for higher compatibility. |
| | | |
− | = Cancellable Events = | + | == Cancellable Events == |
| An event may be marked as '''cancellable''', which allows event listeners to cancel the event. | | An event may be marked as '''cancellable''', which allows event listeners to cancel the event. |
| | | |
Line 12: |
Line 12: |
| To mark an event as cancellable, the event class should be annotated with <code>@Cancelable</code>. This will automatically make <code>Event#isCancelable()</code> return <code>true</code>. Modders may check if an event has a result through the presence of the annotation or by calling the given method. | | To mark an event as cancellable, the event class should be annotated with <code>@Cancelable</code>. This will automatically make <code>Event#isCancelable()</code> return <code>true</code>. Modders may check if an event has a result through the presence of the annotation or by calling the given method. |
| | | |
− | = Events with Results = | + | == Events with Results == |
− | An event may have a ```result''', which is an enum of <code>Event.Result</code>. | + | An event may have a '''result''', which is an enum of <code>Event.Result</code>. |
| | | |
| The <code>Event.Result</code> enum has three values: <code>ALLOW</code>, <code>DEFAULT</code>, and <code>DENY</code>. The meaning of these result values is entirely dependent on the event itself. | | The <code>Event.Result</code> enum has three values: <code>ALLOW</code>, <code>DEFAULT</code>, and <code>DENY</code>. The meaning of these result values is entirely dependent on the event itself. |
Line 21: |
Line 21: |
| To mark an event as having a result, the event class should be annotated with <code>@Event.HasResult</code>. This will automatically make <code>Event#hasResult</code> return <code>true</code>. Modders may check if an event has a result through the presence of the annotation or by calling the given method. | | To mark an event as having a result, the event class should be annotated with <code>@Event.HasResult</code>. This will automatically make <code>Event#hasResult</code> return <code>true</code>. Modders may check if an event has a result through the presence of the annotation or by calling the given method. |
| | | |
− | = Event Bus = | + | == Event Bus == |
| An '''event bus''' is an object which holds a list of event listeners, and the logic for firing the events. Events may be posted on these event buses, which then invokes the handlers. | | An '''event bus''' is an object which holds a list of event listeners, and the logic for firing the events. Events may be posted on these event buses, which then invokes the handlers. |
| + | |
| + | === Existing Buses === |
| + | Forge exposes three main families of event buses: the main Forge event bus, the mod-specific event buses, and the network channel event buses. |
| + | |
| + | The '''main Forge event bus''' is located at <code>MinecraftForge#EVENT_BUS</code>, and is where most events relating to ingame actions or events are fired on, such as events for ticking, block interactions, and entity interactions. |
| + | |
| + | <div class="mw-collapsible mw-collapsed" style="border: 2px solid; border-radius: 2px; padding: 5px; margin: 1em; overflow:auto;"> |
| + | <div style="font-weight:bold; line-height:1.6;">List of events fired on the main Forge event bus</div> |
| + | <div class="mw-collapsible-content"> |
| + | {{:Events/Forge bus}} |
| + | </div></div> |
| + | |
| + | The '''mod-specific event buses''' are the family of event buses where mod-related initialization and registration events are fired, such as the events for [[Registration|registering objects]] or setup on different physical sides. Only events which implement <code>IModBusEvent</code> may be fired or listened for on these event buses. |
| + | |
| + | Each loaded mod has their own instance of a mod-specific event bus. The mod-specific event bus for the currently loading mod can be retrieved from <code>FMLModContainer#getEventBus()</code>, which is also accessible from <code>FMLJavaModLoadingContext#getModEventBus()</code>. |
| + | {{Tip|title=Tip|The mod-specific event buses are provided by the <code>javafml</code> language provider which is builtin to Forge Mod Loader. Custom language providers may provide other ways for mods to receive the different mod-related initialization and registration events; see the documentation of your custom language provider for details.}} |
| + | |
| + | The '''network channel event buses''' are the family of event buses where different network-related events are fired. Each registered [[Networking|networking channel]] has their own instance of an event-bus in <code>NetworkInstance</code>, where only events pertinent to that channel are fired on. |
| + | |
| + | The network channel event buses cannot be accessed directly; <code>EventNetworkChannel</code> provides methods to register events listeners to the event bus. |
| + | |
| + | |
| + | |
| | | |
| == Forge and Mod Buses == | | == Forge and Mod Buses == |