KubeJS-Mods / KubeJS

https://kubejs.com
GNU Lesser General Public License v3.0
307 stars 90 forks source link

Add hurtEnemy callback to ItemBuilder (1.20.4) #819

Closed squoshi closed 5 months ago

squoshi commented 5 months ago

Description

Port of my other PR for the hurtEnemy callback to 1.20.4.

Example Script

StartupEvents.registry('item', event => {
    event.create('test')
        .hurtEnemy(ctx => {
        console.log([ctx.item, ctx.target, ctx.attacker])
        global.attackTest(ctx)
        return true
    })
})

global.attackTest = function(ctx) {
    let exp = ctx.target.level.createExplosion(ctx.target.x, ctx.target.y + 1, ctx.target.z)
    exp.strength(1.25)
    exp.explode()
}

Other details