import * as mc from "@minecraft/server";
import * as utils from "../../utils/index";
export class MobEffectResistanceComponent extends utils.ActorComponent {
    constructor() {
        super(...arguments);
        this.effectBinding = this.onEffectAdded.bind(this);
    }
    onComponentAdded() {
        mc.world.afterEvents.effectAdd.subscribe(this.effectBinding, { entities: [this.actor.UnsafeEntity] });
    }
    onComponentRemoved() {
        mc.world.afterEvents.effectAdd.unsubscribe(this.effectBinding);
    }
    onEffectAdded(event) {
        const exeption = this.options.exceptions[event.effect.typeId];
        if (!exeption || !exeption()) {
            this.actor.removeEffect(event.effect.typeId);
        }
        else {
            utils.mclog(`Not clearing ${event.effect.displayName} from ${this.actor.ActorId} as it was a valid exception`, this.id);
        }
    }
}
