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

export class stoveManager {

    static beforeplace(data) {
        const block = data.block;
        const below = block.below();
        if (below.hasTag("sgs_farm_stove_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_stove_pot") below.setPermutation(below.permutation.withState('sgs_farm:crafting_station', 1));
            if (data.permutationToPlace.type.id == "sgs_farm:fun_stove_pan") below.setPermutation(below.permutation.withState('sgs_farm:crafting_station', 2));
            if (data.permutationToPlace.type.id == "sgs_farm:fun_stove_oven") below.setPermutation(below.permutation.withState('sgs_farm:crafting_station', 3));

            highlightBlock(block);
            highlightBlock(below);

            block.dimension.playSound("block.campfire.crackle", block.location);
        }
    }

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