event

the event parameter passed into any @Katton.listen(...) handler. its exact set of available properties depends on which event fired, see event list & properties for the full breakdown

properties (availability varies by event)

event.player // a `player` value, where applicable
event.item // a `item` value, where applicable
event.block // the block's material name as a string, where applicable
event.entity // the entity's type name as a string, where applicable
event.projectile // the projectile's name as a string, where applicable

methods

event.cancel()

cancels the actual action (if the event supports cancellation). returns true if it actually cancelled something, false if the event isn't cancellable (safe to call either way). more details on cancelling events

event.clearDrops()

this clears the drops from when a player dies

event.item is a full item, not just a name

unlike event.block/event.entity/event.projectile (which are just strings), event.item gives you a real item value with all its methods available:

@Katton.listen("player_rightclick")
function onRightClick(event) {
    val item = event.item
    if (item == null) {
        return // player right clicked with an empty hand
    }

    val ability = item.getTag("ability")
    if (ability == "leap_wand") {
        event.player.launchForward(horizontal = 1.8, vertical = 0.65)
    } else if (ability == "heal_wand") {
        event.player.health = 20
    }
}

always check for null on optional properties

@Katton.listen("player_interact")
function onInteract(event) {
    // event.item can be null (empty hand), event.block can be null (clicking air)
    if (event.item != null) {
        Katton.log.info("Holding: " + event.item.getTag("ability"))
    }
}