// Custom Curios Related Events

BlockEvents.broken(event => {

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

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

    //Stone Charm
    if(event.getBlock() === "minecraft:stone" && curios.toString().contains('stoneopolis:stone_charm') && event.level.dimension === "minecraft:overworld" ) {
      event.server.runCommandSilent(`setblock ${event.getBlock().getX()} ${event.getBlock().getY()} ${event.getBlock().getZ()} minecraft:air`)
      event.server.runCommandSilent(`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') && event.level.dimension === "minecraft:overworld" ) {

      let block = `"${event.getBlock().id}"`
    
      event.server.runCommandSilent(`setblock ${event.getBlock().getX()} ${event.getBlock().getY()} ${event.getBlock().getZ()} minecraft:air`);
      event.server.runCommandSilent(`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);
    }
    
  }
})