java.lang.Object
net.neoforged.bus.EventBus
- All Implemented Interfaces:
IEventBus,IEventExceptionHandler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Event>
voidaddListener(boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Add a consumer listener receiving potentially canceled events.<T extends Event>
voidaddListener(boolean receiveCanceled, Consumer<T> consumer) Add a consumer listener receiving potentially canceled events.<T extends Event>
voidaddListener(Class<T> eventType, Consumer<T> consumer) Add a consumer listener not receiving canceled events.<T extends Event>
voidaddListener(Consumer<T> consumer) Add a consumer listener with defaultEventPriority.NORMALand not recieving canceled events.<T extends Event>
voidaddListener(EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand potentially canceled events.<T extends Event>
voidaddListener(EventPriority priority, boolean receiveCanceled, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand potentially canceled events.<T extends Event>
voidaddListener(EventPriority priority, Class<T> eventType, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand not receiving canceled events.<T extends Event>
voidaddListener(EventPriority priority, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand not receiving canceled events.voidhandleException(IEventBus bus, Event event, EventListener[] listeners, int index, Throwable throwable) Fired when a EventListener throws an exception for the specified event on the event bus.<T extends Event>
Tpost(EventPriority phase, T event) Submit the event for dispatch to listeners registered with a specificEventPriority.<T extends Event>
Tpost(T event) Submit the event for dispatch to appropriate listenersvoidRegister an instance object or a Class, and add listeners for allSubscribeEventannotated methods found there, or directly a Method annotated withSubscribeEvent.voidstart()Start this bus (if it was created shut down), making it able to post events to listeners.voidunregister(Object object) Unregister the supplied listener from this EventBus.
-
Constructor Details
-
EventBus
-
-
Method Details
-
register
Description copied from interface:IEventBusRegister an instance object or a Class, and add listeners for allSubscribeEventannotated methods found there, or directly a Method annotated withSubscribeEvent. Depending on what is passed as an argument, different listener creation behaviour is performed.- Object Instance
- Scanned for non-static methods annotated with
SubscribeEventand creates listeners for each method found. - Class Instance
- Scanned for static methods annotated with
SubscribeEventand creates listeners for each method found. - Method Instance
- Expects a static method annotated with
SubscribeEventwhich will be registered as a listener for the Event type it has as its sole parameter.
-
addListener
Description copied from interface:IEventBusAdd a consumer listener with defaultEventPriority.NORMALand not recieving canceled events.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
consumer- Callback to invoke when a matching event is received
-
addListener
Description copied from interface:IEventBusAdd a consumer listener with the specifiedEventPriorityand not receiving canceled events.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenerconsumer- Callback to invoke when a matching event is received
-
addListener
public <T extends Event> void addListener(EventPriority priority, boolean receiveCanceled, Consumer<T> consumer) Description copied from interface:IEventBusAdd a consumer listener with the specifiedEventPriorityand potentially canceled events.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenerreceiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledconsumer- Callback to invoke when a matching event is received
-
addListener
public <T extends Event> void addListener(EventPriority priority, Class<T> eventType, Consumer<T> consumer) Description copied from interface:IEventBusAdd a consumer listener with the specifiedEventPriorityand not receiving canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenereventType- The concreteEventsubclass to subscribe toconsumer- Callback to invoke when a matching event is received
-
addListener
Description copied from interface:IEventBusAdd a consumer listener receiving potentially canceled events.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
receiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledconsumer- Callback to invoke when a matching event is received
-
addListener
public <T extends Event> void addListener(boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Description copied from interface:IEventBusAdd a consumer listener receiving potentially canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
receiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledeventType- The concreteEventsubclass to subscribe toconsumer- Callback to invoke when a matching event is received
-
addListener
Description copied from interface:IEventBusAdd a consumer listener not receiving canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
eventType- The concreteEventsubclass to subscribe toconsumer- Callback to invoke when a matching event is received
-
addListener
public <T extends Event> void addListener(EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Description copied from interface:IEventBusAdd a consumer listener with the specifiedEventPriorityand potentially canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to.- Specified by:
addListenerin interfaceIEventBus- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenerreceiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledeventType- The concreteEventsubclass to subscribe toconsumer- Callback to invoke when a matching event is received
-
unregister
Description copied from interface:IEventBusUnregister the supplied listener from this EventBus. Removes all listeners from events. NOTE: Consumers can be stored in a variable if unregistration is required for the Consumer.- Specified by:
unregisterin interfaceIEventBus- Parameters:
object- The object, Class, Method or Consumer to unsubscribe.
-
post
Description copied from interface:IEventBusSubmit the event for dispatch to appropriate listenersIf this bus was not started yet, the event is returned without being dispatched.
-
post
Description copied from interface:IEventBusSubmit the event for dispatch to listeners registered with a specificEventPriority.If this bus was not started yet, the event is returned without being dispatched.
Manually posting events phase-by-phase through this method is less performant than dispatching to all phases through a
IEventBus.post(Event)call. Prefer that method when per-phase dispatching is not needed. -
handleException
public void handleException(IEventBus bus, Event event, EventListener[] listeners, int index, Throwable throwable) Description copied from interface:IEventExceptionHandlerFired when a EventListener throws an exception for the specified event on the event bus. After this function returns, the original Throwable will be propagated upwards.- Specified by:
handleExceptionin interfaceIEventExceptionHandler- Parameters:
bus- The bus the event is being fired onevent- The event that is being firedlisteners- All listeners that are listening for this event, in orderindex- Index for the current listener being fired.throwable- The throwable being thrown
-
start
public void start()Description copied from interface:IEventBusStart this bus (if it was created shut down), making it able to post events to listeners.
-