import { world, BlockPermutation, system } from "@minecraft/server";

system.beforeEvents.startup.subscribe((initEvent) => {
    initEvent.blockComponentRegistry.registerCustomComponent("rustic:farmland_place", {
        beforeOnPlayerPlace: e => {
            const { player, block, face, permutationToPlace, dimension } = e
            const blockBelow = block.below()

            if (blockBelow.typeId === "minecraft:farmland") {
                const permutation = BlockPermutation.resolve(permutationToPlace.type.id,{"r:farmland": true})
                e.permutationToPlace = permutation
            }
            else{
                return
            }
        }
    });
});