Skip to content

GenericEventManager

youyihj edited this page Feb 21, 2024 · 6 revisions

GenericEventManager

@since 1.16.0

GenericEventManager is an expansion of CraftTweaker event manager, adds a method to register handler for almost all events. In addition, it adds event priority and receive canceled parameter, making possible to control other mod logic that listen to the same event.

Usage

events.register(IEventHandler<T> eventHandler, @Optional EventPriority priority, @Optional bool receiveCanceled)

Example

import crafttweaker.event.EntityLivingAttackedEvent;
import mods.zenutils.EventPriority;

// This event listener is registered at lowest priority and would receive canceled
// It always runs after all other event handlers no matter the event is canceled or not
events.register(function(event as EntityLivingAttackedEvent) {
    event.entity.sendMessage("The event is canceled: " ~ event.canceled);
}, EventPriority.lowest(), true);

// Old way
// This event listener is registered at normal priority
events.onEntityLivingAttacked(function(event as EntityLivingAttackedEvent) {
    event.cancel();
});

EventPriority

Defines the priority of the event listener

Package: mods.zenutils.EventPriority

5 priorities are available:

  • highest
  • high
  • normal (default)
  • low
  • lowest

Note

This method directly accesses forge event internal code. Only events that simply delegate forge events can use it.

Known unavailable events:

CraftTweaker:

  • PlayerLoggedIn
  • PlayerLoggedOut
  • PlayerSmelted

ZenUtils:

  • EntityRemove
  • EntityItemFall
  • EntityItemDeath
Clone this wiki locally