// Custom Curios Related Events

BlockEvents.broken(event => {

  let curios = event.player.nbt.ForgeCaps['curios:inventory']

  if(!event.getLevel().isClientSide()) {

    let dimension = event.getLevel().getDimension().toString()

    //Stone Charm
    if(event.getBlock() === "minecraft:stone" && curios.toString().contains('stoneopolis:stone_charm') ) {
      event.server.runCommandSilent(`execute in ${dimension} run setblock ${event.getBlock().getX()} ${event.getBlock().getY()} ${event.getBlock().getZ()} minecraft:air`)
      event.server.runCommandSilent(`execute in ${dimension} run summon minecraft:item ${event.getBlock().getX()} ${event.getBlock().getY()+0.75} ${event.getBlock().getZ()} {Item:{id:"minecraft:cobblestone",Count:1}}`)
      if (event.player.getMainHandItem().isDamageableItem) {
        event.player.getMainHandItem().hurtAndBreak(1, event.player, (_player) => {
          return true;
        });
      }
      event.cancel(true)
    }

    //Budding Charm
    if (event.getBlock().hasTag('stoneopolis:budding_blocks') && curios.toString().contains('stoneopolis:budding_charm')) {

      let block = `"${event.getBlock().id}"`
    
      event.server.runCommandSilent(`execute in ${dimension} run setblock ${event.getBlock().getX()} ${event.getBlock().getY()} ${event.getBlock().getZ()} minecraft:air`);
      event.server.runCommandSilent(`execute in ${dimension} run summon minecraft:item ${event.getBlock().getX()} ${event.getBlock().getY() + 0.75} ${event.getBlock().getZ()} {Item:{id:${block},Count:1}}`);
      if (event.player.getMainHandItem().isDamageableItem) {
        event.player.getMainHandItem().hurtAndBreak(1, event.player, (_player) => {
          return true;
        });
      }
      event.cancel(true);
    }
    
  }
})