Changes

53 bytes added ,  13:09, 3 April 2022
Add mod bus list
Line 8: Line 8:  
'''Generic events''' are events which supply additional generic type information, allowing event listeners to filter based on that secondary type. Generic events must implement <code>IGenericEvent<T></code>, and return their generic type from the <code>IGenericEvent#getType()</code> method. As a convenience, events that wish to be generic events may extend the <code>GenericEvent<T></code> instead of manually implementing the interface.
 
'''Generic events''' are events which supply additional generic type information, allowing event listeners to filter based on that secondary type. Generic events must implement <code>IGenericEvent<T></code>, and return their generic type from the <code>IGenericEvent#getType()</code> method. As a convenience, events that wish to be generic events may extend the <code>GenericEvent<T></code> instead of manually implementing the interface.
   −
For generic events, the generic type must be an exact match with the listener's generic type filter to pass; if an <code>AttachCapabilitiesEvent<ItemStack></code> is fired and a listener is listening for <code>AttachCapabilitiesEvent<Object></code>, the listener does not receive the event. A event listener may listen to events with any generic type by supplying a wildcard generic (<code><?></code>). Nested generic types are ignored.
+
For generic events, the generic type must be an exact match with the listener's generic type filter to pass; if an <code>AttachCapabilitiesEvent<ItemStack></code> is fired and a listener is listening for <code>AttachCapabilitiesEvent<Object></code>, the listener does not receive the event. If an event listener is registered using <code>EventBus#register(Object)</code>, it may listen to events with any generic type by supplying a wildcard generic (<code><?></code>). Nested generic types are ignored.
    
== Cancellable Events ==
 
== Cancellable Events ==
Line 26: Line 26:  
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. The main class for event buses is <code>IEventBus</code>, and a bus is created using <code>BusBuilder</code>.
 
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. The main class for event buses is <code>IEventBus</code>, and a bus is created using <code>BusBuilder</code>.
   −
