import * as mc from "@minecraft/server";
import { highlightBlock, itemManager } from "../sgs_cake_lib";

export class miscBlocksManager {

    static onplaceOpenShelf(data) {
        const block = data.block;
        const below = block.below();

        if (below.isAir) block.setPermutation(block.permutation.withState('sgs_cake:lower', 1));
    }
}

mc.world.afterEvents.playerBreakBlock.subscribe((data) => {
    const { block } = data;
    if (block.above().hasTag("sgs_cake_open_shelf") && block.isAir) {
        block.above().setPermutation(block.above().permutation.withState('sgs_cake:lower', 1));
    }
});

mc.world.afterEvents.playerPlaceBlock.subscribe((data) => {
    const { block } = data;
    if (block.above().hasTag("sgs_cake_open_shelf") && !block.isAir) {
        block.above().setPermutation(block.above().permutation.withState('sgs_cake:lower', 0));
    }
});