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

export class stoveManager {

    static onplace(data) {
        const block = data.block;
        const above = block.above();

        if (above.hasTag("sgs_cake_stove_top")) {
            above.setPermutation(above.permutation.withState('sgs_cake:can_craft', 1));

            highlightBlock(block);
            highlightBlock(above);
            return;
        }

        if (above.type.id == "sgs_farm:fun_stove_pot" || above.type.id == "sgs_farm:fun_stove_pan" || above.type.id == "sgs_farm:fun_stove_oven") {
            above.setPermutation(above.permutation.withState('sgs_farm:can_craft', 1));

            if (above.type.id == "sgs_farm:fun_stove_pot") block.setPermutation(block.permutation.withState('sgs_farm:crafting_station', 1)); //farm pot
            if (above.type.id == "sgs_farm:fun_stove_pan") block.setPermutation(block.permutation.withState('sgs_farm:crafting_station', 2)); //farm pan
            if (above.type.id == "sgs_farm:fun_stove_oven") block.setPermutation(block.permutation.withState('sgs_farm:crafting_station', 3)); //farm oven

            highlightBlock(block);
            highlightBlock(above);
        }
    }

    static destroy(data) {
        const block = data.block;
        const above = block.above();
        if (above.hasTag("sgs_cake_stove_top")) {
            above.setPermutation(above.permutation.withState('sgs_cake:can_craft', 0));
        }
        if (above.type.id == "sgs_farm:fun_stove_pot" || above.type.id == "sgs_farm:fun_stove_pan" || above.type.id == "sgs_farm:fun_stove_oven") {
            above.setPermutation(above.permutation.withState('sgs_farm:can_craft', 0));
        }
    }
}