import { world, system, EquipmentSlot} from "@minecraft/server";
import * as utils from "../utils.js";
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:poison_sword') {
            if(entity.isValid()){
                utils.runEntityCommand(entity, "effect @s poison 5 1");
                source?.dimension.spawnParticle("pu_sg:poison_sword_1", {x: source?.location.x, y: source?.location.y + 1, z: source?.location.z});
                entity.dimension.spawnParticle("pu_sg:poison_sword_2", {x: entity.location.x, y: entity.location.y + 1, z: entity.location.z});
                entity.dimension.playSound("pu_sg:poisonous_sword_attack", entity.location);
            }
        }
    }
}