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

//on entitiy hit by the pet's projectiles
world.afterEvents.entityHurt.subscribe(e => {
    const pet = e.damageSource?.damagingEntity?.typeId;
    const hurt = e.hurtEntity;
    switch (pet) {
        case "oct_eg:pyro_pet":
            e.hurtEntity.dimension.spawnParticle("oct_eg:fiery_punch.stage2explosion", e.hurtEntity.location);
            e.hurtEntity.setOnFire(3*20);
            break;
        case "oct_eg:necro_pet":
            e.hurtEntity.dimension.spawnParticle("oct_eg:putrid_ribs.smoke", e.hurtEntity.location);
            e.hurtEntity.dimension.spawnParticle("oct_eg:putrid_ribs.souls", e.hurtEntity.location);
            break;
        case "oct_eg:ender_pet":
            e.hurtEntity.dimension.spawnParticle("oct_eg:shulker_bullet.explosion", e.hurtEntity.location);
            break;
        case "oct_eg:hydro_pet":
            e.hurtEntity.dimension.spawnParticle("oct_eg:hydro_pet.splash", e.hurtEntity.location);
            e.hurtEntity.addEffect("minecraft:slowness",3*20,{amplifier:1});
            break;
        case "oct_eg:anemo_pet":
            //I could not get the pet (projectile's owner) using the projectile component
            const pet = hurt.dimension.getEntities({ closest: 1, location: hurt.location, type: "oct_eg:anemo_pet" })[0];
            e.hurtEntity.applyKnockback(pet.getViewDirection().x, pet.getViewDirection().z, 5, 0.5);
            e.hurtEntity.dimension.spawnParticle("oct_eg:double_jump.start", e.hurtEntity.location);
            break;
        default:
            break;
    }

})
