Skip to content

GenericEventManager

youyihj edited this page Dec 11, 2023 · 6 revisions

GenericEventManager

@since 1.16.0

GenericEventManager is a expansion of CraftTweaker event manager, add 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 listened 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();
});

EntityPriority

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