import { world, system, EquipmentSlot} from "@minecraft/server";
import * as utils from "../utils";
export async function onEntityHurt(event) {
    const source = event.damageSource.damagingEntity;
    const entity = event.hurtEntity;
    if (source?.typeId === "minecraft:player") {
        const equippable = source.getComponent('equippable');
        if (!equippable) return;
        const mainhand = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (mainhand?.typeId === 'pu_sg:katana') {
            if(entity.isValid()){
                const dimension = entity.dimension;
                dimension.spawnParticle("pu_sg:katana_1", {x: source.location.x, y: source.location.y + 1, z: source.location.z});
                dimension.spawnParticle("pu_sg:katana_2", {x: entity.location.x, y: entity.location.y + 1, z: entity.location.z});
                dimension.playSound("pu_sg:katana_attack", entity.location);
            }
        }
    }
}