import * as mc from "@minecraft/server";
import { highlightBlock } from "../sgs_farm_lib";

export class preptableManager {

    static beforeplace(data) {
        const block = data.block;
        const below = block.below();
        if (below.hasTag("sgs_farm_preptable_base")) {
            data.permutationToPlace = mc.BlockPermutation.resolve(data.permutationToPlace.type.id, { 'sgs_farm:can_craft': 1, "minecraft:cardinal_direction": data.permutationToPlace.getState("minecraft:cardinal_direction") });

            if (data.permutationToPlace.type.id == "sgs_farm:fun_chop_board") below.setPermutation(below.permutation.withState('sgs_farm:crafting_station', 1));

            highlightBlock(block);
            highlightBlock(below);
        }
    }

    static destroy(data) {
        const block = data.block;
        const below = block.below();
        if (below.hasTag("sgs_farm_preptable_base")) {
            below.setPermutation(below.permutation.withState('sgs_farm:crafting_station', 0));
        }
    }
}