import { ItemStack, system } from "@minecraft/server";
import { amountToDropWithFortune, getFortuneLevel, getRandomInt, getSilkTouchLevel } from "../utils/my_API";
export class Pickaxe {
    constructor(typeId, pickDiggableTags) {
        this.typeId = typeId;
        this.pickDiggableTags = pickDiggableTags;
    }
}
export class Hammer {
    constructor(typeId, pickDiggableTags) {
        this.typeId = typeId;
        this.pickDiggableTags = pickDiggableTags;
    }
}
export class PickaxeCollection {
    constructor(pickaxes) {
        this.pickaxes = pickaxes;
    }
    addPickaxe(pickaxe) {
        this.pickaxes.push(pickaxe);
    }
    removePickaxe(typeId) {
        this.pickaxes = this.pickaxes.filter(pickaxe => pickaxe.typeId !== typeId);
    }
    getPickaxe(typeId) {
        return this.pickaxes.find(pickaxe => pickaxe.typeId === typeId);
    }
    getTagsFromPickaxeType(typeId) {
        const pickaxe = this.getPickaxe(typeId);
        return pickaxe ? pickaxe.pickDiggableTags : undefined;
    }
}
export class OreLoot {
    constructor(typeId, oreDrop, itemDropAmount, experienceAmount, fortuneBoostEnabled, maximumDropAmount) {
        this.typeId = typeId;
        this.oreDrop = oreDrop;
        this.itemDropAmount = itemDropAmount;
        this.experienceAmount = experienceAmount;
        this.fortuneBoostEnabled = fortuneBoostEnabled;
        this.maximumDropAmount = maximumDropAmount;
    }
    dropLoot(dimensionLocation, itemStack, isTriggering = false) {
        system.run(() => {
            const silktouchLevel = getSilkTouchLevel(itemStack);
            if (silktouchLevel > 0) {
                if (isTriggering) {
                    return;
                }
                // Spawn the silk touch item
                dimensionLocation.dimension.spawnItem(new ItemStack(this.typeId), dimensionLocation);
                return;
            }
            else {
                // Apply fortune level
                const fortuneLevel = getFortuneLevel(itemStack);
                let amount = getRandomInt(this.itemDropAmount[0], this.itemDropAmount[1]);
                if (this.fortuneBoostEnabled) {
                    amount = amountToDropWithFortune(fortuneLevel, amount);
                    amount = Math.min(amount, this.maximumDropAmount);
                }
                // Spawn the item
                dimensionLocation.dimension.spawnItem(new ItemStack(this.oreDrop.typeId, amount), dimensionLocation);
                // Spawn experience orbs
                const experienceAmount = getRandomInt(this.experienceAmount[0], this.experienceAmount[1]);
                for (let i = 0; i < experienceAmount; i++) {
                    dimensionLocation.dimension.spawnEntity("minecraft:xp_orb", dimensionLocation);
                }
            }
        });
    }
    getLootType() {
        return undefined;
    }
    getOreDropTranslateText() {
        const lootType = this.getLootType();
        let oreTypeId = this.oreDrop.typeId;
        if (oreTypeId.includes('minecraft:')) {
            switch (lootType) {
                case "item": {
                    return `item.${oreTypeId.split('minecraft:')[1]}.name`;
                }
                case "tile": {
                    return `tile.${oreTypeId.split('minecraft:')[1]}.name`;
                }
                default: {
                    return undefined;
                }
            }
        }
        else {
            switch (lootType) {
                case "item": {
                    return `item.${oreTypeId}`;
                }
                case "tile": {
                    return `tile.${oreTypeId}.name`;
                }
                default: {
                    return undefined;
                }
            }
        }
    }
    getOreTranslateText() {
        let typeId = this.typeId;
        if (typeId.includes('minecraft:')) {
            typeId = typeId.split('minecraft:')[1];
        }
        return `tile.${typeId}.name`;
    }
}
class GemOre extends OreLoot {
    constructor(typeId, oreDrop, itemDropAmount = [1, 1], experienceAmount = [1, 1], fortuneBoostEnabled = true, maximumDropAmount = undefined) {
        if (maximumDropAmount === undefined) {
            if (fortuneBoostEnabled == true) {
                maximumDropAmount = itemDropAmount[1] * 4;
            }
            else {
                maximumDropAmount = itemDropAmount[1];
            }
        }
        super(typeId, oreDrop, itemDropAmount, experienceAmount, fortuneBoostEnabled, maximumDropAmount);
    }
    getLootType() {
        return "item";
    }
}
class RawOre extends OreLoot {
    constructor(typeId, oreDrop, itemDropAmount = [1, 1], experienceAmount = [1, 1], fortuneBoostEnabled = false, maximumDropAmount = undefined) {
        if (maximumDropAmount === undefined) {
            if (fortuneBoostEnabled == true) {
                maximumDropAmount = itemDropAmount[1] * 4;
            }
            else {
                maximumDropAmount = itemDropAmount[1];
            }
        }
        super(typeId, oreDrop, itemDropAmount, experienceAmount, fortuneBoostEnabled, maximumDropAmount);
    }
    getLootType() {
        return "item";
    }
}
class ConstructionBlock extends OreLoot {
    constructor(typeId) {
        super(typeId, new ItemStack(typeId), [1, 1], [0, 0], false, 1);
    }
    getLootType() {
        return "tile";
    }
}
export class OreLootCollection {
    static findOreIndexByOreId(oreId) {
        return this.ores.findIndex((ore) => ore.typeId === oreId);
    }
    static findVanillaOreIndexByOreId(oreId) {
        return this.vanillaOres.findIndex((ore) => ore.typeId === oreId);
    }
    static findOreIndexByOreDrop(oreDropId) {
        return this.ores.findIndex((ore) => ore.oreDrop.typeId === oreDropId);
    }
}
OreLootCollection.ores = [
    new RawOre(`nps_mot:lead_ore`, new ItemStack(`nps_mot:raw_lead`), [1, 1], [0, 0], true),
    new RawOre(`nps_mot:cassiterite_ore`, new ItemStack(`nps_mot:raw_cassiterite`), [1, 1], [0, 0], true),
    new RawOre(`nps_mot:deepslate_cassiterite_ore`, new ItemStack(`nps_mot:raw_cassiterite`), [1, 1], [0, 0], true),
    new RawOre(`nps_mot:aluminium_ore`, new ItemStack(`nps_mot:raw_aluminium`), [1, 1], [0, 0], true),
    //
    new GemOre(`nps_mot:sulfur_ore`, new ItemStack(`nps_mot:sulfur`)),
    new GemOre(`nps_mot:benitoite_ore`, new ItemStack(`nps_mot:benitoite`)),
    new GemOre(`nps_mot:fire_opal_ore`, new ItemStack(`nps_mot:fire_opal`)),
    new GemOre(`nps_mot:garnet_ore`, new ItemStack(`nps_mot:garnet`)),
    new GemOre(`nps_mot:lazurite_ore`, new ItemStack(`nps_mot:lazurite`)),
    new GemOre(`nps_mot:peridot_ore`, new ItemStack(`nps_mot:peridot`)),
    new GemOre(`nps_mot:spinel_ore`, new ItemStack(`nps_mot:spinel`)),
    new GemOre(`nps_mot:amber_ore`, new ItemStack(`nps_mot:amber`)),
    new GemOre(`nps_mot:black_diamond_ore`, new ItemStack(`nps_mot:black_diamond`)),
    new GemOre(`nps_mot:black_opal_ore`, new ItemStack(`nps_mot:black_opal`)),
    new GemOre(`nps_mot:blue_garnet_ore`, new ItemStack(`nps_mot:blue_garnet`)),
    new RawOre(`nps_mot:chrome_ore`, new ItemStack(`nps_mot:raw_chrome`)),
    new GemOre(`nps_mot:citrine_ore`, new ItemStack(`nps_mot:citrine`)),
    new RawOre(`nps_mot:cobalt_ore`, new ItemStack(`nps_mot:raw_cobalt`)),
    new GemOre(`nps_mot:osmium_ore`, new ItemStack(`nps_mot:raw_osmium`)),
    new GemOre(`nps_mot:green_diamond_ore`, new ItemStack(`nps_mot:green_diamond`)),
    new RawOre(`nps_mot:iridium_ore`, new ItemStack(`nps_mot:raw_iridium`)),
    new RawOre(`nps_mot:nickel_ore`, new ItemStack(`nps_mot:raw_nickel`)),
    new GemOre(`nps_mot:opal_ore`, new ItemStack(`nps_mot:opal`)),
    new GemOre(`nps_mot:orange_diamond_ore`, new ItemStack(`nps_mot:orange_diamond`)),
    new RawOre(`nps_mot:orichalc_ore`, new ItemStack(`nps_mot:raw_orichalc`), [1, 1], [0, 0], true),
    new RawOre(`nps_mot:palladium_ore`, new ItemStack(`nps_mot:raw_palladium`)),
    new GemOre(`nps_mot:pink_diamond_ore`, new ItemStack(`nps_mot:pink_diamond`)),
    new RawOre(`nps_mot:platinum_ore`, new ItemStack(`nps_mot:raw_platinum`)),
    new GemOre(`nps_mot:purple_diamond_ore`, new ItemStack(`nps_mot:purple_diamond`)),
    new GemOre(`nps_mot:red_diamond_ore`, new ItemStack(`nps_mot:red_diamond`)),
    new RawOre(`nps_mot:rhodium_ore`, new ItemStack(`nps_mot:raw_rhodium`)),
    new GemOre(`nps_mot:ruby_ore`, new ItemStack(`nps_mot:ruby`)),
    new RawOre(`nps_mot:ruthenium_ore`, new ItemStack(`nps_mot:raw_ruthenium`)),
    new GemOre(`nps_mot:sapphire_ore`, new ItemStack(`nps_mot:sapphire`)),
    new GemOre(`nps_mot:topaz_ore`, new ItemStack(`nps_mot:topaz`)),
    new GemOre(`nps_mot:yellow_diamond_ore`, new ItemStack(`nps_mot:yellow_diamond`)),
    //
    new GemOre(`nps_mot:deepslate_amber_ore`, new ItemStack(`nps_mot:amber`)),
    new GemOre(`nps_mot:deepslate_black_diamond_ore`, new ItemStack(`nps_mot:black_diamond`)),
    new GemOre(`nps_mot:deepslate_black_opal_ore`, new ItemStack(`nps_mot:black_opal`)),
    new GemOre(`nps_mot:deepslate_blue_garnet_ore`, new ItemStack(`nps_mot:blue_garnet`)),
    new RawOre(`nps_mot:deepslate_chrome_ore`, new ItemStack(`nps_mot:raw_chrome`)),
    new GemOre(`nps_mot:deepslate_citrine_ore`, new ItemStack(`nps_mot:citrine`)),
    new RawOre(`nps_mot:deepslate_cobalt_ore`, new ItemStack(`nps_mot:raw_cobalt`)),
    new GemOre(`nps_mot:deepslate_green_diamond_ore`, new ItemStack(`nps_mot:green_diamond`)),
    new RawOre(`nps_mot:deepslate_iridium_ore`, new ItemStack(`nps_mot:raw_iridium`)),
    new RawOre(`nps_mot:deepslate_nickel_ore`, new ItemStack(`nps_mot:raw_nickel`)),
    new GemOre(`nps_mot:deepslate_opal_ore`, new ItemStack(`nps_mot:opal`)),
    new GemOre(`nps_mot:deepslate_orange_diamond_ore`, new ItemStack(`nps_mot:orange_diamond`)),
    new RawOre(`nps_mot:deepslate_orichalc_ore`, new ItemStack(`nps_mot:raw_orichalc`), [1, 1], [0, 0], true),
    new GemOre(`nps_mot:deepslate_osmium_ore`, new ItemStack(`nps_mot:raw_osmium`)),
    new RawOre(`nps_mot:deepslate_palladium_ore`, new ItemStack(`nps_mot:raw_palladium`)),
    new GemOre(`nps_mot:deepslate_pink_diamond_ore`, new ItemStack(`nps_mot:pink_diamond`)),
    new RawOre(`nps_mot:deepslate_platinum_ore`, new ItemStack(`nps_mot:raw_platinum`)),
    new GemOre(`nps_mot:deepslate_purple_diamond_ore`, new ItemStack(`nps_mot:purple_diamond`)),
    new GemOre(`nps_mot:deepslate_red_diamond_ore`, new ItemStack(`nps_mot:red_diamond`)),
    new RawOre(`nps_mot:deepslate_rhodium_ore`, new ItemStack(`nps_mot:raw_rhodium`)),
    new GemOre(`nps_mot:deepslate_ruby_ore`, new ItemStack(`nps_mot:ruby`)),
    new RawOre(`nps_mot:deepslate_ruthenium_ore`, new ItemStack(`nps_mot:raw_ruthenium`)),
    new GemOre(`nps_mot:deepslate_sapphire_ore`, new ItemStack(`nps_mot:sapphire`)),
    new GemOre(`nps_mot:deepslate_topaz_ore`, new ItemStack(`nps_mot:topaz`)),
    new GemOre(`nps_mot:deepslate_yellow_diamond_ore`, new ItemStack(`nps_mot:yellow_diamond`)),
    new RawOre(`nps_mot:deepslate_lead_ore`, new ItemStack(`nps_mot:raw_lead`), [1, 1], [0, 0], true),
    new RawOre(`nps_mot:deepslate_aluminium_ore`, new ItemStack(`nps_mot:raw_aluminium`), [1, 1], [0, 0], true),
    //
    new RawOre(`nps_mot:adamantite_ore`, new ItemStack(`nps_mot:raw_adamantite`)),
    new RawOre(`nps_mot:bismuthinite_ore`, new ItemStack(`nps_mot:bismuthinite`)),
    //
    new ConstructionBlock(`nps_mot:tungsten_ore`),
    new ConstructionBlock(`nps_mot:titanium_ore`),
    new ConstructionBlock(`nps_mot:deepslate_titanium_ore`),
    new ConstructionBlock(`nps_mot:deepslate_tungsten_ore`),
    //
    new ConstructionBlock(`nps_mot:adamantite_block`),
    new ConstructionBlock(`nps_mot:tin_block`),
    new ConstructionBlock(`nps_mot:sulfur_block`),
    new ConstructionBlock(`nps_mot:benitoite_block`),
    new ConstructionBlock(`nps_mot:bismuthinite_block`),
    new ConstructionBlock(`nps_mot:fire_opal_block`),
    new ConstructionBlock(`nps_mot:garnet_block`),
    new ConstructionBlock(`nps_mot:lazurite_block`),
    new ConstructionBlock(`nps_mot:peridot_block`),
    new ConstructionBlock(`nps_mot:spinel_block`),
    //
    new ConstructionBlock(`nps_mot:aluminium_block`),
    new ConstructionBlock(`nps_mot:amber_block`),
    new ConstructionBlock(`nps_mot:black_diamond_block`),
    new ConstructionBlock(`nps_mot:black_opal_block`),
    new ConstructionBlock(`nps_mot:blue_garnet_block`),
    new ConstructionBlock(`nps_mot:bronze_block`),
    new ConstructionBlock(`nps_mot:chrome_block`),
    new ConstructionBlock(`nps_mot:citrine_block`),
    new ConstructionBlock(`nps_mot:cobalt_block`),
    new ConstructionBlock(`nps_mot:green_diamond_block`),
    new ConstructionBlock(`nps_mot:iridium_block`),
    new ConstructionBlock(`nps_mot:lead_block`),
    new ConstructionBlock(`nps_mot:nickel_block`),
    new ConstructionBlock(`nps_mot:opal_block`),
    new ConstructionBlock(`nps_mot:orange_diamond_block`),
    new ConstructionBlock(`nps_mot:orichalc_block`),
    new ConstructionBlock(`nps_mot:osmium_block`),
    new ConstructionBlock(`nps_mot:palladium_block`),
    new ConstructionBlock(`nps_mot:pink_diamond_block`),
    new ConstructionBlock(`nps_mot:platinum_block`),
    new ConstructionBlock(`nps_mot:purple_diamond_block`),
    new ConstructionBlock(`nps_mot:red_diamond_block`),
    new ConstructionBlock(`nps_mot:rhodium_block`),
    new ConstructionBlock(`nps_mot:ruby_block`),
    new ConstructionBlock(`nps_mot:ruthenium_block`),
    new ConstructionBlock(`nps_mot:sapphire_block`),
    new ConstructionBlock(`nps_mot:stainless_steel_block`),
    new ConstructionBlock(`nps_mot:titanium_block`),
    new ConstructionBlock(`nps_mot:topaz_block`),
    new ConstructionBlock(`nps_mot:tungsten_block`),
    new ConstructionBlock(`nps_mot:tungsten_aluminium_block`),
    new ConstructionBlock(`nps_mot:yellow_diamond_block`),
    //
    new ConstructionBlock(`nps_mot:raw_adamantite_block`),
    new ConstructionBlock(`nps_mot:raw_cassiterite_block`),
    //
    new ConstructionBlock(`nps_mot:raw_aluminium_block`),
    new ConstructionBlock(`nps_mot:raw_chrome_block`),
    new ConstructionBlock(`nps_mot:raw_cobalt_block`),
    new ConstructionBlock(`nps_mot:raw_iridium_block`),
    new ConstructionBlock(`nps_mot:raw_lead_block`),
    new ConstructionBlock(`nps_mot:raw_nickel_block`),
    new ConstructionBlock(`nps_mot:raw_orichalc_block`),
    new ConstructionBlock(`nps_mot:raw_osmium_block`),
    new ConstructionBlock(`nps_mot:raw_palladium_block`),
    new ConstructionBlock(`nps_mot:raw_platinum_block`),
    new ConstructionBlock(`nps_mot:raw_rhodium_block`),
    new ConstructionBlock(`nps_mot:raw_ruthenium_block`),
    new ConstructionBlock(`nps_mot:raw_titanium_block`),
    new ConstructionBlock(`nps_mot:raw_tungsten_block`),
    new RawOre(`nps_mot:nether_orichalc_ore`, new ItemStack(`nps_mot:raw_orichalc`), [1, 1], [0, 0], true)
];
OreLootCollection.vanillaOres = [
    new GemOre(`minecraft:coal_ore`, new ItemStack(`minecraft:coal`)),
    new GemOre(`minecraft:deepslate_coal_ore`, new ItemStack(`minecraft:coal`)),
    new GemOre(`minecraft:lapis_ore`, new ItemStack(`minecraft:lapis_lazuli`), [4, 9], [1, 3]),
    new GemOre(`minecraft:deepslate_lapis_ore`, new ItemStack(`minecraft:lapis_lazuli`), [4, 9], [1, 3]),
    new RawOre(`minecraft:iron_ore`, new ItemStack(`minecraft:raw_iron`), [1, 1], [0, 0], true),
    new RawOre(`minecraft:deepslate_iron_ore`, new ItemStack(`minecraft:raw_iron`), [1, 1], [0, 0], true),
    new RawOre(`minecraft:gold_ore`, new ItemStack(`minecraft:raw_gold`), [1, 1], [0, 0], true),
    new RawOre(`minecraft:deepslate_gold_ore`, new ItemStack(`minecraft:raw_gold`), [1, 1], [0, 0], true),
    new RawOre(`minecraft:nether_gold_ore`, new ItemStack(`minecraft:gold_nugget`), [2, 6], [0, 0], true),
    new GemOre(`minecraft:redstone_ore`, new ItemStack(`minecraft:redstone`), [4, 5], [1, 3,], true, 8),
    new GemOre(`minecraft:deepslate_redstone_ore`, new ItemStack(`minecraft:redstone`), [4, 5], [1, 3,], true, 8),
    new GemOre(`minecraft:diamond_ore`, new ItemStack(`minecraft:diamond`), [1, 1], [1, 3]),
    new GemOre(`minecraft:deepslate_diamond_ore`, new ItemStack(`minecraft:diamond`), [1, 1], [1, 3]),
    new GemOre(`minecraft:emerald_ore`, new ItemStack(`minecraft:emerald`), [1, 1], [1, 3]),
    new GemOre(`minecraft:deepslate_emerald_ore`, new ItemStack(`minecraft:emerald`), [1, 1], [1, 3]),
    new RawOre(`minecraft:copper_ore`, new ItemStack(`minecraft:raw_copper`), [2, 5], [0, 0], true),
    new RawOre(`minecraft:deepslate_copper_ore`, new ItemStack(`minecraft:raw_copper`), [2, 5], [0, 0], true),
    new GemOre(`minecraft:quartz_ore`, new ItemStack(`minecraft:quartz`), [1, 1], [2, 5]),
    new ConstructionBlock(`minecraft:ancient_debris`)
];
