import * as utils from "../../utils/index";
import { ComponentCompanion } from "./base";
export class PlayerInteract extends ComponentCompanion {
    constructor(interact = () => { var _a; utils.mclog(`${(_a = this.npc) === null || _a === void 0 ? void 0 : _a.ID} Interact`); }) {
        super();
        this.eventBinding = this.onInteract.bind(this);
        this.interact = interact;
    }
    async onComponentAdded(npc) {
        super.onComponentAdded(npc);
        utils.afterEvents.onInteractWithEntity.subscribe(this.eventBinding);
    }
    async onComponentRemoved(npc) {
        utils.afterEvents.onInteractWithEntity.unsubscribe(this.eventBinding);
    }
    onInteract(event) {
        var _a;
        if (event.victim.id === ((_a = this.npc) === null || _a === void 0 ? void 0 : _a.ID)) {
            this.interact(event.player);
        }
    }
}
