import { system, ItemStack } from "@minecraft/server";
import { healableItems, healableEntities } from "../DATA/Config";
import * as Vector3Utils from "../U/Vector3Utils";
import { itemLoreConfig } from "../DATA/LoreConfig";
const maxFoodItems = 20;
function getHealAmount(entityId, item) {
    return healableEntities.has(entityId) ? healableItems.get(item) : undefined;
}
export function feedMount(sourceEntity, entityLocation, entityId, log) {
    const healthComponent = sourceEntity.getComponent("health");
    const healItem = sourceEntity.getProperty("kicu_mmad:food_item");
    const healInfo = getHealAmount(entityId, healItem);
    if (healthComponent && healInfo) {
        const healAmount = healInfo.healAmount;
        const isSpecial = healInfo.isSpecial;
        let foodCounter = sourceEntity.getProperty("kicu_mmad:food_counter");
        if (isSpecial) {
            foodCounter = maxFoodItems;
        }
        else {
            foodCounter = Math.min(foodCounter + 1, maxFoodItems);
        }
        sourceEntity.setProperty("kicu_mmad:food_counter", foodCounter);
        sourceEntity.runCommandAsync("playsound mob.horse.eat @a[r=16] ~ ~ ~");
        let entityNewHealth = healthComponent.currentValue + healAmount;
        let entityMaxHealth = healthComponent.effectiveMax;
        entityNewHealth = Math.min(entityNewHealth, entityMaxHealth);
        if (entityNewHealth === entityMaxHealth) {
            sourceEntity.dimension.spawnParticle(`kicu_mmad:full_health_particle`, entityLocation);
        }
        system.run(() => {
            healthComponent.setCurrentValue(entityNewHealth);
            if (foodCounter === maxFoodItems) {
                sourceEntity.dimension.spawnParticle(`kicu_mmad:feeding_success`, entityLocation);
                foodCounter = 0;
                sourceEntity.setProperty("kicu_mmad:food_counter", foodCounter);
                const itemId = "kicu_mmad:mythic_material";
                const mythic_material = new ItemStack(itemId, 1);
                mythic_material.setLore(itemLoreConfig[itemId]);
                const itemLocation = Vector3Utils.add(sourceEntity.location, sourceEntity.getViewDirection());
                sourceEntity.dimension.spawnItem(mythic_material, itemLocation);
            }
            else {
                sourceEntity.dimension.spawnParticle(`kicu_mmad:feeding`, entityLocation);
            }
        });
    }
}

//# sourceMappingURL=../../../../../_KiCuMountsBPDebug/kicu/mmad/C/Feeding.js.map
