import { system, world } from "@minecraft/server";
export class InWaterBlock {
    constructor(config) {
        this.config = config;
    }
    static registerBehavior(config) {
        const block = new InWaterBlock(config);
        this.blocks.push(block);
    }
    // Method to get a InWaterBlocks by its id
    static getBlock(id) {
        return InWaterBlock.blocks.find((block) => block.config.id === id);
    }
    static initialize() {
        world.beforeEvents.itemUseOn.subscribe((event) => {
            const registeredBlock = InWaterBlock.getBlock(event.itemStack.typeId);
            if (!registeredBlock)
                return;
            if (event.block.below()?.typeId !== "minecraft:dirt") {
                world.sendMessage("You can only place blocks on dirt!");
                event.cancel = true;
                return;
            }
            if (event.block.typeId !== "minecraft:water")
                return;
            system.runTimeout(() => {
                event.block.above()?.setType(registeredBlock.config.id);
                if (registeredBlock.config.sound)
                    world.playSound(registeredBlock.config.sound, event.block.location);
            }, 1);
        });
    }
}
InWaterBlock.blocks = [];
