import * as mc from "@minecraft/server";
import { WornHat } from "../worn_hat";
class ConductorHat extends WornHat {
    constructor() {
        super(...arguments);
        this.hatTypeId = "ldz_crcomp:hat_conductor";
        this.onHurtEvent = this.onHurt.bind(this);
    }
    async onEquip() {
        mc.world.afterEvents.entityHurt.subscribe(this.onHurtEvent, { entities: [this.hatWearer.Entity.UnsafeEntity] });
    }
    async onUnequip() {
        mc.world.afterEvents.entityHurt.unsubscribe(this.onHurtEvent);
    }
    onHurt(event) {
        var _a;
        if (event.damageSource.cause === mc.EntityDamageCause.entityAttack && ((_a = event.damageSource.damagingEntity) === null || _a === void 0 ? void 0 : _a.isValid())) {
            event.damageSource.damagingEntity.applyDamage(event.damage * 0.5, { cause: mc.EntityDamageCause.thorns });
        }
    }
}
WornHat.HatTable["ldz_crcomp:hat_conductor"] = ConductorHat;
