import { world } from "@minecraft/server";
import { namespace } from "../../../config/_config";
export class InteractBlock {
    constructor(config) {
        this.config = config;
    }
    static registerBehavior(config) {
        const block = new InteractBlock(config);
        this.blocks.push(block);
    }
    static initialize() {
        world.beforeEvents.worldInitialize.subscribe((event) => {
            event.blockComponentRegistry.registerCustomComponent(`${namespace}:interact`, {
                onPlayerInteract: (event) => {
                    this.interactBlock(event);
                },
            });
        });
    }
    static interactBlock(event) {
        const block = event.block;
        const interactBlock = InteractBlock.blocks.find((block) => block.config.id === event.block.typeId);
        if (!event.player)
            return;
        if (interactBlock) {
            interactBlock.config.action(block, event.player);
        }
    }
}
InteractBlock.blocks = [];
