import { Block, Dimension, ItemStack, system, world } from "@minecraft/server";
import { randomBetween } from "../../util/random";

/**
 * 
 * @param {Block} block 
 * @param {Dimension} dimension 
 */
export function superFortunePickaxe(block, dimension) {
    const [count, itemId] = getOreType(block)
    if (count == 0) {
        return
    }

    const random = randomBetween(100, 200)
    const itemCount = Math.floor(count * random)
    system.run(() => {
        dimension.spawnItem(new ItemStack(itemId, itemCount), block.center())
    })
}

/**
 * 
 * @param {Block} block 
 * @returns {[number, string]}
 */
export function getOreType(block) {
    for (const [id, [count, itemId]] of oreTypes) {
        if (block.typeId == id) {
            return [count, itemId];
        }
    }
    return [0, "stone"];
}

const oreTypes = new Map([
    ["minecraft:coal_ore", [1, "coal"]],
    ["minecraft:deepslate_coal_ore", [1, "coal"]],
    ["minecraft:iron_ore", [1, "iron_ingot"]],
    ["minecraft:deepslate_iron_ore", [1, "iron_ingot"]],
    ["minecraft:gold_ore", [1, "gold_ingot"]],
    ["minecraft:deepslate_gold_ore", [1, "gold_ingot"]],
    ["minecraft:redstone_ore", [5, "redstone"]],
    ["minecraft:lit_redstone_ore", [5, "redstone"]],
    ["minecraft:deepslate_redstone_ore", [5, "redstone"]],
    ["minecraft:lit_deepslate_redstone_ore", [5, "redstone"]],
    ["minecraft:lapis_ore", [8, "lapis_lazuli"]],
    ["minecraft:deepslate_lapis_ore", [8, "lapis_lazuli"]],
    ["minecraft:diamond_ore", [1, "diamond"]],
    ["minecraft:deepslate_diamond_ore", [1, "diamond"]],
    ["minecraft:emerald_ore", [1, "emerald"]],
    ["minecraft:deepslate_emerald_ore", [1, "emerald"]],
    ["minecraft:quartz_ore", [1, "quartz"]],
    ["minecraft:ancient_debris", [1, "netherite_scrap"]],
    ["minecraft:nether_gold_ore", [1, "gold_nugget"]],
    ["minecraft:copper_ore", [4, "copper_ingot"]]
]);

