import * as mc from "@minecraft/server";
import * as utils from "../../utils/index";
import { WornHat } from "../worn_hat";
class MohawkHat extends WornHat {
    constructor() {
        super(...arguments);
        this.hatTypeId = "ldz_crcomp:hat_mohawk";
        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;
        if (((_a = event.damageSource.damagingEntity) === null || _a === void 0 ? void 0 : _a.id) === this.hatWearer.Entity.id) {
            if (event.hurtEntity.isValid()) {
                const victim = new utils.SafetyCheckedEntity(event.hurtEntity);
                const direction = victim.location.subtract(this.hatWearer.Entity.location).normalize();
                victim.applyKnockback(direction.x, direction.z, 2, 0.6);
            }
        }
    }
}
WornHat.HatTable["ldz_crcomp:hat_mohawk"] = MohawkHat;
