import { Block, Dimension, Player, world } from "@minecraft/server";
import { namespace } from "../../namespace";

/**
 * 
 * @param {Block[]} blocks 
 * @param {Dimension} dimension 
 * @param {Player} player
 */
export function sortBlocksAndBreak(blocks, dimension, player) {
    if (player.getDynamicProperty(`${namespace}:in_tutorial`) == true) {
        blocks.filter(block => block.typeId == "minecraft:stone").forEach(block => {
            dimension.runCommandAsync(`fill ${block.location.x} ${block.location.y} ${block.location.z} ${block.location.x} ${block.location.y} ${block.location.z} air destroy`)
        })
    }
    else {
        blocks.filter(block => block.typeId.includes("stone") || block.typeId.includes("deepslate") || block.typeId.includes("ore") || block.typeId == "ancient_debris" || block.typeId.includes("quartz") ||
            block.typeId.includes("terracotta") || block.typeId.includes("blackstone") || block.typeId.includes("sandstone") || block.typeId.includes("prismarine") ||
            (block.typeId.includes("concrete") && !block.typeId.endsWith("powder")) || block.typeId == "mud_brick" || block.typeId.includes("nether_brick") || block.hasTag("stone") || block.typeId.includes("obsidian")
            || block.typeId.includes("tuff") || block.typeId.includes("ice") || block.typeId.includes("netherrack")).forEach(block => {
                dimension.runCommandAsync(`fill ${block.location.x} ${block.location.y} ${block.location.z} ${block.location.x} ${block.location.y} ${block.location.z} air destroy`)
            })
    }
}