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


world.afterEvents.playerBreakBlock.subscribe((ev) => {
    const player = ev.player;
    const block = ev.block;
    const item = player.getComponent("inventory").container.getItem(player.selectedSlot).typeId;
    const { x, y, z } = block.location;

    if (item == "twm:drill") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run fill ~1 ~1 ~1 ~-1 ~-1 ~-1 air destroy`);
    };
    if (item == "twm:heavy_drill") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run fill ~+2 ~+3 ~+2 ~-2 ~-1 ~-2 air destroy`);
    };
    if (item == "twm:smelting_pickaxe") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function smelting`);
    };
    if (item == "twm:stone_hammer") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function hammer/twm_break`);
    };
    if (item == "twm:iron_hammer") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function hammer/twm_break`);
    };
    if (item == "twm:diamond_hammer") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function hammer/twm_break`);
    };
    if (item == "twm:netherite_hammer") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function hammer/twm_break`);
    };
    if (item == "twm:advanced_netherite_pickaxe") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_pickaxe`);
    };
    if (item == "twm:advanced_diamond_pickaxe") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_pickaxe`);
    };
    if (item == "twm:advanced_iron_pickaxe") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_pickaxe`);
    }
    if (item == "twm:advanced_netherite_axe") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_axe`);
    };
    if (item == "twm:advanced_diamond_axe") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_axe`);
    };
    if (item == "twm:advanced_iron_axe") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_axe`);
    }
    if (item == "twm:advanced_netherite_shovel") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_shovel`);
    };
    if (item == "twm:advanced_diamond_shovel") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_shovel`);
    };
    if (item == "twm:advanced_iron_shovel") {
        player.runCommandAsync(`execute positioned ${x} ${y} ${z} run function advanced_shovel`);
    }
})





