import { world,system} from "@minecraft/server"

world.afterEvents.entityHurt.subscribe((ev) => {
    var victim = ev.hurtEntity
    var attacker = ev.damageSource.damagingEntity
    var projectile = ev.damageSource.damagingProjectile
    if (attacker != undefined){
        if (attacker.typeId === 'minecraft:player' && attacker.hasTag("explosive_blaze_rod") && victim.getComponent("minecraft:onfire")) {
            system.runTimeout(() => {
                var entities = victim.dimension.getEntities({
                    location: { x: victim.location.x, y: victim.location.y, z: victim.location.z },
                    maxDistance: 0.5,
                });
                victim.runCommand(`particle edx:blazeblade_explosion ~~1~`)
                for (let entity of entities) {
                    entity.applyDamage(5,{
                        cause: "fire" ,
                    },)
                    entity.applyKnockback(0,0,0,0.5);
                entity.extinguishFire()
                };
                
            },20)
        }
        }

    if (projectile != undefined && attacker != undefined){
    if (projectile.typeId === 'edx:fire_strike') {
        victim.setOnFire(4, true);
    }
    }

    
})

