import { world } from "@minecraft/server";

world.afterEvents.entityHurt.subscribe(ev => {
    if (ev.damageSource.cause == "entityAttack" && ev.damageSource.damagingEntity.typeId == "minecraft:player") {
        const selectedItem = ev.damageSource.damagingEntity.getComponent("minecraft:inventory").container.getItem(ev.damageSource.damagingEntity.selectedSlotIndex);
        if (selectedItem?.typeId == "fiery:ender_claymore") {
            const attackerHealth = ev.damageSource.damagingEntity.getComponent("minecraft:health");
            attackerHealth.setCurrentValue(attackerHealth.currentValue + ev.damage * 0.4);
            ev.hurtEntity.runCommandAsync("particle fiery:dragon_egg ~ ~ ~");
        }
    }
});