import * as mc from "@minecraft/server";
import { ComponentNPC } from "./base";
export class OnEntityDeathEventComponent extends ComponentNPC {
    constructor(options) {
        super();
        this.eventBinding = this.onDeath.bind(this);
        this.deathFilters = [];
        this.options = options !== null && options !== void 0 ? options : {};
    }
    async onComponentAdded(npc) {
        super.onComponentAdded(npc);
        mc.world.afterEvents.entityDie.subscribe(this.eventBinding, this.options);
    }
    async onComponentRemoved(npc) {
        mc.world.afterEvents.entityDie.unsubscribe(this.eventBinding);
    }
    onDeath(event) {
        for (const deathFilter of this.deathFilters) {
            if (deathFilter.filter(event)) {
                deathFilter.event(event);
            }
        }
    }
}