=== Existing Buses ===
+
You can find a more detailed explanation on the Event Bus pattern [https://dzone.com/articles/design-patterns-event-bus here.]
 +
===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.
 
Forge exposes three main families of event buses: the main Forge event bus, the mod-specific event buses, and the network channel event buses.
 +
====Main Forge Event Bus====
 +
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.
   −
==== Main Forge Event Bus ====
  −
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;">
+
List of events fired on the main Forge event bus{{:Events/Forge bus}}
<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>
     −
==== Mod-Specific Event Buses ====
+
====Mod-Specific Event Buses====
 
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.
 
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.
   Line 48: Line 46:  
{{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.}}
 
{{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.}}
   −
==== Network Channel Event Buses ====
+
List of events fired on the Mod-Specific event bus{{:Events/Mod bus}}
 +
 
 +
====Network Channel Event Buses====
 
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''' 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.
   Line 206: Line 206:       −
An example for a static event listener listening to <code>RenderWorldLastEvent</code> which will only be called on the physical client:  
+
An example for a static event listener listening to <code>RenderLevelLastEvent</code> which will only be called on the physical client:  
    
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
Line 212: Line 212:  
public class MyStaticClientOnlyEventHandler {
 
public class MyStaticClientOnlyEventHandler {
 
     @SubscribeEvent
 
     @SubscribeEvent
     public static void drawLast(RenderWorldLastEvent event) {
+
     public static void drawLast(RenderLevelLastEvent event) {
 
         System.out.println("Drawing!");
 
         System.out.println("Drawing!");
 
     }
 
     }
Line 292: Line 292:  
* <code>Event</code> - ''The root event class''
 
* <code>Event</code> - ''The root event class''
 
** '''Rendering events''' ('''client-only''')
 
** '''Rendering events''' ('''client-only''')
*** <code>RenderWorldLastEvent</code> - Fired after world rendering to allow mods to add custom renders
+
*** <code>RenderLevelLastEvent</code> - Fired after level rendering to allow mods to add custom renders
 
*** <code>RenderHandEvent</code> - Fired before and after the hand of the player is rendered in the first person POV
 
*** <code>RenderHandEvent</code> - Fired before and after the hand of the player is rendered in the first person POV
 
*** <code>RenderLivingEvent</code> - Fired before and after a <code>LivingRenderer</code> is executed
 
*** <code>RenderLivingEvent</code> - Fired before and after a <code>LivingRenderer</code> is executed
Line 301: Line 301:  
*** <code>EntityViewRenderEvent</code> - Superclass for events relating to the player's viewpoint
 
*** <code>EntityViewRenderEvent</code> - Superclass for events relating to the player's viewpoint
 
*** <code>RenderGameOverlayEvent</code> - Superclass, fired for each element on the player's HUD or game overlay
 
*** <code>RenderGameOverlayEvent</code> - Superclass, fired for each element on the player's HUD or game overlay
*** <code>FOVUpdateEvent</code> - Fired when the FOV of the player is requested (?)
+
*** <code>FOVModifierEvent</code> - Fired when the FOV of the player is requested (?)
** '''GUI/Screen events''' ('''client-only''')
+
** '''Screen events''' ('''client-only''')
*** <code>GuiScreenEvent</code> - Superclass for events relating to <code>Screen</code>s
+
*** <code>ScreenEvent</code> - Superclass for events relating to <code>Screen</code>s
*** <code>GuiContainerEvent</code> - Superclsas for events relating to <code>ContainerScreen</code>s
+
*** <code>ScreenContainerEvent</code> - Superclsas for events relating to <code>ContainerScreen</code>s
*** <code>GuiOpenEvent</code> - Fired before a new screen is opened on the game window
+
*** <code>ScreenOpenEvent</code> - Fired before a new screen is opened on the game window
 
** '''Superclass events''' - ''These events exist to be superclasses of other events''
 
** '''Superclass events''' - ''These events exist to be superclasses of other events''
 
*** <code>GenericEvent</code> - ''from EventBus'', superclass of events which have a generic type
 
*** <code>GenericEvent</code> - ''from EventBus'', superclass of events which have a generic type
*** <code>BlockEvent</code> - Superclass for events relating to a block within the world
+
*** <code>BlockEvent</code> - Superclass for events relating to a block within the level
*** <code>WorldEvent</code> - Superclass for events relating to the world
+
*** <code>LevelEvent</code> - Superclass for events relating to the level
 
*** <code>InputEvent</code> - ('''client-only''') Superclass for events relating to the player's keyboard and mouse inputs
 
*** <code>InputEvent</code> - ('''client-only''') Superclass for events relating to the player's keyboard and mouse inputs
 
*** <code>NetworkEvent</code> - Superclass for events relating to networking
 
*** <code>NetworkEvent</code> - Superclass for events relating to networking
*** <code>ExplosionEvent</code> - Fired before an explosion explodes in the world
+
*** <code>ExplosionEvent</code> - Fired before an explosion explodes in the level
 
*** <code>SoundEvent</code> - ('''client-only''') Superclass for events related to sounds
 
*** <code>SoundEvent</code> - ('''client-only''') Superclass for events related to sounds
 
*** <code>EntityEvent</code> - Superclass for events relating to entities
 
*** <code>EntityEvent</code> - Superclass for events relating to entities
Line 331: Line 331:  
** '''Gamemode events'''
 
** '''Gamemode events'''
 
*** <code>DifficultyChangeEvent</code>
 
*** <code>DifficultyChangeEvent</code>
*** <code>ClientPlayerChangeGamemodeEvent</code>
+
*** <code>ClientPlayerChangeGameTypeEvent</code>
 
**'''Trade events'''
 
**'''Trade events'''
 
*** <code>WandererTradesEvent</code>
 
*** <code>WandererTradesEvent</code>
Line 355: Line 355:     
[[Category:Events]]
 
[[Category:Events]]
 +
 +
 +
[[Category:Common Concepts]]