import { EntityEquippableComponent, EquipmentSlot } from "@minecraft/server";
import { hasTag } from "../../functions"


export default {
    async execute(data) {
        const { item, player, attackedEntity, damage } = data; 

        if (!hasTag(item, "true:is_spear")) return;
        const equipmentComponent = player.getComponent(EntityEquippableComponent.componentId);
        const offHand = equipmentComponent.getEquipment(EquipmentSlot.Offhand);
        if (offHand) return;
        
        attackedEntity.applyDamage(damage * 0.5);

    }
}

