import { world } from "@minecraft/server";
import { namespace } from "../../../config/_config";
// PreventInWaterBlock class prevents blocks from being placed in water.
export class PreventInWaterBlock {
    constructor() {
        PreventInWaterBlock.initialize();
    }
    // Initialization method to register the custom component that prevents block placement in water
    static initialize() {
        world.beforeEvents.worldInitialize.subscribe((event) => {
            event.blockComponentRegistry.registerCustomComponent(`${namespace}:not_in_water`, {
                // Handle the event before a player places a block
                beforeOnPlayerPlace: (event) => {
                    this.checkBlock(event);
                },
            });
        });
    }
    // Method to check if the block the player is placing is on water, and cancel the placement if so
    static checkBlock(event) {
        const { block } = event; // Get the block where the player is trying to place another block
        if (!block)
            return; // Exit if no block is found
        // If the block is water, cancel the placement event
        if (block.typeId === "minecraft:water") {
            event.cancel = true; // Prevent the block from being placed in water
        }
    }
}
