let $IronsSpellbooksUtils = Java.loadClass("io.redspace.ironsspellbooks.api.util.Utils")
let lasershoot = "com.github.L_Ender.cataclysm.entity.InternalAnimationMonster.The_Prowler_Entity$Lasershoot"

/** @param {Internal.BeeEntityJS} mob */
function counterBeam(mob) {
    let laserfound = 0
    mob.goalSelector.runningGoals.forEach(g => {
        if (g.goal.class.name.toString() == lasershoot) {
            let t = mob.target
            if (!t) return

            if (mob.persistentData[`laserstart`] == 0) {
                    mob.server.runCommandSilent(`particle minecells:explosion ${mob.x} ${mob.y + 3} ${mob.z} 0 0 0 1 1 normal`)
                    mob.server.runCommandSilent(`playsound minecells:shocker.charge hostile @a ${mob.x} ${mob.y} ${mob.z}`)
                    mob.server.runCommandSilent(`effect give @p minecraft:speed 3 3`)
            }
            mob.persistentData[`laserstart`] = 1
            laserfound = 1
        }
    })
    if (laserfound == 0) {
        mob.persistentData[`laserstart`] = 0
    }
}

EntityJSEvents.addGoalSelectors("cataclysm:the_prowler", event => {
    let entity = event.entity

    if (!entity.server) { return }

    event.customGoal(
        'counterLaser',
        2,
        mob => true, // mob.target != null && mob.hasLineOfSight(mob.target),
        mob => true, // mob.target != null && mob.hasLineOfSight(mob.target),
        true,
        mob => { },
        mob => { },
        true,
        mob => {
            try {
                counterBeam(mob)
            } catch (error) {
                console.log(error)
            }
        }
    )
}
)

