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

// Snareling Web

world.afterEvents.entityHurt.subscribe((event) => {
    const hurtEntity = event.hurtEntity;
    const damageSource = event.damageSource.damagingEntity;
    const damageProjectile = event.damageSource.damagingProjectile;
    if (!damageSource || !damageProjectile) {
        return;
    }
    if (damageSource.typeId === "dungeons:snareling" && damageProjectile.typeId === "dungeons:snareling_ammo") {
        hurtEntity.runCommandAsync('function snareling_web')
    }
});

// Enchanted Sheep

world.afterEvents.entityHurt.subscribe((event) => {
    const damage = event.damage;
    const hurtEntity = event.hurtEntity;
    const damageSource = event.damageSource.damagingEntity;
    if (!damageSource) {
        return;
    }
    if (damageSource.typeId === "dungeons:enchanted_sheep") {

        //0 = red
        if (damageSource.hasTag('sheep_red')) {
            hurtEntity.setOnFire(damage * 2, true)
        }
        //1 = green
        if (damageSource.hasTag('sheep_green')) {
            hurtEntity.addEffect("poison", damage * 18, {
                amplifier: 1,
                showParticles: true
            });
        }
        //2 = blue
        if (damageSource.hasTag('sheep_blue')) {
            hurtEntity.addEffect("slowness", 80, {
                amplifier: damage,
                showParticles: true
            });
        }
    }
});

// Wretched Wraith Death Anim

world.afterEvents.entityDie.subscribe((event) => {
  const deadEntity = event.deadEntity;

  if (deadEntity.typeId === "dungeons:wretched_wraith") { 
deadEntity.runCommandAsync('summon dungeons:wretched_wraith_death ~~~ facing ~~~')
deadEntity.addEffect("invisibility", 80, {
                amplifier: 1,
                showParticles: false
            });
}


});