import * as mc from "@minecraft/server";
import * as blocklib from "../sgs_cake_block_lib";

const BLOCK_ENTITY = "sgs_cake:block_inventory";

export class blockInventoryManager {

    static onplace(data) {
        const block = data.block;
        const location = block.bottomCenter();

        const display_entity = mc.world.getDimension(block.dimension.id).spawnEntity(BLOCK_ENTITY, location);
        display_entity.nameTag = "§r";
        const direction = block.permutation.getState("minecraft:cardinal_direction");
        switch (direction) {
            case "north":
                display_entity.setProperty("sgs_cake:rotation", 0);
                break;
            case "east":
                display_entity.setProperty("sgs_cake:rotation", 1);
                break;
            case "south":
                display_entity.setProperty("sgs_cake:rotation", 2);
                break;
            case "west":
                display_entity.setProperty("sgs_cake:rotation", 3);
                break;
            default:
                break;
        }
    }

    //clean up connections made in case this block breaks
    static destroy(data) {
        const block = data.block;
        blocklib.clearDisplay(block);
    }
}
