import * as utils from "../../utils/index";
import { WornHat } from "../worn_hat";
class CowboyHat extends WornHat {
    constructor() {
        super(...arguments);
        this.hatTypeId = "ldz_crcomp:hat_cowboy";
    }
    async onEquip() {
        const wearer = this.hatWearer.Entity;
        utils.waitForLoopEvent(40, () => {
            if (wearer.isValid()) {
                const cowQuery = { location: wearer.location, maxDistance: 16, type: "minecraft:cow" };
                const horseQuery = { location: wearer.location, maxDistance: 16, type: "minecraft:horse" };
                if (wearer.dimension.getEntities(cowQuery).length || wearer.dimension.getEntities(horseQuery).length) {
                    if (!wearer.getEffect("regeneration"))
                        wearer.addEffect("regeneration", 200, { showParticles: false });
                }
                else {
                    wearer.removeEffect("regeneration");
                }
            }
            return false;
        }, this.cancelCategory);
    }
    async onUnequip() {
        utils.abortEvents(this.cancelCategory);
    }
}
WornHat.HatTable["ldz_crcomp:hat_cowboy"] = CowboyHat;
