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

//anemo passive: knocks the enemy back when the pet is hit
world.afterEvents.entityHurt.subscribe(e => {
    const damager = e.damageSource.damagingEntity;
    const anemo = e.hurtEntity;

    if (!(anemo && anemo.typeId == "oct_eg:anemo_pet") || e.damageSource.cause != EntityDamageCause.entityAttack) return;

    try {
        anemo.dimension.spawnParticle("oct_eg:double_jump.dots", anemo.location);
        damager.applyKnockback(-damager.getViewDirection().x, -damager.getViewDirection().z, 2, 0.3);
    } catch (e) {
        //console.warn("Entity has no view direction.");
    }


}, { entityTypes: ["oct_eg:anemo_pet"] });