Changes

955 bytes added ,  16:28, 10 February 2021
Add section for event bus
Line 17: Line 17:  
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.
   −
<br>
+
= Event Bus =
 +
An '''event bus''' is an object which holds a list of event listeners. Events may be fired on these event buses, which is then given to each event listener in turn.
 +
 
 +
== Forge and Mod Buses ==
 +
There are two event buses of note to a mod: the '''main Forge event bus''', and the '''mod-specific event bus'''.
 +
 
 +
The Forge event bus is the primary event bus where most mods relating to the game are fired on, including ticking events, entity events, server events, and more. This event bus is located at <code>MinecraftForge#EVENT_BUS</code>.
 +
 
 +
The mod-specific event bus is an event bus created for each mod loaded by the FMLJavaMod language provider (which is the default language provider for Java mods). This can be retrieved from <code>FMLJavaModLoadingContext#getEventBus()</code> when in the mod's constructor. This is where [[Stages of Modloading|mod loading events]] are fired on for mods (which may be fired in parallel for multiple mods).
 +
 
 +
 
 +
 
    
Forge uses an event bus that allows mods to intercept events from various vanilla and mod behaviors.
 
Forge uses an event bus that allows mods to intercept events from various vanilla and mod behaviors.
297

edits