var _a;
import * as utils from "../../utils/index";
import { ComponentCompanion } from "../../npc/components/base";
export class PowderedSnowComponent extends ComponentCompanion {
    async onComponentAdded(npc) {
        var _b;
        super.onComponentAdded(npc);
        utils.waitForLoopEvent(40, () => {
            if (npc.Entity.isValid()) {
                this.snapToSurface(npc);
                return false;
            }
            return true;
        }, ((_b = this.npc) === null || _b === void 0 ? void 0 : _b.ID) + this.id);
    }
    async onComponentRemoved(npc) {
        var _b;
        utils.abortEvents(((_b = this.npc) === null || _b === void 0 ? void 0 : _b.ID) + this.id);
    }
    snapToSurface(npc) {
        try {
            const origin = npc.Entity.dimension.getBlock(npc.Entity.location);
            const above = npc.Entity.dimension.getBlock(npc.Entity.location.up());
            if ((origin === null || origin === void 0 ? void 0 : origin.permutation.matches("minecraft:powder_snow")) && (above === null || above === void 0 ? void 0 : above.permutation.matches("minecraft:air"))) {
                npc.Entity.teleport(npc.Entity.location.up());
            }
        }
        catch (error) { }
    }
}
_a = PowderedSnowComponent;
PowderedSnowComponent.ComponentId = _a.name;
