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

world.beforeEvents.itemUseOn.subscribe(eventData => {
  const player = eventData.source;
  const itemUsed = eventData.itemStack;
  const block = eventData.block;
  const blockLocation = block.location;
  const playerEquippable = player.getComponent("equippable");
  const stateAll = block.permutation.getAllStates();
  const customAxes = [
    "nicothekid:brass_axe",
    "nicothekid:bronze_axe",
    "nicothekid:copper_axe",
    "nicothekid:flint_axe",
    "nicothekid:olivine_axe",
    "nicothekid:tin_axe",
    "nicothekid:zinc_axe"
  ]
  const customHoes = [
    "nicothekid:brass_hoe",
    "nicothekid:bronze_hoe",
    "nicothekid:copper_hoe",
    "nicothekid:olivine_hoe",
    "nicothekid:tin_hoe",
    "nicothekid:zinc_hoe"
  ]
  const customShovels = [
    "nicothekid:brass_shovel",
    "nicothekid:bronze_shovel",
    "nicothekid:copper_shovel",
    "nicothekid:olivine_shovel",
    "nicothekid:tin_shovel",
    "nicothekid:zinc_shovel"
  ]
  function damageDurability () {
    if (!player.matches({ gameMode: GameMode.creative })) {
      const itemEnchantable = itemUsed.getComponent("minecraft:enchantable");
      const unbreakingLevel = itemEnchantable?.getEnchantment("unbreaking")?.level ?? 0;
      const breakChance = 100 / (unbreakingLevel + 1);
      const randomizeChance = Math.random() * 100;
      if (breakChance < randomizeChance) return;
      const itemDurability = itemUsed.getComponent("durability");
      if (!itemDurability) return;
      const itemMaxDurability = itemDurability.maxDurability;
      const itemDurabilityDamage = itemDurability.damage;
      const durabilityCalculation = itemMaxDurability - itemDurabilityDamage;
      let damageAmount = 1;
      const currentDurability = durabilityCalculation - damageAmount;
      if (currentDurability <= 0) {
        player.playSound("random.break", { pitch: 0.9, location: player.location, volume: 1 });
        playerEquippable.setEquipment("Mainhand", null);
      }
      else {
        itemDurability.damage += damageAmount;
        playerEquippable.setEquipment("Mainhand", itemUsed)
      }
    }
  }
  if (itemUsed === undefined) return;
  if (itemUsed.hasTag("minecraft:is_axe") || customAxes.includes(itemUsed.typeId) || itemUsed.hasTag("minecraft:is_hoe") || customHoes.includes(itemUsed.typeId) || itemUsed.hasTag("minecraft:is_shovel") || customShovels.includes(itemUsed.typeId)) {
    if (itemUsed.hasTag("minecraft:is_axe") || customAxes.includes(itemUsed.typeId)) {
      const customWoods = [
        "nicothekid:corrupted_log",
        "nicothekid:corrupted_wood",
        "nicothekid:mosshroom_stem",
        "nicothekid:mosshroom_hyphae",
        "nicothekid:mossy_log",
        "nicothekid:mossy_wood",
        "nicothekid:overgrown_jungle_log",
        "nicothekid:overgrown_jungle_wood"
      ]
      const customCopper = [
        "nicothekid:copper_lamp_exposed",
        "nicothekid:copper_lamp_oxidized",
        "nicothekid:copper_lamp_weathered",
        "nicothekid:copper_lantern_exposed",
        "nicothekid:copper_lantern_oxidized",
        "nicothekid:copper_lantern_weathered"
      ]
      const customWaxedCopper = [
        "nicothekid:waxed_copper_lamp",
        "nicothekid:waxed_copper_lamp_exposed",
        "nicothekid:waxed_copper_lamp_oxidized",
        "nicothekid:waxed_copper_lamp_weathered",
        "nicothekid:waxed_copper_lantern",
        "nicothekid:waxed_copper_lantern_exposed",
        "nicothekid:waxed_copper_lantern_oxidized",
        "nicothekid:waxed_copper_lantern_weathered"
      ]
      if (customWoods.includes(block.typeId)) {
        system.run(() => {
          damageDurability ();
          if (block.permutation.matches("nicothekid:corrupted_log")) {
            block.dimension.playSound("use.wood", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log_stripped", stateAll ));
            return;
          }
          if (block.permutation.matches("nicothekid:corrupted_wood")) {
            block.dimension.playSound("use.wood", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_wood_stripped", stateAll ));
            return;
          }
          if (block.permutation.matches("nicothekid:mosshroom_hyphae")) {
            block.dimension.playSound("use.stem", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:mosshroom_hyphae_stripped", stateAll ));
            return;
          }
          if (block.permutation.matches("nicothekid:mosshroom_stem")) {
            block.dimension.playSound("use.stem", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:mosshroom_stem_stripped", stateAll ));
            return;
          }
          if (block.permutation.matches("nicothekid:mossy_log")) {
            block.dimension.playSound("use.wood", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log_stripped", stateAll ));
            return;
          }
          if (block.permutation.matches("nicothekid:mossy_wood")) {
            block.dimension.playSound("use.wood", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_wood_stripped", stateAll ));
            return;
          }
          if (block.permutation.matches("nicothekid:overgrown_jungle_log")) {
            block.dimension.playSound("use.wood", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log_stripped", stateAll ));
            return;
          }
          if (block.permutation.matches("nicothekid:overgrown_jungle_wood")) {
            block.dimension.playSound("use.wood", blockLocation, { pitch: 0.8, volume: 1.0 });
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_wood_stripped", stateAll ));
            return;
          }
        });
      }
      if (customCopper.includes(block.typeId)) {
        system.run(() => {
          const pitchRange = Math.random() * (1.2 - 0.8) + 0.8;
          damageDurability ();
          block.dimension.playSound("scrape", blockLocation, { pitch: pitchRange, volume: 1.0 });
          block.dimension.spawnParticle("nicothekid:copper_scrape_particle", blockLocation);
          if (block.permutation.matches("nicothekid:copper_lamp_exposed")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lamp"));
          }
          if (block.permutation.matches("nicothekid:copper_lamp_weathered")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lamp_exposed"));
          }
          if (block.permutation.matches("nicothekid:copper_lamp_oxidized")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lamp_weathered"));
          }
          if (block.permutation.matches("nicothekid:copper_lantern_exposed")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lantern", stateAll ));
          }
          if (block.permutation.matches("nicothekid:copper_lantern_weathered")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lantern_exposed", stateAll ));
          }
          if (block.permutation.matches("nicothekid:copper_lantern_oxidized")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lantern_weathered", stateAll ));
          }
        });
      }
      if (customWaxedCopper.includes(block.typeId)) {
        system.run(() => {
          const pitchRange = Math.random() * (1.2 - 0.8) + 0.8;
          damageDurability ();
          block.dimension.playSound("copper.wax.off", blockLocation, { pitch: pitchRange, volume: 1.0 });
          block.dimension.spawnParticle("nicothekid:copper_wax_off_particle", blockLocation);
          if (block.permutation.matches("nicothekid:waxed_copper_lamp")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lamp"));
          }
          if (block.permutation.matches("nicothekid:waxed_copper_lamp_exposed")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lamp_exposed"));
          }
          if (block.permutation.matches("nicothekid:waxed_copper_lamp_weathered")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lamp_weathered"));
          }
          if (block.permutation.matches("nicothekid:waxed_copper_lamp_oxidized")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lamp_oxidized"));
          }
          if (block.permutation.matches("nicothekid:waxed_copper_lantern")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lantern", stateAll ));
          }
          if (block.permutation.matches("nicothekid:waxed_copper_lantern_exposed")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lantern_exposed", stateAll ));
          }
          if (block.permutation.matches("nicothekid:waxed_copper_lantern_weathered")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lantern_weathered", stateAll ));
          }
          if (block.permutation.matches("nicothekid:waxed_copper_lantern_oxidized")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:copper_lantern_oxidized", stateAll ));
          }
        });
      }
    }
    if (itemUsed.hasTag("minecraft:is_hoe") || customHoes.includes(itemUsed.typeId)) {
      const grassedBlocks = [
        "nicothekid:grassed_stone",
        "nicothekid:grassed_oak_log_side",
        "nicothekid:grassed_oak_log_top",
        "nicothekid:grassed_oak_planks",
        "nicothekid:grassed_stripped_oak_log_side",
        "nicothekid:grassed_stripped_oak_log_top",
        "nicothekid:grassed_spruce_log_side",
        "nicothekid:grassed_spruce_log_top",
        "nicothekid:grassed_spruce_planks",
        "nicothekid:grassed_stripped_spruce_log_side",
        "nicothekid:grassed_stripped_spruce_log_top",
        "nicothekid:grassed_birch_log_side",
        "nicothekid:grassed_birch_log_top",
        "nicothekid:grassed_birch_planks",
        "nicothekid:grassed_stripped_birch_log_side",
        "nicothekid:grassed_stripped_birch_log_top",
        "nicothekid:grassed_jungle_log_side",
        "nicothekid:grassed_jungle_log_top",
        "nicothekid:grassed_jungle_planks",
        "nicothekid:grassed_stripped_jungle_log_side",
        "nicothekid:grassed_stripped_jungle_log_top",
        "nicothekid:grassed_acacia_log_side",
        "nicothekid:grassed_acacia_log_top",
        "nicothekid:grassed_acacia_planks",
        "nicothekid:grassed_stripped_acacia_log_side",
        "nicothekid:grassed_stripped_acacia_log_top",
        "nicothekid:grassed_dark_oak_log_side",
        "nicothekid:grassed_dark_oak_log_top",
        "nicothekid:grassed_dark_oak_planks",
        "nicothekid:grassed_stripped_dark_oak_log_side",
        "nicothekid:grassed_stripped_dark_oak_log_top",
        "nicothekid:grassed_mangrove_log_side",
        "nicothekid:grassed_mangrove_log_top",
        "nicothekid:grassed_mangrove_planks",
        "nicothekid:grassed_stripped_mangrove_log_side",
        "nicothekid:grassed_stripped_mangrove_log_top",
        "nicothekid:grassed_cherry_log_side",
        "nicothekid:grassed_cherry_log_top",
        "nicothekid:grassed_cherry_planks",
        "nicothekid:grassed_stripped_cherry_log_side",
        "nicothekid:grassed_stripped_cherry_log_top",
        "nicothekid:grassed_corrupted_log_side",
        "nicothekid:grassed_corrupted_log_top",
        "nicothekid:grassed_corrupted_planks",
        "nicothekid:grassed_stripped_corrupted_log_side",
        "nicothekid:grassed_stripped_corrupted_log_top",
        "nicothekid:grassed_mossy_log_side",
        "nicothekid:grassed_mossy_log_top",
        "nicothekid:grassed_mossy_planks",
        "nicothekid:grassed_stripped_mossy_log_side",
        "nicothekid:grassed_stripped_mossy_log_top",
        "nicothekid:grassed_overgrown_jungle_log_side",
        "nicothekid:grassed_overgrown_jungle_log_top",
        "nicothekid:grassed_overgrown_jungle_planks",
        "nicothekid:grassed_stripped_overgrown_jungle_log_side",
        "nicothekid:grassed_stripped_overgrown_jungle_log_top"
      ]
      const mossedBlocks = [
        "nicothekid:mossed_stone",
        "nicothekid:mossed_oak_log_side",
        "nicothekid:mossed_oak_log_top",
        "nicothekid:mossed_oak_planks",
        "nicothekid:mossed_stripped_oak_log_side",
        "nicothekid:mossed_stripped_oak_log_top",
        "nicothekid:mossed_spruce_log_side",
        "nicothekid:mossed_spruce_log_top",
        "nicothekid:mossed_spruce_planks",
        "nicothekid:mossed_stripped_spruce_log_side",
        "nicothekid:mossed_stripped_spruce_log_top",
        "nicothekid:mossed_birch_log_side",
        "nicothekid:mossed_birch_log_top",
        "nicothekid:mossed_birch_planks",
        "nicothekid:mossed_stripped_birch_log_side",
        "nicothekid:mossed_stripped_birch_log_top",
        "nicothekid:mossed_jungle_log_side",
        "nicothekid:mossed_jungle_log_top",
        "nicothekid:mossed_jungle_planks",
        "nicothekid:mossed_stripped_jungle_log_side",
        "nicothekid:mossed_stripped_jungle_log_top",
        "nicothekid:mossed_acacia_log_side",
        "nicothekid:mossed_acacia_log_top",
        "nicothekid:mossed_acacia_planks",
        "nicothekid:mossed_stripped_acacia_log_side",
        "nicothekid:mossed_stripped_acacia_log_top",
        "nicothekid:mossed_dark_oak_log_side",
        "nicothekid:mossed_dark_oak_log_top",
        "nicothekid:mossed_dark_oak_planks",
        "nicothekid:mossed_stripped_dark_oak_log_side",
        "nicothekid:mossed_stripped_dark_oak_log_top",
        "nicothekid:mossed_mangrove_log_side",
        "nicothekid:mossed_mangrove_log_top",
        "nicothekid:mossed_mangrove_planks",
        "nicothekid:mossed_stripped_mangrove_log_side",
        "nicothekid:mossed_stripped_mangrove_log_top",
        "nicothekid:mossed_cherry_log_side",
        "nicothekid:mossed_cherry_log_top",
        "nicothekid:mossed_cherry_planks",
        "nicothekid:mossed_stripped_cherry_log_side",
        "nicothekid:mossed_stripped_cherry_log_top",
        "nicothekid:mossed_corrupted_log_side",
        "nicothekid:mossed_corrupted_log_top",
        "nicothekid:mossed_corrupted_planks",
        "nicothekid:mossed_stripped_corrupted_log_side",
        "nicothekid:mossed_stripped_corrupted_log_top",
        "nicothekid:mossed_mossy_log_side",
        "nicothekid:mossed_mossy_log_top",
        "nicothekid:mossed_mossy_planks",
        "nicothekid:mossed_stripped_mossy_log_side",
        "nicothekid:mossed_stripped_mossy_log_top",
        "nicothekid:mossed_overgrown_jungle_log_side",
        "nicothekid:mossed_overgrown_jungle_log_top",
        "nicothekid:mossed_overgrown_jungle_planks",
        "nicothekid:mossed_stripped_overgrown_jungle_log_side",
        "nicothekid:mossed_stripped_overgrown_jungle_log_top"
      ]
      const myceliumedBlocks = [
        "nicothekid:myceliumed_deepslate"
      ]
      if (grassedBlocks.includes(block.typeId)) {
        system.run(() => {
          const pitchRange = Math.random() * (1.0 - 0.8) + 0.8;
          function spawnGrassCarpet () {
            const grassCarpet = new ItemStack ("nicothekid:grass_carpet", 1);
            let randomChance = Math.random();
            if (itemUsed.getComponent("enchantable").hasEnchantment("silk_touch")) {
              block.dimension.spawnItem(grassCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
            }
            else if (itemUsed.getComponent("enchantable").hasEnchantment("fortune")) {
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 1) {
                if (randomChance <= 0.5) {
                  block.dimension.spawnItem(grassCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 2) {
                if (randomChance <= 0.75) {
                  block.dimension.spawnItem(grassCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 3) {
                if (randomChance <= 1.0) {
                  block.dimension.spawnItem(grassCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
            }
            else {
              if (randomChance <= 0.25) {
                block.dimension.spawnItem(grassCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
              }
              else return;
            }
          }
          damageDurability ();
          spawnGrassCarpet ();
          block.dimension.playSound("use.gravel", blockLocation, { pitch: pitchRange, volume: 0.8 });
          if (block.permutation.matches("nicothekid:grassed_stone")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stone"));
          }
          if (block.permutation.matches("nicothekid:grassed_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:oak_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_oak_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:oak_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_oak_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_spruce_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:spruce_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:spruce_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_spruce_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:spruce_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_spruce_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:spruce_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_spruce_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_spruce_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_spruce_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_spruce_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_spruce_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_birch_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:birch_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:birch_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_birch_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:birch_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_birch_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:birch_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_birch_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_birch_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_birch_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_birch_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_birch_log", { pillar_axis: "y" }))
          }
          if (block.permutation.matches("nicothekid:grassed_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:jungle_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:jungle_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:jungle_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_jungle_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:jungle_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_jungle_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_jungle_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_jungle_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_acacia_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:acacia_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:acacia_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_acacia_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:acacia_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_acacia_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:acacia_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_acacia_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_acacia_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_acacia_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_acacia_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_acacia_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_dark_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_dark_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_dark_oak_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_dark_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_dark_oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_dark_oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_dark_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_dark_oak_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_mangrove_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_mangrove_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_mangrove_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_mangrove_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_mangrove_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_mangrove_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_mangrove_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_mangrove_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_cherry_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:cherry_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:cherry_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_cherry_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:cherry_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_cherry_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:cherry_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_cherry_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_cherry_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_cherry_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_cherry_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_cherry_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_corrupted_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:grassed_corrupted_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_corrupted_planks")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_corrupted_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log_stripped", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_corrupted_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log_stripped"));
          }
          if (block.permutation.matches("nicothekid:grassed_mossy_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:grassed_mossy_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_mossy_planks")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_mossy_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log_stripped", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_mossy_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log_stripped"));
          }
          if (block.permutation.matches("nicothekid:grassed_overgrown_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:grassed_overgrown_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log"));
          }
          if (block.permutation.matches("nicothekid:grassed_overgrown_jungle_planks")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_planks"));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_overgrown_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log_stripped", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:grassed_stripped_overgrown_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log_stripped"));
          }
        });
      }
      if (mossedBlocks.includes(block.typeId)) {
        system.run(() => {
          const pitchRange = Math.random() * (1.0 - 0.8) + 0.8;
          function spawnMossCarpet () {
            const mossCarpet = new ItemStack ("minecraft:moss_carpet", 1);
            let randomChance = Math.random();
            if (itemUsed.getComponent("enchantable").hasEnchantment("silk_touch")) {
              block.dimension.spawnItem(mossCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
            }
            else if (itemUsed.getComponent("enchantable").hasEnchantment("fortune")) {
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 1) {
                if (randomChance <= 0.5) {
                  block.dimension.spawnItem(mossCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 2) {
                if (randomChance <= 0.75) {
                  block.dimension.spawnItem(mossCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 3) {
                if (randomChance <= 1.0) {
                  block.dimension.spawnItem(mossCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
            }
            else {
              if (randomChance <= 0.25) {
                block.dimension.spawnItem(mossCarpet, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
              }
              else return;
            }
          }
          damageDurability ();
          spawnMossCarpet ();
          block.dimension.playSound("use.gravel", blockLocation, { pitch: pitchRange, volume: 0.8 });
          if (block.permutation.matches("nicothekid:mossed_stone")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stone"));
          }
          if (block.permutation.matches("nicothekid:mossed_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:oak_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_oak_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:oak_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_oak_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_spruce_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:spruce_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:spruce_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_spruce_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:spruce_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_spruce_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:spruce_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_spruce_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_spruce_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_spruce_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_spruce_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_spruce_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_birch_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:birch_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:birch_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_birch_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:birch_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_birch_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:birch_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_birch_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_birch_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_birch_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_birch_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_birch_log", { pillar_axis: "y" }))
          }
          if (block.permutation.matches("nicothekid:mossed_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:jungle_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:jungle_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:jungle_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_jungle_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:jungle_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_jungle_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_jungle_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_jungle_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_acacia_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:acacia_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:acacia_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_acacia_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:acacia_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_acacia_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:acacia_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_acacia_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_acacia_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_acacia_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_acacia_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_acacia_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_dark_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_dark_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_dark_oak_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:dark_oak_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_dark_oak_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_dark_oak_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_dark_oak_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_dark_oak_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_dark_oak_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_mangrove_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_mangrove_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_mangrove_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:mangrove_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_mangrove_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_mangrove_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_mangrove_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_mangrove_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_mangrove_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_cherry_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:cherry_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:cherry_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_cherry_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:cherry_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_cherry_planks")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:cherry_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_cherry_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            if (stateCardinalDirection === "east" || stateCardinalDirection === "west") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_cherry_log", { "pillar_axis": "x" }));
            }
            else if (stateCardinalDirection === "north" || stateCardinalDirection === "south") {
              block.setPermutation(BlockPermutation.resolve("minecraft:stripped_cherry_log", { "pillar_axis": "z" }));
            }
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_cherry_log_top")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:stripped_cherry_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_corrupted_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:mossed_corrupted_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_corrupted_planks")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_corrupted_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log_stripped", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_corrupted_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:corrupted_log_stripped"));
          }
          if (block.permutation.matches("nicothekid:mossed_mossy_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:mossed_mossy_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_mossy_planks")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_mossy_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log_stripped", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_mossy_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:mossy_log_stripped"));
          }
          if (block.permutation.matches("nicothekid:mossed_overgrown_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:mossed_overgrown_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log"));
          }
          if (block.permutation.matches("nicothekid:mossed_overgrown_jungle_planks")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_planks"));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_overgrown_jungle_log_side")) {
            const stateCardinalDirection = block.permutation.getState("minecraft:cardinal_direction");
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log_stripped", { "minecraft:block_face": stateCardinalDirection }));
          }
          if (block.permutation.matches("nicothekid:mossed_stripped_overgrown_jungle_log_top")) {
            block.setPermutation(BlockPermutation.resolve("nicothekid:overgrown_jungle_log_stripped"));
          }
        });
      }
      if (myceliumedBlocks.includes(block.typeId)) {
        system.run(() => {
          const pitchRange = Math.random() * (1.0 - 0.8) + 0.8;
          function spawnMyceliumSprouts () {
            const myceliumSprouts = new ItemStack ("nicothekid:mycelium_sprouts_small", 1);
            let randomChance = Math.random();
            if (itemUsed.getComponent("enchantable").hasEnchantment("silk_touch")) {
              block.dimension.spawnItem(myceliumSprouts, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
            }
            else if (itemUsed.getComponent("enchantable").hasEnchantment("fortune")) {
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 1) {
                if (randomChance <= 0.5) {
                  block.dimension.spawnItem(myceliumSprouts, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 2) {
                if (randomChance <= 0.75) {
                  block.dimension.spawnItem(myceliumSprouts, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
              if (itemUsed.getComponent("enchantable").getEnchantment("fortune").level == 3) {
                if (randomChance <= 1.0) {
                  block.dimension.spawnItem(myceliumSprouts, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
                }
              }
            }
            else {
              if (randomChance <= 0.25) {
                block.dimension.spawnItem(myceliumSprouts, { x: blockLocation.x + 0.5, y: blockLocation.y + 1.0, z: blockLocation.z + 0.5 });
              }
              else return;
            }
          }
          damageDurability ();
          spawnMyceliumSprouts ();
          block.dimension.playSound("use.gravel", blockLocation, { pitch: pitchRange, volume: 0.8 });
          if (block.permutation.matches("nicothekid:myceliumed_deepslate")) {
            block.setPermutation(BlockPermutation.resolve("minecraft:deepslate"));
          }
        });
      }
    }
  }
  else return;
});
