-
Notifications
You must be signed in to change notification settings - Fork 11
GenericEventManager
@since 1.16.0
GenericEventManager is an expansion of CraftTweaker event manager, adds a method to register handler for almost all events (including native forge / mods ones). In addition, it adds event priority and receive canceled parameter, making possible to control other mod logic that listen to the same event.
events.register(IEventHandler<T> eventHandler, @Optional EventPriority priority, @Optional bool receiveCanceled, @Optional int busID)
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();
});Defines the priority of the event listener
Package: mods.zenutils.EventPriority
5 priorities are available:
highesthigh-
normal(default) lowlowest
Describes which bus should be subscribed. The default value is 0 for the main event bus.
Terrain gen bus is 1. Ore gen bus is 2.
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
- GlobalFunctions
- ScriptReloading
- SuppressErrorPreprocessor
- HardFailPreprocessor
- OrderlyMap
- IData Deep Update
- Template String
- Nullish Operators
- Array and List Operations
- Native Method Access
- Mixin
- CrTI18n
- CrTUUID
- CrTItemHandler
- CrTLiquidHandler
- ILiquidTankProperties
- StringList
- HexHelper
- StaticString
- Catenation
- PersistedCatenation
- PlayerStat
- IStatFormatter
- GameRuleHelper
- ZenCommand
- ZenCommandTree
- ZenUtilsCommandSender
- IGetCommandUsage
- ICommandExecute
- IGetTabCompletion
- CommandUtils