IEventManager

The IEventManager is what you’re gonna need when dealing with event handlers.

Importing the class

It might be required for you to import the class if you encounter any issues.
import crafttweaker.events.IEventManager;

Calling the event manager

You can access the event manager using the global events field

How do events work?

You can add a function that represents the event and from there on you can decide what you want CrT to do if such an event occurs.
The most important thing to remember is that you need to CAST THE EVENT TO IT’S TYPE! as otherwise you will not be able to access any if it’s ZenGetters.
If you simply want to print something where you don’t need to access the event, then it’s fine.

events.onPlayerCrafted(function(event as crafttweaker.event.PlayerCraftedEvent){
    print("event".length);
    print(event.player.name);
    event.player.xp += 1;
});


events.onPlayerLoggedIn(function(event) {
    //event instanceof Object -> No way of accessing it, so better cast!
    print("SOMEONE HAS LOGGED IN!!!");
});

What events are available?

The ZenMethods would be what you’ll need to call on events, the Event Class would be what you need to cast the event as.

ZenMethod Event Class
onBlockBreak crafttweaker.event.BlockBreak
onBlockHarvestDrops crafttweaker.event.BlockHarvestDrops
onEnderTeleport crafttweaker.event.EnderTeleportEvent
onEntityLivingAttacked crafttweaker.event.EntityLivingAttackedEvent
onEntityLivingDeath crafttweaker.event.EntityLivingDeathEvent
onEntityLivingDeathDrops crafttweaker.event.EntityLivingDeathDropsEvent
onEntityLivingFall crafttweaker.event.EntityLivingFallEvent
onEntityLivingHurt crafttweaker.event.EntityLivingHurtEvent
onEntityLivingJump crafttweaker.event.EntityLivingJumpEvent
onEntityLivingUseItem crafttweaker.event.EntityLivingUseItemEvent.All
onEntityLivingUseItemFinish crafttweaker.event.EntityLivingUseItemEvent.Finish
onEntityLivingUseItemStart crafttweaker.event.EntityLivingUseItemEvent.Start
onEntityLivingUseItemStop crafttweaker.event.EntityLivingUseItemEvent.Stop
onEntityLivingUseItemTick crafttweaker.event.EntityLivingUseItemEvent.Tick
onEntityStruckByLightning crafttweaker.event.EntityStruckByLightningEvent
onItemExpire crafttweaker.event.ItemExpireEvent
onItemToss crafttweaker.event.ItemTossEvent
onPlayerAnvilRepair crafttweaker.event.PlayerAnvilRepair
onPlayerAttackEntity crafttweaker.event.PlayerAttackEntityEvent
onPlayerBonemeal crafttweaker.event.PlayerBonemealEvent
onPlayerBreakSpeed crafttweaker.event.PlayerBreakSpeed
onPlayerBrewedPotion crafttweaker.event.PlayerBrewedPotion
onPlayerChangedDimension crafttweaker.event.PlayerChangedDimensionEvent
onPlayerCrafted crafttweaker.event.PlayerCraftedEvent
onPlayerDeathDrops crafttweaker.event.PlayerDeathDropsEvent
onPlayerDestroyItem crafttweaker.event.PlayerDestroyItem
onPlayerFillBucket crafttweaker.event.PlayerFillBucketEvent
onPlayerInteract crafttweaker.event.PlayerInteractEvent
onPlayerInteractBlock crafttweaker.event.PlayerInteractBlockEvent
onPlayerInteractEntity crafttweaker.event.PlayerInteractEntityEvent
onPlayerLoggedIn crafttweaker.event.PlayerLoggedInEvent
onPlayerLoggedOut crafttweaker.event.PlayerLoggedOutEvent
onPlayerOpenContainer crafttweaker.event.PlayerOpenContainerEvent
onPlayerPickupItem crafttweaker.event.PlayerPickupItemEvent
onPlayerPickupXp crafttweaker.event.PlayerPickupXpEvent
onPlayerRespawn crafttweaker.event.PlayerRespawnEvent
onPlayerSetSpawn crafttweaker.event.PlayerSetSpawn
onPlayerSleepInBed crafttweaker.event.PlayerSleepInBedEvent
onPlayerSmelted crafttweaker.event.PlayerSmeltedEvent
onPlayerTick crafttweaker.event.PlayerTick
onPlayerUseHoe crafttweaker.event.PlayerUseHoeEvent

Clear all event handlers

events.clear();