import { ItemStack, world } from "@minecraft/server";
import { nestHit } from "../C/Nest";
import { getArmorType } from "../U/ArmorUtility";
import { ArmorType } from "../DATA/ArmorConfig";
import { applyWitherEffectToAttacker } from "../A/ShadowPhoenixArmor";
import { applyFireEffectToAttacker } from "../A/PlainsArmour";
import { knockbackNearbyEnemies } from "../A/CockatriceArmour";
import { strikeLightningEffectOnAttacker } from "../A/PegasusArmour";
import { allMountIDs } from "../DATA/Config";
import { itemLoreConfig } from "../DATA/LoreConfig";
const eggIncubatorId = "kicu_mmad:egg_incubator_spawn_egg";
export function logNearbyEntityHealth(sourceEntity, range) {
    try {
        const nearbyEntities = sourceEntity.dimension.getEntities({
            location: sourceEntity.location,
            maxDistance: range,
        });
        if (!nearbyEntities || nearbyEntities.length === 0) {
            return;
        }
        let formattedOutput = "Nearby Entities Health Status:\n";
        nearbyEntities.forEach((entity) => {
            const healthComponent = entity.getComponent("health");
            const currentHealth = healthComponent?.currentValue ?? "N/A";
            const entityId = entity.typeId;
            formattedOutput += `- ID: ${entityId}, Health: ${currentHealth}\n`;
        });
        console.warn(formattedOutput);
    }
    catch { }
}
export function runEntityHitAfterEvent(log) {
    world.afterEvents.entityHitEntity.subscribe((event) => {
        try {
            const { damagingEntity, hitEntity } = event;
            const damEntityId = damagingEntity.typeId;
            const hitEntityId = hitEntity.typeId;
            if (allMountIDs.includes(hitEntityId)) {
                const mountEntity = hitEntity;
                const healthComponent = mountEntity.getComponent("health");
                if (healthComponent.currentValue <= 3) {
                    mountEntity.runCommandAsync("scriptevent kicu_mmad:mount_death ");
                }
            }
            if (damEntityId === "minecraft:player") {
                if (hitEntityId.startsWith("kicu_mmad:") && hitEntityId.endsWith("_nest")) {
                    nestHit(log, damagingEntity, hitEntity);
                }
                else if (hitEntityId === "kicu_mmad:egg_incubator") {
                    let hitCounter = hitEntity.getProperty("kicu_mmad:hitcount");
                    if (hitCounter < 4) {
                        hitCounter++;
                        hitEntity.runCommand("playanimation @s animation.kicu_mmad_damaged.generic");
                        if (hitCounter === 4) {
                            let dropItem = new ItemStack(eggIncubatorId);
                            dropItem.setLore(itemLoreConfig[eggIncubatorId]);
                            hitEntity.dimension.spawnItem(dropItem, hitEntity.location);
                            hitEntity.runCommand("playsound random.glass @a[r=16] ~ ~ ~ 1.0 1.0 1.0");
                            hitEntity.runCommand("fill ~ ~-1 ~ ~ ~2 ~ air replace kicu_mmad:egg_i_l_s_off");
                            hitEntity.runCommand("fill ~ ~-1 ~ ~ ~2 ~ air replace kicu_mmad:egg_i_l_s_on");
                            hitEntity.dimension.spawnParticle("kicu_mmad:egg_incubator_break", hitEntity.location);
                            hitEntity.triggerEvent("kicu_mmad:despawns");
                        }
                        else {
                            hitEntity.setProperty("kicu_mmad:hitcount", hitCounter);
                        }
                    }
                }
            }
            if (hitEntityId === "minecraft:player") {
                const armorType = getArmorType(hitEntity);
                if (armorType === ArmorType.ShadowPhoenix) {
                    applyWitherEffectToAttacker(log, damagingEntity);
                }
                if (armorType === ArmorType.PlainsDragon) {
                    applyFireEffectToAttacker(log, damagingEntity);
                }
                if (armorType === ArmorType.Cockatrice) {
                    knockbackNearbyEnemies(log, hitEntity, damagingEntity);
                }
                if (armorType === ArmorType.Pegasus) {
                    strikeLightningEffectOnAttacker(log, damagingEntity, hitEntity);
                }
            }
        }
        catch { }
    });
}

//# sourceMappingURL=../../../../../_KiCuMountsBPDebug/kicu/mmad/ESS/EntityHitEvent.js.map
