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

const tobeCheckedBlocks = ["hb_hr:dead_grass", "hb_hr:dead_root_carpet", "hb_hr:grim_stone_chunks", "hb_hr:hive_carpet", "hb_hr:bone_pile_b2_0", "hb_hr:bone_pile_b2_1", "hb_hr:bone_pile_b2_2", "hb_hr:bone_pile_small_0", "hb_hr:bone_pile_small_1", "hb_hr:bone_pile_small_2", "hb_hr:bone_pile_small_3", "hb_hr:bone_pile_small_4", "hb_hr:cursed_vine_carpet", "hb_hr:black_vine_carpet"];
export function airBelowBlock() {
  world.afterEvents.playerBreakBlock.subscribe((event) => {
    const block = event.block;
    const player = event.player;
    if (block.above()) {
      if (tobeCheckedBlocks.includes(block.above().typeId)) {
        player.dimension.runCommand("/fill " + event.block.location.x + " " + (event.block.location.y + 1) + " " + event.block.location.z + " " + event.block.location.x + " " + (event.block.location.y + 1) + " " + event.block.location.z + " air destroy");
      }
    }
  });
  world.beforeEvents.explosion.subscribe((event) => {
    const blownUpBlocks = event.getImpactedBlocks();
    for (const block of blownUpBlocks) {
      system.runTimeout(() => {
        if (block.above()) {
          if (tobeCheckedBlocks.includes(block.above().typeId)) {
            event.dimension.runCommand("/fill " + block.location.x + " " + (block.location.y + 1) + " " + block.location.z + " " + block.location.x + " " + (block.location.y + 1) + " " + block.location.z + " air destroy");
          }
        }
      }, 1);
    }
  });
}
