import * as mc from "@minecraft/server"
const { world, system } = mc;

system.beforeEvents.startup.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent("bnc:rotation", {
        beforeOnPlayerPlace: result => {
            let direction = 0;
            try {
                let rotationAngle = result.player.getRotation().y;
                direction = rotationAngle >= -45 && rotationAngle < 45 ? 3 :
                    rotationAngle >= 45 && rotationAngle < 135 ? 4 :
                        rotationAngle >= -135 && rotationAngle < -45 ? 5 : 2;
            } catch (e) {
                // Можно добавить логирование, если нужно
            }
            let state = result.block.permutation.getAllStates();
            state["block:rotation"] = direction;
            result.permutationToPlace = mc.BlockPermutation.resolve(result.permutationToPlace.type.id, state);
        }
    });
}); 