import { world, } from "@minecraft/server";
import { namespace } from "../../../config/_config";
// VineBlock class handles the behavior of vine-like blocks that can connect when placed or change state when destroyed.
export class VarationBlock {
    constructor() {
        VarationBlock.initialize();
    }
    // Initialization method to register the custom vine block component and related events
    static initialize() {
        // Subscribe to the world initialization event to register the custom block component
        world.beforeEvents.worldInitialize.subscribe((event) => {
            event.blockComponentRegistry.registerCustomComponent(`${namespace}:variation`, {
                beforeOnPlayerPlace: (event) => {
                    this.onPlace(event);
                },
            });
        });
    }
    // Method to handle the behavior when a vine block is placed
    static onPlace(event) {
        // random state between from 1 to 4
        const state = Math.floor(Math.random() * 4) + 1;
        event.permutationToPlace = event.permutationToPlace.withState(`${namespace}:variation`, state);
    }
}
