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


world.beforeEvents.playerInteractWithBlock.subscribe((dirt) => {
    const blockInteracted = dirt.block.typeId;
    system.runTimeout(() => {
        const block = dirt.block;
        const location = block.center();
        const player = dirt.player;
        const blockType = block.typeId;
        const hand = player.getComponent("minecraft:equippable");
        const item = hand.getEquipmentSlot(EquipmentSlot.Mainhand);
        const hasSlab = item.hasItem() && item.typeId === "stupidstuff:dirt_slab";
        const dimension = world.getDimension("overworld");
        const itemStack = dirt.itemStack;
        if (blockType === "stupidstuff:dirt_slab" && hasSlab === true) {
            dimension.setBlockType(location, "minecraft:dirt");
        };
    }, 0);
    system.runTimeout(() => {
        const blockAbove = dirt.block.above();
        const dimension = world.getDimension("overworld");
        if (blockAbove.typeId === "stupidstuff:dirt_slab" && blockInteracted === "stupidstuff:dirt_slab") {
            dimension.setBlockType(blockAbove, "minecraft:air");
        };
    }, 0);
});