import { world } from "@minecraft/server";
import Random from "../_Utilities/Random";
import Biome_Manager from "../Biome/Biome_Manager";
import Progression_Manager from "../Progression/Progression_Manager";
import Form_Upgrade_Manager from "../Form/Managers/Form_Upgrade_Manager";
import { MinecraftBlockTypes } from "../_Utilities/vanilla-data/mojang-block";
export default class Block_Manager {
    static hit(player, block, permutation) {
        const progression = Progression_Manager.get("07b1d6ae-6288-4d5c-93fb-d10737e6f2c0");
        if (player.isSneaking &&
            block.location.x == progression.location.x &&
            block.location.y == progression.location.y &&
            block.location.z == progression.location.z) {
            Form_Upgrade_Manager.load(player);
        }
    }
    static interact(player, block) {
        const progression = Progression_Manager.get("07b1d6ae-6288-4d5c-93fb-d10737e6f2c0");
        if (block.location.x == progression.location.x &&
            block.location.y == progression.location.y &&
            block.location.z == progression.location.z) {
            Form_Upgrade_Manager.load(player);
        }
    }
    static break(player, block, permutation) {
        const generator = Progression_Manager.get("07b1d6ae-6288-4d5c-93fb-d10737e6f2c0");
        const gen_Location = generator.location;
        const location = block.location;
        if (gen_Location.x != location.x || gen_Location.y != location.y || gen_Location.z != location.z)
            return;
        const drop = Random.integer(1, 100);
        if (drop <= generator.drop_Rate)
            player.dimension.spawnItem(permutation.getItemStack(), { x: location.x, y: location.y + 1, z: location.z });
        this.generator(player, block.location);
    }
    static get_Block(dimension_ID, location) {
        return world.getDimension(dimension_ID).getBlock(location);
    }
    static set_Block(dimension_ID, location, block_ID) {
        world.getDimension(dimension_ID).setBlockType(location, block_ID);
        return this.get_Block(dimension_ID, location);
    }
    static generator(player, location) {
        const progression = Progression_Manager.get("07b1d6ae-6288-4d5c-93fb-d10737e6f2c0");
        const gen_Location = progression.location;
        if (gen_Location.x != location.x || gen_Location.y != location.y || gen_Location.z != location.z)
            return;
        const dimension_ID = player.dimension.id;
        const biome_ID = progression.biome_IDs[Random.integer(0, progression.biome_IDs.length - 1)];
        const biome = Biome_Manager.get(biome_ID);
        const index = Random.probability(biome.blocks);
        progression.blocks_Mined++;
        Progression_Manager.set(progression);
        if (index == undefined)
            return;
        const block_ID = biome.blocks[index].id;
        try {
            this.set_Block(dimension_ID, progression.location, block_ID);
        }
        catch (error) {
            this.set_Block(dimension_ID, progression.location, MinecraftBlockTypes.Dirt);
        }
    }
}
