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

world.beforeEvents.playerBreakBlock.subscribe(ev => {
    var item = ev.itemStack
    var block = ev.block;
    if (item != undefined){
        if (block.typeId === 'minecraft:mob_spawner')
        {
       var location = { x: ev.block.location.x, y: ev.block.location.y, z: ev.block.location.z };
       system.runTimeout(() => {
           ev.dimension.runCommand(`structure load spawner_loot ${location.x} ${location.y} ${location.z}`)
       }
    )
   }
    if (block.hasTag('no_silktouch')){
        ev.cancel = true
        var location = { x: ev.block.location.x, y: ev.block.location.y, z: ev.block.location.z };
        system.runTimeout(() => {
            ev.dimension.runCommand(`fill ${location.x} ${location.y} ${location.z} ${location.x} ${location.y} ${location.z} air destroy`)
        })
    }
    }
}
)