KubeJS-Mods / KubeJS

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

Add hurtEnemy callback to ItemBuilder #812

Closed squoshi closed 6 months ago

squoshi commented 6 months ago

Description

This fix adds the hurtEnemy callback from the Item class into ItemBuilder. It will make making items with attack effects much easier.

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.damagesTerrain(false)
    exp.strength(1.25)
    exp.explode()
}

Other details

No other details

squoshi commented 6 months ago

Oops, code formatting kinda broke