import * as mc from "@minecraft/server";
import * as utils from "../../utils/index";
import { WornHat } from "../worn_hat";
class ArrowHat extends WornHat {
    constructor() {
        super(...arguments);
        this.hatTypeId = "ldz_crcomp:hat_arrow_head";
        this.onHurtEvent = this.onHurt.bind(this);
    }
    async onEquip() {
        mc.world.afterEvents.entityHurt.subscribe(this.onHurtEvent);
    }
    async onUnequip() {
        mc.world.afterEvents.entityHurt.unsubscribe(this.onHurtEvent);
    }
    onHurt(event) {
        var _a, _b;
        if (((_a = event.damageSource.damagingEntity) === null || _a === void 0 ? void 0 : _a.id) === this.hatWearer.Entity.id && event.damageSource.cause === mc.EntityDamageCause.projectile) {
            if (event.hurtEntity.isValid()) {
                utils.mclog("Applying extra arrow damage");
                const victim = new utils.SafetyCheckedEntity(event.hurtEntity);
                (_b = victim.Health) === null || _b === void 0 ? void 0 : _b.setCurrentValue(victim.Health.currentValue - 4);
            }
        }
    }
}
WornHat.HatTable["ldz_crcomp:hat_arrow_head"] = ArrowHat;
