import { Player, world } from "@minecraft/server";

/**
 * 
 * @param {Player} player 
 */
export function randomOrePickaxe(player) {
    const cast = player.getBlockFromViewDirection({ maxDistance: 7, includeLiquidBlocks: true, includePassableBlocks: true })
    if (cast) {
        const block = cast.block
        const perm = block.permutation
        const loc = block.location
        if (perm.matches("stone")) {
            const ore = stoneOres[Math.floor(Math.random() * stoneOres.length)]
            player.dimension.runCommand(`/setblock ${loc.x} ${loc.y} ${loc.z} ${ore}`)
        }
        else if (perm.matches("deepslate")) {
            const ore = deepslateOres[Math.floor(Math.random() * deepslateOres.length)]
            player.dimension.runCommand(`/setblock ${loc.x} ${loc.y} ${loc.z} ${ore}`)
        }
    }
}

const stoneOres = [
    "coal_ore",
    "iron_ore",
    "gold_ore",
    "diamond_ore",
    "emerald_ore",
    "redstone_ore",
    "lapis_ore",
    "quartz_ore",
    //"ancient_debris",
    "copper_ore"
]

const deepslateOres = [
    "deepslate_coal_ore",
    "deepslate_iron_ore",
    "deepslate_gold_ore",
    "deepslate_diamond_ore",
    "deepslate_emerald_ore",
    "deepslate_redstone_ore",
    "deepslate_lapis_ore",
    "deepslate_copper_ore"
]