var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};

// data/system_template_esbuild/subscripts/menu.ts
import { world } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

// data/system_template_esbuild/subscripts/book_data.ts
var BLOCKS = [
  "vertical_slab",
  "tile",
  "lantern",
  "wooden_stool",
  "birdhouse",
  "direction_sign",
  "tree_sign",
  "planks_path",
  "bucket"
  // "log",
  // "stripped_log",
  // "wood",
  // "stripped_wood",
  // "planks",
  // "slab",
  // "double_slab",
  // "leaves",
  // "fence",
  // "fence_gate",
  // "trapdoor",
  // "door",
];
var Data = class {
  constructor() {
    // Constants
    __publicField(this, "TREES", [
      {
        typeId: "green_apple_tree",
        fruit: "green_apple",
        foods: ["golden_apple", "apple_pie", "apple_juice"],
        blocks: BLOCKS
      },
      {
        typeId: "pear_tree",
        fruit: "pear",
        foods: ["golden_pear", "pear_tart"],
        blocks: BLOCKS
      },
      {
        typeId: "peach_tree",
        fruit: "peach",
        foods: ["golden_peach", "peach_cobbler", "peach_ice_tea"],
        blocks: BLOCKS
      },
      {
        typeId: "wild_cherry_tree",
        fruit: "wild_cherry",
        foods: ["golden_wild_cherry", "wild_cherry_pie"],
        blocks: BLOCKS
      },
      {
        typeId: "orange_tree",
        fruit: "orange",
        foods: ["golden_orange", "orange_marmalade", "orange_juice"],
        blocks: BLOCKS
      },
      {
        typeId: "lemon_tree",
        fruit: "lemon",
        foods: ["golden_lemon", "lemon_meringue_pie", "lemonade"],
        blocks: BLOCKS
      },
      {
        typeId: "pecan_tree",
        fruit: "pecan",
        foods: ["golden_pecan", "pecan_pie", "pecan_milk"],
        blocks: BLOCKS
      },
      // {
      // 	typeId: "banana_tree",
      // 	fruit: "banana",
      // 	foods: ["golden_banana", "banana_bread"],
      // 	blocks: BLOCKS,
      // },
      {
        typeId: "maple_tree",
        fruit: "maple_syrup",
        foods: ["golden_maple_syrup", "pancakes"],
        blocks: BLOCKS
      },
      {
        typeId: "coconut_tree",
        fruit: "coconut",
        foods: ["golden_coconut", "coconut_water"],
        blocks: BLOCKS
      }
      // {
      // 	typeId: "almond_tree",
      // 	fruit: "almond",
      // 	foods: ["golden_almond", "almond_cookies", "almond_milk"],
      // 	blocks: BLOCKS,
      // },
    ]);
  }
};

// data/system_template_esbuild/subscripts/menu.ts
var ICON_PATH = "textures/ods/orch/ui";
var Menu = class {
  constructor() {
    __publicField(this, "TREES", new Data().TREES);
  }
  // This function opens the start menu
  startMenu(player) {
    const form = new ActionFormData().title({ translate: "ods_orch.ui.start_menu.title", with: ["\n"] }).body({ translate: "ods_orch.ui.start_menu.body", with: ["\n"] }).button(
      { translate: "ods_orch.ui.start_menu.button.trees", with: ["\n"] },
      `${ICON_PATH}/trees.png`
    ).button(
      { translate: "ods_orch.ui.start_menu.button.tools", with: ["\n"] },
      `textures/ods/orch/items/lumberjack_axe.png`
    ).button(
      {
        translate: "ods_orch.ui.start_menu.button.guide_book_crafting",
        with: ["\n"]
      },
      `textures/ods/orch/items/guide_book.png`
    );
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection === 0) {
        this.treesMenu(player);
      }
      if (response.selection === 1) {
        this.toolsMenu(player);
      }
      if (response.selection === 2) {
        this.guideBookCrafting(player);
      }
    });
  }
  // This function handles UI for when the password is incorrect
  guideBookCrafting(player) {
    let form = new ActionFormData().title({
      translate: `ods_orch.ui.guide_book_crafting.title`,
      with: ["\n"]
    }).body({ translate: `ods_orch.ui.guide_book_crafting.body`, with: ["\n"] }).button({ translate: `ods_orch.ui.back` });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0) {
        this.startMenu(player);
      }
    });
  }
  // This function opens the trees menu **********************************************************************
  treesMenu(player) {
    let form = new ActionFormData().title({ translate: "ods_orch.ui.trees_menu.title", with: ["\n"] }).body({ translate: "ods_orch.ui.trees_menu.body", with: ["\n"] }).button({ translate: `ods_orch.ui.back` });
    this.TREES.forEach((tree) => {
      form = form.button(
        {
          translate: `ods_orch.ui.trees_menu.button.${tree.typeId}`,
          with: ["\n"]
        },
        `textures/ods/orch/items/${tree.fruit}.png`
      );
    });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0 && response.selection === 0) {
        this.startMenu(player);
      }
      if (response.selection !== void 0 && response.selection > 0) {
        this.specificTreeMenu(player, this.TREES[response.selection - 1]);
      }
    });
  }
  specificTreeMenu(player, tree) {
    let form = new ActionFormData().title({ translate: `ods_orch.ui.${tree.typeId}.title`, with: ["\n"] }).body({ translate: `ods_orch.ui.${tree.typeId}.body`, with: ["\n"] }).button({ translate: `ods_orch.ui.back`, with: ["\n"] }).button(
      { translate: `ods_orch.ui.specific_tree.food`, with: ["\n"] },
      `textures/ods/orch/items/${tree.fruit}.png`
    ).button(
      { translate: `ods_orch.ui.specific_tree.blocks`, with: ["\n"] },
      `textures/ods/orch/blocks/${tree.typeId}_wood.png`
    );
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection === 0) {
        this.treesMenu(player);
      }
      if (response.selection === 1) {
        this.specificTreeFoodsMenu(player, tree);
      }
      if (response.selection === 2) {
        this.specificTreeBlocksMenu(player, tree);
      }
    });
  }
  specificTreeFoodsMenu(player, tree) {
    let form = new ActionFormData().title({
      translate: `ods_orch.ui.${tree.typeId}.foods.title`,
      with: ["\n"]
    }).body({
      translate: `ods_orch.ui.${tree.typeId}.foods.body`,
      with: ["\n"]
    }).button({ translate: `ods_orch.ui.back`, with: ["\n"] });
    form = form.button(
      {
        translate: `ods_orch.ui.${tree.typeId}.foods.button.${tree.fruit}`,
        with: ["\n"]
      },
      `textures/ods/orch/items/${tree.fruit}.png`
    );
    tree.foods.forEach((food) => {
      form = form.button(
        {
          translate: `ods_orch.ui.${tree.typeId}.foods.button.${food}`,
          with: ["\n"]
        },
        `${ICON_PATH}/${food}.png`
      );
    });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0 && response.selection === 0) {
        this.specificTreeMenu(player, tree);
      }
      if (response.selection !== void 0 && response.selection === 1) {
        this.foodMenu(player, tree, tree.fruit);
      }
      if (response.selection !== void 0 && response.selection > 1) {
        this.foodMenu(player, tree, tree.foods[response.selection - 2]);
      }
    });
  }
  foodMenu(player, tree, food) {
    let form = new ActionFormData().title({
      translate: `ods_orch.ui.${tree.typeId}.foods.${food}.title`,
      with: ["\n"]
    }).body({
      translate: `ods_orch.ui.${tree.typeId}.foods.${food}.body`,
      with: ["\n"]
    }).button({ translate: `ods_orch.ui.back` });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0) {
        this.specificTreeFoodsMenu(player, tree);
      }
    });
  }
  specificTreeBlocksMenu(player, tree) {
    let form = new ActionFormData().title({
      translate: `ods_orch.ui.${tree.typeId}.blocks.title`,
      with: ["\n"]
    }).body({
      translate: `ods_orch.ui.${tree.typeId}.blocks.body`,
      with: ["\n"]
    }).button({ translate: `ods_orch.ui.back` });
    tree.blocks.forEach((block) => {
      form = form.button(
        {
          translate: `ods_orch.ui.${tree.typeId}.blocks.button.${block}`,
          with: ["\n"]
        },
        `${ICON_PATH}/${block}.png`
      );
    });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0 && response.selection === 0) {
        this.specificTreeMenu(player, tree);
      }
      if (response.selection !== void 0 && response.selection > 0) {
        this.blockMenu(player, tree, tree.blocks[response.selection - 1]);
      }
    });
  }
  // Blocks Menu ********************************************************************************************************
  blockMenu(player, tree, block) {
    let form = new ActionFormData().title({
      translate: `ods_orch.ui.${tree.typeId}.blocks.${block}.title`,
      with: ["\n"]
    }).body({
      translate: `ods_orch.ui.${tree.typeId}.blocks.${block}.body`,
      with: ["\n"]
    }).button({ translate: `ods_orch.ui.back` });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0) {
        this.specificTreeBlocksMenu(player, tree);
      }
    });
  }
  // Tools Menu *******************************************************
  // This function opens the tools menu
  toolsMenu(player) {
    let form = new ActionFormData().title({ translate: "ods_orch.ui.tools_menu.title", with: ["\n"] }).body({ translate: "ods_orch.ui.tools_menu.body", with: ["\n"] }).button({ translate: `ods_orch.ui.back` }).button(
      { translate: `item.ods_orch:fruit_picker`, with: ["\n"] },
      `textures/ods/orch/items/fruit_picker.png`
    ).button(
      { translate: `item.ods_orch:lumberjack_axe`, with: ["\n"] },
      `textures/ods/orch/items/lumberjack_axe.png`
    );
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0 && response.selection === 0) {
        this.startMenu(player);
      }
      if (response.selection !== void 0 && response.selection === 1) {
        this.fruitPickerMenu(player);
      }
      if (response.selection !== void 0 && response.selection === 2) {
        this.lumberjackAxeMenu(player);
      }
    });
  }
  fruitPickerMenu(player) {
    let form = new ActionFormData().title({ translate: `item.ods_orch:fruit_picker`, with: ["\n"] }).body({
      translate: `ods_orch.ui.tools_menu.fruit_picker.body`,
      with: ["\n"]
    }).button({ translate: `ods_orch.ui.back` });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0) {
        this.toolsMenu(player);
      }
    });
  }
  lumberjackAxeMenu(player) {
    let form = new ActionFormData().title({ translate: `item.ods_orch:lumberjack_axe`, with: ["\n"] }).body({
      translate: `ods_orch.ui.tools_menu.lumberjack_axe.body`,
      with: ["\n"]
    }).button({ translate: `ods_orch.ui.back` });
    form.show(player).then((response) => {
      if (response.canceled || response === void 0) {
        return;
      }
      if (response.selection !== void 0) {
        this.toolsMenu(player);
      }
    });
  }
};
var MENU = new Menu();
world.afterEvents.itemUse.subscribe((event) => {
  let player = event.source;
  let itemStack = event.itemStack;
  if (itemStack.typeId === "ods_orch:guide_book") {
    MENU.startMenu(player);
  }
});

// data/system_template_esbuild/subscripts/giving.ts
import {
  EntityComponentTypes,
  EquipmentSlot,
  ItemStack,
  system as system2,
  world as world2
} from "@minecraft/server";
var VERSION2 = "1_0_0";
var DISPLAY_VERSION = "";
var PREFIX2 = "ODS_ORCH";
var LORE_02 = `\xA76More Trees Add-On\xA7r ${DISPLAY_VERSION}`;
var LORE_12 = "By Odyssey Builds";
world2.afterEvents.playerJoin.subscribe((event) => {
  let player = world2.getEntity(event.playerId);
  checkPlayer(player);
});
function checkPlayer(player) {
  try {
    let testBlock = player.dimension.getBlock(player.location);
    if (testBlock === void 0) {
      system2.runTimeout(() => {
        checkPlayer(player);
      }, 5);
      return;
    }
  } catch (error) {
    system2.runTimeout(() => {
      checkPlayer(player);
    }, 5);
    return;
  }
  giveTheBook(player);
  let location = player.location;
  addonApplied(player, location);
}
function addonApplied(player, originalLocation) {
  let tagged = player.hasTag(`${PREFIX2}_${VERSION2}_ADDON_APPLIED`);
  if (tagged)
    return;
  if (Math.abs(originalLocation.x - player.location.x) > 1 || Math.abs(originalLocation.z - player.location.z) > 1) {
    system2.runTimeout(() => {
      player.playSound("note.bell");
      player.sendMessage({ translate: "ods_orch.addon_applied" });
      player.addTag(`${PREFIX2}_${VERSION2}_ADDON_APPLIED`);
    }, 20);
  } else {
    system2.runTimeout(() => {
      addonApplied(player, originalLocation);
    }, 20);
  }
}
function giveTheBook(player) {
  let tagged = player.hasTag(`${PREFIX2}_${VERSION2}_BOOK`);
  if (tagged)
    return;
  let book = new ItemStack("ods_orch:guide_book", 1);
  let peachSapling = new ItemStack("ods_orch:peach_tree_sapling_placer", 1);
  let greenAppleSapling = new ItemStack(
    "ods_orch:green_apple_tree_sapling_placer",
    1
  );
  let wildCherrySapling = new ItemStack(
    "ods_orch:wild_cherry_tree_sapling_placer",
    1
  );
  let peachFruit = new ItemStack("ods_orch:peach", 3);
  let greenAppleFruit = new ItemStack("ods_orch:green_apple", 3);
  let wildCherryFruit = new ItemStack("ods_orch:wild_cherry", 3);
  book.setLore([`${LORE_02}`, `${LORE_12}`]);
  player.dimension.spawnItem(book, player.location);
  player.dimension.spawnItem(peachSapling, player.location);
  player.dimension.spawnItem(greenAppleSapling, player.location);
  player.dimension.spawnItem(wildCherrySapling, player.location);
  player.dimension.spawnItem(peachFruit, player.location);
  player.dimension.spawnItem(greenAppleFruit, player.location);
  player.dimension.spawnItem(wildCherryFruit, player.location);
  player.addTag(`${PREFIX2}_${VERSION2}_BOOK`);
}
function addLore(player) {
  let itemStack = getItemHeld(player);
  if (itemStack?.typeId.includes("ods_orch:guide_book") && itemStack.getLore().length === 0) {
    itemStack.setLore([`${LORE_02}`, `${LORE_12}`]);
    const playerEquippableComp = player.getComponent(EntityComponentTypes.Equippable);
    playerEquippableComp.setEquipment(EquipmentSlot.Mainhand, itemStack);
  }
}
function getItemHeld(player) {
  const playerEquippableComp = player.getComponent(EntityComponentTypes.Equippable);
  if (!playerEquippableComp)
    return;
  let heldItem = playerEquippableComp.getEquipment(EquipmentSlot.Mainhand);
  return heldItem;
}
system2.runInterval(() => {
  world2.getAllPlayers().forEach((player) => addLore(player));
}, 40);

// data/system_template_esbuild/subscripts/golden_foods.ts
import {
  ItemStack as ItemStack2,
  world as world3
} from "@minecraft/server";
var SECOND_IN_TICKS = 20;
var FOODS = [
  // If you change amplifiers, be sure to update display names in the _scope.json of this system
  // {
  // 	identifier: "almond",
  // 	effects: [
  // 		{
  // 			effect_name: "invisibility",
  // 			amplifier: 4,
  // 			duration: 300, // seconds
  // 		},
  // 	],
  // },
  // {
  // 	identifier: "banana",
  // 	effects: [
  // 		{
  // 			effect_name: "jump_boost",
  // 			amplifier: 4,
  // 			duration: 40, // seconds
  // 		},
  // 	],
  // },
  {
    identifier: "coconut",
    effects: [
      {
        effect_name: "resistance",
        amplifier: 3,
        duration: 40
        // seconds
      }
    ]
  },
  {
    identifier: "lemon",
    effects: [
      {
        effect_name: "haste",
        amplifier: 3,
        duration: 30
        // seconds
      }
    ]
  },
  {
    identifier: "maple_syrup",
    effects: [
      {
        effect_name: "health_boost",
        amplifier: 4,
        duration: 40
        // seconds
      }
    ]
  },
  {
    identifier: "orange",
    effects: [
      {
        effect_name: "levitation",
        amplifier: 3,
        duration: 10
        // seconds
      },
      {
        effect_name: "slow_falling",
        amplifier: 0,
        duration: 15
        // seconds
      }
    ]
  },
  {
    identifier: "peach",
    effects: [
      {
        effect_name: "instant_health",
        amplifier: 2,
        duration: 1
        // seconds
      }
    ]
  },
  {
    identifier: "pear",
    effects: []
    // Has no effect, but better nutrition and saturation than golden carrot but it's eaten slower
  },
  {
    identifier: "pecan",
    effects: [
      {
        effect_name: "conduit_power",
        amplifier: 5,
        duration: 45
        // seconds
      }
    ]
  },
  {
    identifier: "wild_cherry",
    effects: []
    // Has no effect, but the same nutrition and saturation than golden carrot, but it's eaten faster.
  }
];
function foodEaten(player, itemStack) {
  let food = FOODS.find(
    (element) => element.identifier === itemStack.typeId.replace("ods_orch:golden_", "")
  );
  if (food !== void 0 && food?.effects.length > 0) {
    food.effects.forEach((effect) => {
      let effect_name = effect.effect_name;
      let amplifier = effect.amplifier;
      let duration = effect.duration * SECOND_IN_TICKS;
      player.addEffect(effect_name, duration, {
        amplifier,
        showParticles: true
      });
    });
  }
}
world3.afterEvents.itemCompleteUse.subscribe((event) => {
  let player = event.source;
  let itemStack = event.itemStack;
  if (itemStack === void 0)
    return;
  if (itemStack.typeId.includes("ods_orch:") && itemStack.typeId.includes("golden")) {
    foodEaten(player, itemStack);
  }
});

// data/system_template_esbuild/subscripts/fruit_picker.ts
import {
  EntityComponentTypes as EntityComponentTypes3,
  EquipmentSlot as EquipmentSlot3,
  ItemComponentTypes as ItemComponentTypes2,
  system as system4,
  world as world4
} from "@minecraft/server";
var FruitPicker = class {
  constructor() {
  }
  pickFruit(player, itemStack, targetBlock) {
    player.playSound("mob.witch.throw", {
      location: player.location,
      pitch: 1.5,
      volume: 1
    });
    if (targetBlock === void 0 || targetBlock.isAir || targetBlock.isLiquid) {
      return;
    }
    let blocks = this.getBlocksFromVolume(targetBlock);
    if (blocks.length === 0)
      return;
    let delay = 0;
    blocks.forEach((block) => {
      delay++;
      system4.runTimeout(() => {
        this.pickFruitVFX(block);
        block.dimension.runCommandAsync(
          `/setblock ${block.location.x} ${block.location.y} ${block.location.z} minecraft:air [] destroy`
        );
      }, delay);
    });
    durability(itemStack, player, blocks.length);
  }
  pickFruitVFX(block) {
    block.dimension.spawnParticle(
      "minecraft:crop_growth_emitter",
      block.center()
    );
  }
  getBlocksFromVolume(block) {
    let blocks = [];
    let volumeSize = 2;
    const volumeMinialPosition = {
      x: block.location.x - volumeSize / 2,
      y: block.location.y - volumeSize / 2,
      z: block.location.z - volumeSize / 2
    };
    let coordinatesToCheck = volumeMinialPosition;
    for (let dx = 0; dx < volumeSize + 1; dx++) {
      for (let dy = 0; dy < volumeSize + 1; dy++) {
        for (let dz = 0; dz < volumeSize + 1; dz++) {
          coordinatesToCheck = {
            x: volumeMinialPosition.x + dx,
            y: volumeMinialPosition.y + dy,
            z: volumeMinialPosition.z + dz
          };
          let blockToCheck = block.dimension.getBlock(coordinatesToCheck);
          if (!blockToCheck)
            return [];
          let checkOdyssey = blockToCheck.typeId.includes("ods_orch:");
          let checkFruit = blockToCheck.typeId.includes("fruit");
          if (checkFruit && checkOdyssey) {
            blocks.push(blockToCheck);
          }
        }
      }
    }
    return blocks;
  }
};
var FRUIT_PICKER = new FruitPicker();
world4.afterEvents.itemStartUseOn.subscribe((event) => {
  let player = event.source;
  let itemStack = event.itemStack;
  let block = event.block;
  if (itemStack === void 0 || block === void 0)
    return;
  if (itemStack.typeId === "ods_orch:fruit_picker") {
    FRUIT_PICKER.pickFruit(player, itemStack, block);
  }
});
function durability(itemStack, player, amount) {
  let durabilityComponent = itemStack.getComponent(ItemComponentTypes2.Durability);
  let playerEquippableComp = player.getComponent(EntityComponentTypes3.Equippable);
  if (durabilityComponent.damage + amount >= durabilityComponent.maxDurability) {
    player.playSound("random.break");
    playerEquippableComp.setEquipment(EquipmentSlot3.Mainhand, void 0);
  } else {
    let currentDur = durabilityComponent.damage;
    durabilityComponent.damage = currentDur + amount;
    playerEquippableComp.setEquipment(EquipmentSlot3.Mainhand, itemStack);
  }
}

// data/system_template_esbuild/subscripts/lumberjack_axe.ts
import {
  EntityComponentTypes as EntityComponentTypes4,
  EquipmentSlot as EquipmentSlot4,
  ItemComponentTypes as ItemComponentTypes3,
  system as system5,
  world as world5
} from "@minecraft/server";
var LumberjackAxe = class {
  constructor() {
    __publicField(this, "RADIUS", 4);
  }
  cutTreeStart(sourceBlock) {
    const middleX = sourceBlock.location.x;
    const middleZ = sourceBlock.location.z;
    if (!this.testForWood(sourceBlock))
      return;
    const type = sourceBlock.typeId.replace("wood", "").replace("log", "").replace("stem", "").replace("wart_block", "").replace("crimson", "nether");
    const blocksToCut = [];
    blocksToCut.push(sourceBlock);
    const blocksAround = this.getBlocksAroundStart(sourceBlock);
    const processedLocations = /* @__PURE__ */ new Set();
    const maxBlocksToCut = 350;
    const locationString = (block) => `${block.location.x},${block.location.y},${block.location.z}`;
    processedLocations.add(locationString(sourceBlock));
    while (blocksAround.length > 0 && blocksToCut.length < maxBlocksToCut) {
      const block = blocksAround.shift();
      if (!block || !block.typeId.includes(type))
        continue;
      if (Math.abs(block.location.x - middleX) > this.RADIUS || Math.abs(block.location.z - middleZ) > this.RADIUS)
        continue;
      const blockLocStr = locationString(block);
      if (!processedLocations.has(blockLocStr)) {
        processedLocations.add(blockLocStr);
        blocksToCut.push(block);
        blocksAround.push(...this.getBlocksAround(block));
      }
    }
    blocksToCut.forEach((block, index) => {
      system5.runTimeout(() => {
        block.dimension.runCommandAsync(
          `/setblock ${block.location.x} ${block.location.y} ${block.location.z} minecraft:air [] destroy`
        );
      }, index + 1);
    });
  }
  getBlocksAroundStart(sourceBlock) {
    let blocksAroundToCheck = [
      sourceBlock.north(1),
      sourceBlock.south(1),
      sourceBlock.east(1),
      sourceBlock.west(1),
      sourceBlock.above(1),
      sourceBlock.above(1)?.north(1),
      sourceBlock.above(1)?.south(1),
      sourceBlock.above(1)?.east(1),
      sourceBlock.above(1)?.west(1)
    ];
    let blocksAround = [];
    blocksAroundToCheck.forEach((element) => {
      if (element !== void 0 && this.testForWood(element)) {
        blocksAround.push(element);
      }
    });
    return blocksAround;
  }
  getBlocksAround(sourceBlock) {
    let blocksAroundToCheck = [
      sourceBlock.north(1),
      sourceBlock.south(1),
      sourceBlock.east(1),
      sourceBlock.west(1),
      sourceBlock.above(1),
      sourceBlock.below(1),
      sourceBlock.above(1)?.north(1),
      sourceBlock.above(1)?.south(1),
      sourceBlock.above(1)?.east(1),
      sourceBlock.above(1)?.west(1),
      sourceBlock.below(1)?.north(1),
      sourceBlock.below(1)?.south(1),
      sourceBlock.below(1)?.east(1),
      sourceBlock.below(1)?.west(1)
    ];
    let blocksAround = [];
    blocksAroundToCheck.forEach((element) => {
      if (element !== void 0 && this.testForWood(element)) {
        blocksAround.push(element);
      }
    });
    return blocksAround;
  }
  testForWood(block) {
    if (block.typeId.includes("wood") || block.typeId.includes("log") || block.typeId.includes("stem") || block.typeId.includes("wart") || block.typeId.includes("leaves") || block.typeId.includes("fruit")) {
      return true;
    } else {
      return false;
    }
  }
};
var LUMBERJACK_AXE = new LumberjackAxe();
world5.beforeEvents.playerBreakBlock.subscribe((event) => {
  let sourceBlock = event.block;
  let itemStack = getItemHeld2(event.player);
  let player = event.player;
  if (itemStack === void 0 || sourceBlock === void 0)
    return;
  if (itemStack.typeId === "ods_orch:lumberjack_axe" && (sourceBlock.typeId.includes("wood") || sourceBlock.typeId.includes("log") || sourceBlock.typeId.includes("stem"))) {
    LUMBERJACK_AXE.cutTreeStart(sourceBlock, true);
    system5.run(() => {
      durability2(itemStack, player);
    });
  }
});
function getItemHeld2(player) {
  const playerEquippableComp = player.getComponent(EntityComponentTypes4.Equippable);
  if (!playerEquippableComp)
    return;
  let heldItem = playerEquippableComp.getEquipment(EquipmentSlot4.Mainhand);
  return heldItem;
}
function durability2(itemStack, player) {
  let durabilityComponent = itemStack.getComponent(ItemComponentTypes3.Durability);
  let playerEquippableComp = player.getComponent(EntityComponentTypes4.Equippable);
  if (durabilityComponent.damage >= durabilityComponent.maxDurability) {
    player.playSound("random.break");
    playerEquippableComp.setEquipment(EquipmentSlot4.Mainhand, void 0);
  } else {
    let currentDur = durabilityComponent.damage;
    durabilityComponent.damage = currentDur + durabilityComponent.maxDurability * 0.05;
    playerEquippableComp.setEquipment(EquipmentSlot4.Mainhand, itemStack);
  }
}

// data/system_template_esbuild/subscripts/trees_events.ts
import {
  Direction as Direction3,
  ItemStack as ItemStack8,
  system as system11,
  world as world11
} from "@minecraft/server";

// data/system_template_esbuild/subscripts/growing.ts
import {
  system as system7,
  world as world7,
  StructureRotation,
  Direction
} from "@minecraft/server";

// data/system_template_esbuild/subscripts/utilities.ts
import {
  EntityComponentTypes as EntityComponentTypes5,
  EquipmentSlot as EquipmentSlot5
} from "@minecraft/server";
var Utilities = class {
  constructor() {
  }
  randInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  getRandomElement(array) {
    const randomIndex = Math.floor(Math.random() * array.length);
    return array[randomIndex];
  }
  getItemHeld(player) {
    const playerEquippableComp = player.getComponent(EntityComponentTypes5.Equippable);
    if (!playerEquippableComp)
      return;
    let heldItem = playerEquippableComp.getEquipment(EquipmentSlot5.Mainhand);
    return heldItem;
  }
};

// data/system_template_esbuild/subscripts/data.ts
var Data2 = class {
  constructor() {
    // Constants
    __publicField(this, "GROWING_MODIFIER", 1);
    // This reflects the chance for the block to tick upon random tick. 1 = 100%.
    __publicField(this, "VARIANTS_NUM", 3);
    // Variants for the trees. The last one is the "weird one", kinda like big variant of the vanilla oak
    __publicField(this, "MAX_GROWTH_STATE", 3);
    __publicField(this, "MAX_FRUIT_STATE", 1);
    __publicField(this, "MAX_DECAY_STATE", 1);
    __publicField(this, "TREES", [
      {
        typeId: "green_apple_tree",
        height: 15,
        width: 7,
        fruitGrowth: 80,
        saplingDropChance: 8
        // 2% is for vanilla oak afaik
      },
      {
        typeId: "pear_tree",
        height: 15,
        width: 7,
        fruitGrowth: 70,
        saplingDropChance: 9
        // 2% is for vanilla oak afaik
      },
      {
        typeId: "peach_tree",
        height: 15,
        width: 7,
        fruitGrowth: 60,
        saplingDropChance: 6
        // 2% is for vanilla oak afaik
      },
      {
        typeId: "wild_cherry_tree",
        height: 15,
        width: 7,
        fruitGrowth: 50,
        saplingDropChance: 7
        // 2% is for vanilla oak afaik
      },
      {
        typeId: "orange_tree",
        height: 15,
        width: 7,
        fruitGrowth: 75,
        saplingDropChance: 14
        // 2% is for vanilla oak afaik
      },
      {
        typeId: "lemon_tree",
        height: 15,
        width: 7,
        fruitGrowth: 65,
        saplingDropChance: 8
        // 2% is for vanilla oak afaik
      },
      {
        typeId: "pecan_tree",
        height: 15,
        width: 7,
        fruitGrowth: 40,
        saplingDropChance: 3
        // 2% is for vanilla oak afaik
      },
      // {
      // 	typeId: "banana_tree",
      // 	height: 15,
      // 	width: 7,
      // 	fruitGrowth: 90,
      // saplingDropChance: 5 // 2% is for vanilla oak afaik
      // },
      {
        typeId: "maple_tree",
        height: 15,
        width: 7,
        fruitGrowth: 50,
        saplingDropChance: 3
        // 2% is for vanilla oak afaik
      },
      {
        typeId: "coconut_tree",
        height: 15,
        width: 7,
        fruitGrowth: 85,
        saplingDropChance: 10
        // 2% is for vanilla oak afaik
      }
      // {
      // 	typeId: "almond_tree",
      // 	height: 15,
      // 	width: 7,
      // 	fruitGrowth: 55,
      // saplingDropChance: 5 // 2% is for vanilla oak afaik
      // },
    ]);
    __publicField(this, "SOIL_TYPES", [
      "minecraft:farmland",
      "minecraft:dirt",
      "minecraft:dirt_with_roots",
      "minecraft:coarse_dirt",
      "minecraft:grass_block",
      "minecraft:moss_block",
      "minecraft:mud",
      "minecraft:muddy_mangrove_roots"
    ]);
  }
};

// data/system_template_esbuild/subscripts/growing.ts
var Growing = class {
  constructor() {
    __publicField(this, "UTILITIES");
    __publicField(this, "DATA");
    this.UTILITIES = new Utilities();
    this.DATA = new Data2();
  }
  // Methods
  growingState(block) {
    let growingState = block.permutation.getState("ods_orch:growing_state_tree");
    let structure = this.drawStructure(block);
    if (structure === void 0)
      return;
    if (growingState === this.DATA.MAX_GROWTH_STATE) {
      for (let index = 1; index < structure.height; index++) {
        let blockToCheck = block.dimension.getBlock({
          x: block.location.x,
          y: block.location.y + index,
          z: block.location.z
        });
        if (blockToCheck?.typeId !== "minecraft:air" && blockToCheck?.typeId !== "minecraft:light_block") {
          return;
        }
      }
      for (let dx = 0; dx < 4; dx += 2) {
        for (let dy = 1; dy < structure.height - 1; dy += 2) {
          for (let dz = 0; dz < 4; dz += 2) {
            let blockToCheck = block.dimension.getBlock({
              x: block.location.x - 1 + dx,
              y: block.location.y + dy,
              z: block.location.z - 1 + dz
            });
            if (blockToCheck?.typeId !== "minecraft:air" && blockToCheck?.typeId !== "minecraft:light_block") {
              return;
            }
          }
        }
      }
      block.dimension.runCommandAsync("/fill ~~~~~~ air []");
      let structureTest = world7.structureManager.get(
        `ods_orch:${structure.typeId}_${structure.variant}`
      );
      if (!structureTest) {
        block.dimension.runCommandAsync(
          `setblock ${block.location.x} ${block.location.y} ${block.location.z} minecraft:redstone_block`
        );
        world7.sendMessage("structure doesnt exist");
        return;
      }
      world7.structureManager.place(
        `ods_orch:${structure.typeId}_${structure.variant}`,
        block.dimension,
        {
          x: block.location.x - 3,
          // Don't change this, all structures should just be saved as 5x5 for simplicity, it's 3x3 for testing.
          y: block.location.y,
          z: block.location.z - 3
          // Don't change this, all structures should just be saved as 5x5 for simplicity, it's 3x3 for testing.
        },
        {
          rotation: structure.rotation
        }
      );
    } else if (growingState < this.DATA.MAX_GROWTH_STATE) {
      growingState++;
      block.setPermutation(
        block.permutation.withState("ods_orch:growing_state_tree", growingState)
      );
    }
  }
  drawStructure(block) {
    let typeId = block.typeId.replace("ods_orch:", "").replace("_sapling", "");
    let variant = 0;
    let randomInt = this.UTILITIES.randInt(0, 100);
    if (randomInt <= 90) {
      variant = this.UTILITIES.randInt(0, this.DATA.VARIANTS_NUM - 2);
    } else if (randomInt > 90) {
      variant = this.DATA.VARIANTS_NUM - 1;
    }
    let rotation = StructureRotation.Rotate90;
    switch (this.UTILITIES.randInt(0, 3)) {
      case 0:
        rotation = StructureRotation.None;
        break;
      case 1:
        rotation = StructureRotation.Rotate90;
        break;
      case 2:
        rotation = StructureRotation.Rotate180;
        break;
      case 3:
        rotation = StructureRotation.Rotate270;
        break;
      default:
        break;
    }
    let dataObject = this.DATA.TREES.find((item) => item.typeId === typeId);
    if (dataObject?.typeId !== void 0) {
      let height = dataObject.height;
      let width = dataObject.width;
      return {
        typeId,
        variant,
        rotation,
        height,
        width
      };
    } else {
      return void 0;
    }
  }
  bonemeal(event) {
    let block = event.block;
    let player = event.source;
    let checkOdyssey = event.block.typeId.includes("ods_orch:");
    let checkSapling = event.block.typeId.includes("sapling");
    if (checkOdyssey === false)
      return;
    if (event.itemStack.typeId === "minecraft:bone_meal" && checkOdyssey && checkSapling) {
      player.runCommandAsync("/clear @s bone_meal 0 1");
      block.dimension.runCommandAsync(
        `/particle minecraft:crop_growth_emitter ${block.location.x} ${block.location.y + 0.5} ${block.location.z}`
      );
      block.dimension.runCommandAsync(
        `/playsound item.bone_meal.use @a  ${block.location.x} ${block.location.y} ${block.location.z}`
      );
      system7.run(() => {
        this.growingState(block);
      });
    }
  }
  /**
   * This function checks for proper block under the sapling, otherwise cannot be placed
   */
  checkForSoil(event) {
    let block = event.block;
    let blockFace = event.blockFace === Direction.Up;
    let checkOdyssey = event.itemStack.typeId.includes("ods_orch:");
    let checkSapling = event.itemStack.typeId.includes("sapling");
    if (checkOdyssey === false)
      return;
    let canPlace = 0;
    if (checkSapling) {
      let blockBelow = block.below(0)?.location;
      let blockToCheck;
      if (blockBelow === void 0)
        return;
      blockToCheck = block.dimension.getBlock(blockBelow)?.typeId;
      if (blockToCheck === void 0)
        return;
      this.DATA.SOIL_TYPES.forEach((element) => {
        if (blockToCheck === element)
          canPlace++;
      });
      if (canPlace === 0 || blockFace === false)
        event.cancel = true;
    }
  }
};

// data/system_template_esbuild/subscripts/tools_usage.ts
import {
  system as system8,
  ItemStack as ItemStack6,
  ItemComponentTypes as ItemComponentTypes4,
  EntityComponentTypes as EntityComponentTypes6,
  EquipmentSlot as EquipmentSlot6
} from "@minecraft/server";
var ToolsUsage = class {
  constructor() {
    __publicField(this, "UTILITIES");
    __publicField(this, "DATA");
    this.UTILITIES = new Utilities();
    this.DATA = new Data2();
  }
  stripping(event) {
    let sourceBlock = event.block;
    let checkOdyssey = event.block.typeId.includes("ods_orch:");
    let checkLog = event.block.typeId.includes("log");
    let checkWood = event.block.typeId.includes("wood");
    let checkStripped = !event.block.typeId.includes("stripped");
    if (checkOdyssey === false)
      return;
    if ((event.itemStack.typeId.includes("axe") || event.itemStack.typeId.includes("chainsaw")) && !event.itemStack.typeId.includes("pickaxe") && !event.itemStack.typeId.includes("pick_axe") && (checkLog || checkWood) && checkStripped) {
      let state = sourceBlock.permutation.getState("minecraft:facing_direction");
      let strippedLogTypeId = sourceBlock.typeId.replace(/log/, "stripped_log");
      let strippedWoodTypeId = sourceBlock.typeId.replace(
        /wood/,
        "stripped_wood"
      );
      let location = sourceBlock.location;
      if (checkLog) {
        sourceBlock.dimension.runCommandAsync(
          `/playsound fall.wood @a ${location.x} ${location.y} ${location.z} 1 1`
        );
        sourceBlock.dimension.runCommandAsync(
          `/setblock ${location.x} ${location.y} ${location.z} ${strippedLogTypeId} ["minecraft:facing_direction"="${state}"]`
        );
      } else if (checkWood) {
        sourceBlock.dimension.runCommandAsync(
          `/playsound fall.wood @a ${location.x} ${location.y} ${location.z} 1 1`
        );
        sourceBlock.dimension.runCommandAsync(
          `/setblock ${location.x} ${location.y} ${location.z} ${strippedWoodTypeId}`
        );
      }
    }
  }
  shears(block, player, itemStack) {
    let drop = new ItemStack6(block.typeId, 1);
    let location = block.location;
    system8.run(() => {
      this.shearsDurability(itemStack, player);
      block.dimension.spawnItem(drop, location);
      block.dimension.runCommandAsync(
        `/setblock ${location.x} ${location.y} ${location.z} minecraft:air [] destroy`
      );
    });
  }
  shearsDurability(itemStack, player) {
    let durabilityComponent = itemStack.getComponent(ItemComponentTypes4.Durability);
    let playerEquippableComp = player.getComponent(EntityComponentTypes6.Equippable);
    if (durabilityComponent.damage >= durabilityComponent.maxDurability) {
      player.playSound("random.break");
      playerEquippableComp.setEquipment(EquipmentSlot6.Mainhand, void 0);
    } else {
      let currentDur = durabilityComponent.damage;
      durabilityComponent.damage = currentDur + 1;
      playerEquippableComp.setEquipment(EquipmentSlot6.Mainhand, itemStack);
    }
  }
};

// data/system_template_esbuild/subscripts/derived_blocks.ts
import {
  world as world9
} from "@minecraft/server";
var DerivedBlocks = class {
  constructor() {
    __publicField(this, "UTILITIES");
    __publicField(this, "DATA");
    this.UTILITIES = new Utilities();
    this.DATA = new Data2();
  }
  logPlacing(event) {
    let sourceBlock = event.block;
    let sourceBlockFace = event.blockFace.toLowerCase();
    let targetBlock = event.itemStack.typeId;
    sourceBlock.dimension.playSound("dig.wood", sourceBlock.location, {
      volume: 1,
      pitch: 1
    });
    let targetBlockLocation = {
      x: sourceBlock.location.x,
      y: sourceBlock.location.y,
      z: sourceBlock.location.z
    };
    switch (sourceBlockFace) {
      case "north":
        targetBlockLocation.z--;
        break;
      case "south":
        targetBlockLocation.z++;
        break;
      case "east":
        targetBlockLocation.x++;
        break;
      case "west":
        targetBlockLocation.x--;
        break;
      case "up":
        targetBlockLocation.y++;
        break;
      case "down":
        targetBlockLocation.y--;
        break;
      default:
        break;
    }
    sourceBlock.dimension.runCommandAsync(
      `/setblock ${targetBlockLocation.x} ${targetBlockLocation.y} ${targetBlockLocation.z} ${targetBlock} ["minecraft:facing_direction"="${sourceBlockFace}"]`
    );
  }
  doubleSlabPlacing(event, vertical) {
    let treeType;
    this.DATA.TREES.forEach((element) => {
      if (event.block.typeId.includes(element.typeId)) {
        treeType = element.typeId;
        event.block.dimension.playSound("step.wood", event.block.location, {
          volume: 1,
          pitch: 1
        });
        if (vertical) {
          event.block.dimension.setBlockType(
            event.block.location,
            `ods_orch:${treeType}_double_vertical_slab`
          );
        } else {
          event.block.dimension.setBlockType(
            event.block.location,
            `ods_orch:${treeType}_double_slab`
          );
        }
        return;
      }
    });
  }
  tilePlacing(event, tilePart, direction) {
    if (tilePart >= 8)
      return;
    let treeType;
    this.DATA.TREES.forEach((element) => {
      if (event.block.typeId.includes(element.typeId)) {
        treeType = element.typeId;
        event.block.dimension.playSound("step.wood", event.block.location, {
          volume: 1,
          pitch: 1
        });
        event.block.dimension.setBlockType(
          event.block.location,
          `ods_orch:${treeType}_tile`
        );
        let newBlock = event.block.dimension.getBlock(event.block.location);
        if (newBlock === void 0)
          return;
        let targetBlock = newBlock.dimension.getBlock(newBlock.location);
        targetBlock?.setPermutation(
          targetBlock.permutation.withState("ods_orch:tile_part", tilePart + 1)
        );
        targetBlock = newBlock.dimension.getBlock(newBlock.location);
        targetBlock?.setPermutation(
          targetBlock.permutation.withState(
            "minecraft:cardinal_direction",
            direction
          )
        );
        return;
      }
    });
  }
  // ******************************** FENCES ********************************
  fencePlacing(sourceBlock, iterateAround) {
    if (iterateAround && !this.blockNorth(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockNorth(sourceBlock)?.typeId?.includes("fence") && !this.blockSouth(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockSouth(sourceBlock)?.typeId?.includes("fence") && !this.blockEast(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockEast(sourceBlock)?.typeId?.includes("fence") && !this.blockWest(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockWest(sourceBlock)?.typeId?.includes("fence")) {
      return;
    }
    let checkOdyssey = sourceBlock.typeId.includes("ods_orch:");
    let checkBlock = sourceBlock.typeId.includes("fence") && !sourceBlock.typeId.includes("gate");
    if (!iterateAround && !(checkOdyssey && checkBlock)) {
      return;
    }
    let connectionAmount = this.checkFenceConnectionsNum(sourceBlock);
    let connectionDir = this.checkFenceConnectionsDir(
      sourceBlock,
      connectionAmount
    );
    let newBlockTypeId = sourceBlock.typeId.replace("_0", "").replace("_1", "").replace("_2_s", "").replace("_2", "").replace("_3", "").replace("_4", "");
    newBlockTypeId = newBlockTypeId + `_${connectionAmount}`;
    if (connectionAmount === 2 && (this.blockNorth(sourceBlock) && this.blockSouth(sourceBlock) && !this.blockEast(sourceBlock) && !this.blockWest(sourceBlock) || !this.blockNorth(sourceBlock) && !this.blockSouth(sourceBlock) && this.blockEast(sourceBlock) && this.blockWest(sourceBlock))) {
      newBlockTypeId = newBlockTypeId + "_s";
    }
    if (!iterateAround) {
      sourceBlock.dimension.setBlockType(sourceBlock.location, newBlockTypeId);
      let targetBlock = sourceBlock.dimension.getBlock(sourceBlock.location);
      targetBlock?.setPermutation(
        targetBlock.permutation.withState(
          "minecraft:cardinal_direction",
          connectionDir
        )
      );
    } else if (iterateAround) {
      if (sourceBlock.typeId.includes("ods_orch:") && sourceBlock.typeId.includes("fence") && !sourceBlock.typeId.includes("gate")) {
        sourceBlock.dimension.setBlockType(
          sourceBlock.location,
          newBlockTypeId
        );
        let targetBlock = sourceBlock.dimension.getBlock(sourceBlock.location);
        targetBlock?.setPermutation(
          targetBlock.permutation.withState(
            "minecraft:cardinal_direction",
            connectionDir
          )
        );
      }
      let blockNorth = this.blockNorth(sourceBlock);
      let blockSouth = this.blockSouth(sourceBlock);
      let blockEast = this.blockEast(sourceBlock);
      let blockWest = this.blockWest(sourceBlock);
      if (blockNorth) {
        this.fencePlacing(blockNorth, false);
      }
      if (blockSouth) {
        this.fencePlacing(blockSouth, false);
      }
      if (blockEast) {
        this.fencePlacing(blockEast, false);
      }
      if (blockWest) {
        this.fencePlacing(blockWest, false);
      }
    }
  }
  fenceDestroying(typeId, location, dimension, iterateAround) {
    let sourceBlock = world9.getDimension(dimension.id).getBlock(location);
    if (sourceBlock === void 0)
      return;
    if (iterateAround && !this.blockNorth(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockNorth(sourceBlock)?.typeId?.includes("fence") && !this.blockSouth(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockSouth(sourceBlock)?.typeId?.includes("fence") && !this.blockEast(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockEast(sourceBlock)?.typeId?.includes("fence") && !this.blockWest(sourceBlock)?.typeId?.includes("ods_orch:") && !this.blockWest(sourceBlock)?.typeId?.includes("fence")) {
      return;
    }
    if (sourceBlock.typeId.includes("gate"))
      return;
    let connectionAmount = this.checkFenceConnectionsNum(sourceBlock);
    let connectionDir = this.checkFenceConnectionsDir(
      sourceBlock,
      connectionAmount
    );
    let newBlockTypeId = typeId.replace("_0", "").replace("_1", "").replace("_2_s", "").replace("_2", "").replace("_3", "").replace("_4", "");
    newBlockTypeId = newBlockTypeId + `_${connectionAmount}`;
    if (connectionAmount === 2 && (this.blockNorth(sourceBlock) && this.blockSouth(sourceBlock) && !this.blockEast(sourceBlock) && !this.blockWest(sourceBlock) || !this.blockNorth(sourceBlock) && !this.blockSouth(sourceBlock) && this.blockEast(sourceBlock) && this.blockWest(sourceBlock))) {
      newBlockTypeId = newBlockTypeId + "_s";
    }
    if (iterateAround) {
      let blockNorth = this.blockNorth(sourceBlock);
      let blockSouth = this.blockSouth(sourceBlock);
      let blockEast = this.blockEast(sourceBlock);
      let blockWest = this.blockWest(sourceBlock);
      if (blockNorth) {
        this.fenceDestroying(
          blockNorth.typeId,
          blockNorth.location,
          blockNorth.dimension,
          false
        );
      }
      if (blockSouth) {
        this.fenceDestroying(
          blockSouth.typeId,
          blockSouth.location,
          blockSouth.dimension,
          false
        );
      }
      if (blockEast) {
        this.fenceDestroying(
          blockEast.typeId,
          blockEast.location,
          blockEast.dimension,
          false
        );
      }
      if (blockWest) {
        this.fenceDestroying(
          blockWest.typeId,
          blockWest.location,
          blockWest.dimension,
          false
        );
      }
    } else if (!iterateAround) {
      let checkOdyssey = sourceBlock.typeId.includes("ods_orch:");
      let checkBlock = sourceBlock.typeId.includes("fence");
      if (checkOdyssey && checkBlock) {
        sourceBlock.dimension.setBlockType(
          sourceBlock.location,
          newBlockTypeId
        );
        let targetBlock = sourceBlock.dimension.getBlock(sourceBlock.location);
        targetBlock?.setPermutation(
          targetBlock.permutation.withState(
            "minecraft:cardinal_direction",
            connectionDir
          )
        );
      }
    }
  }
  checkFenceConnectionsNum(block) {
    let connectionAmount = 0;
    if (this.blockNorth(block)) {
      connectionAmount++;
    }
    if (this.blockSouth(block)) {
      connectionAmount++;
    }
    if (this.blockEast(block)) {
      connectionAmount++;
    }
    if (this.blockWest(block)) {
      connectionAmount++;
    }
    return connectionAmount;
  }
  checkFenceConnectionsDir(block, connectionAmount) {
    let direction = "north";
    if (connectionAmount === 1) {
      if (this.blockNorth(block)) {
        direction = "north";
      }
      if (this.blockSouth(block)) {
        direction = "south";
      }
      if (this.blockEast(block)) {
        direction = "east";
      }
      if (this.blockWest(block)) {
        direction = "west";
      }
    }
    if (connectionAmount === 2) {
      if (this.blockNorth(block) && this.blockEast(block)) {
        direction = "north";
      }
      if (this.blockEast(block) && this.blockSouth(block)) {
        direction = "east";
      }
      if (this.blockSouth(block) && this.blockWest(block)) {
        direction = "south";
      }
      if (this.blockWest(block) && this.blockNorth(block)) {
        direction = "west";
      }
    }
    if (connectionAmount === 2) {
      if (this.blockNorth(block) && this.blockSouth(block) && !this.blockEast(block) && !this.blockWest(block)) {
        direction = "north";
      }
      if (this.blockEast(block) && this.blockWest(block) && !this.blockNorth(block) && !this.blockSouth(block)) {
        direction = "east";
      }
    }
    if (connectionAmount === 3) {
      if (this.blockNorth(block) && this.blockEast(block) && this.blockSouth(block)) {
        direction = "north";
      }
      if (this.blockEast(block) && this.blockSouth(block) && this.blockWest(block)) {
        direction = "east";
      }
      if (this.blockSouth(block) && this.blockWest(block) && this.blockNorth(block)) {
        direction = "south";
      }
      if (this.blockWest(block) && this.blockNorth(block) && this.blockEast(block)) {
        direction = "west";
      }
    }
    if (connectionAmount === 4) {
      direction = "north";
    }
    return direction;
  }
  // Blocks utilities
  blockNorth(sourceBlock) {
    let targetBlock = sourceBlock.north(1);
    if (targetBlock !== void 0 && !targetBlock.isAir && targetBlock.typeId !== "minecraft:snow_layer" && targetBlock.typeId !== "minecraft:short_grass" && targetBlock.typeId !== "minecraft:tall_grass" && targetBlock.typeId !== "minecraft:lantern" && targetBlock.typeId !== "minecraft:soul_lantern" && targetBlock.typeId !== "minecraft:torch" && targetBlock.typeId !== "minecraft:soul_torch" && targetBlock.typeId !== "minecraft:potates" && targetBlock.typeId !== "minecraft:beetroot" && targetBlock.typeId !== "minecraft:carrots" && targetBlock.typeId !== "minecraft:wheat" && targetBlock.typeId !== "minecraft:pumpkin_stem" && targetBlock.typeId !== "minecraft:melon_stem" && !targetBlock.typeId.includes("flower") && !targetBlock.typeId.includes("dandelion") && !targetBlock.typeId.includes("poppy") && !targetBlock.typeId.includes("blue_orchid") && !targetBlock.typeId.includes("allium") && !targetBlock.typeId.includes("azure_bluet") && !targetBlock.typeId.includes("red_tulip") && !targetBlock.typeId.includes("orange_tulip") && !targetBlock.typeId.includes("white_tulip") && !targetBlock.typeId.includes("pink_tulip") && !targetBlock.typeId.includes("oxeye_daisy") && !targetBlock.typeId.includes("cornflower") && !targetBlock.typeId.includes("lily_of_the_valley") && !targetBlock.typeId.includes("sunflower") && !targetBlock.typeId.includes("lilac") && !targetBlock.typeId.includes("rose_bush") && !targetBlock.typeId.includes("peony") && !targetBlock.typeId.includes("pitcher_plant") && !targetBlock.typeId.includes("pink_petals") && !targetBlock.typeId.includes("torchflower") && !targetBlock.typeId.includes("fern") && !targetBlock.typeId.includes("deadbush") && !targetBlock.typeId.includes("sapling") && !targetBlock.typeId.includes("amethyst_cluster") && !targetBlock.typeId.includes("amethyst_bud") && !targetBlock.typeId.includes("banner") && !targetBlock.isLiquid) {
      return targetBlock;
    } else {
      return;
    }
  }
  blockSouth(sourceBlock) {
    let targetBlock = sourceBlock.south(1);
    if (targetBlock !== void 0 && !targetBlock.isAir && targetBlock.typeId !== "minecraft:snow_layer" && targetBlock.typeId !== "minecraft:short_grass" && targetBlock.typeId !== "minecraft:tall_grass" && targetBlock.typeId !== "minecraft:lantern" && targetBlock.typeId !== "minecraft:soul_lantern" && targetBlock.typeId !== "minecraft:torch" && targetBlock.typeId !== "minecraft:soul_torch" && targetBlock.typeId !== "minecraft:potates" && targetBlock.typeId !== "minecraft:beetroot" && targetBlock.typeId !== "minecraft:carrots" && targetBlock.typeId !== "minecraft:wheat" && targetBlock.typeId !== "minecraft:pumpkin_stem" && targetBlock.typeId !== "minecraft:melon_stem" && !targetBlock.typeId.includes("flower") && !targetBlock.typeId.includes("dandelion") && !targetBlock.typeId.includes("poppy") && !targetBlock.typeId.includes("blue_orchid") && !targetBlock.typeId.includes("allium") && !targetBlock.typeId.includes("azure_bluet") && !targetBlock.typeId.includes("red_tulip") && !targetBlock.typeId.includes("orange_tulip") && !targetBlock.typeId.includes("white_tulip") && !targetBlock.typeId.includes("pink_tulip") && !targetBlock.typeId.includes("oxeye_daisy") && !targetBlock.typeId.includes("cornflower") && !targetBlock.typeId.includes("lily_of_the_valley") && !targetBlock.typeId.includes("sunflower") && !targetBlock.typeId.includes("lilac") && !targetBlock.typeId.includes("rose_bush") && !targetBlock.typeId.includes("peony") && !targetBlock.typeId.includes("pitcher_plant") && !targetBlock.typeId.includes("pink_petals") && !targetBlock.typeId.includes("torchflower") && !targetBlock.typeId.includes("fern") && !targetBlock.typeId.includes("deadbush") && !targetBlock.typeId.includes("sapling") && !targetBlock.typeId.includes("amethyst_cluster") && !targetBlock.typeId.includes("amethyst_bud") && !targetBlock.typeId.includes("banner") && !targetBlock.isLiquid) {
      return targetBlock;
    } else {
      return;
    }
  }
  blockEast(sourceBlock) {
    let targetBlock = sourceBlock.east(1);
    if (targetBlock !== void 0 && !targetBlock.isAir && targetBlock.typeId !== "minecraft:snow_layer" && targetBlock.typeId !== "minecraft:short_grass" && targetBlock.typeId !== "minecraft:tall_grass" && targetBlock.typeId !== "minecraft:lantern" && targetBlock.typeId !== "minecraft:soul_lantern" && targetBlock.typeId !== "minecraft:torch" && targetBlock.typeId !== "minecraft:soul_torch" && targetBlock.typeId !== "minecraft:potates" && targetBlock.typeId !== "minecraft:beetroot" && targetBlock.typeId !== "minecraft:carrots" && targetBlock.typeId !== "minecraft:wheat" && targetBlock.typeId !== "minecraft:pumpkin_stem" && targetBlock.typeId !== "minecraft:melon_stem" && !targetBlock.typeId.includes("flower") && !targetBlock.typeId.includes("dandelion") && !targetBlock.typeId.includes("poppy") && !targetBlock.typeId.includes("blue_orchid") && !targetBlock.typeId.includes("allium") && !targetBlock.typeId.includes("azure_bluet") && !targetBlock.typeId.includes("red_tulip") && !targetBlock.typeId.includes("orange_tulip") && !targetBlock.typeId.includes("white_tulip") && !targetBlock.typeId.includes("pink_tulip") && !targetBlock.typeId.includes("oxeye_daisy") && !targetBlock.typeId.includes("cornflower") && !targetBlock.typeId.includes("lily_of_the_valley") && !targetBlock.typeId.includes("sunflower") && !targetBlock.typeId.includes("lilac") && !targetBlock.typeId.includes("rose_bush") && !targetBlock.typeId.includes("peony") && !targetBlock.typeId.includes("pitcher_plant") && !targetBlock.typeId.includes("pink_petals") && !targetBlock.typeId.includes("torchflower") && !targetBlock.typeId.includes("fern") && !targetBlock.typeId.includes("deadbush") && !targetBlock.typeId.includes("sapling") && !targetBlock.typeId.includes("amethyst_cluster") && !targetBlock.typeId.includes("amethyst_bud") && !targetBlock.typeId.includes("banner") && !targetBlock.isLiquid) {
      return targetBlock;
    } else {
      return;
    }
  }
  blockWest(sourceBlock) {
    let targetBlock = sourceBlock.west(1);
    if (targetBlock !== void 0 && !targetBlock.isAir && targetBlock.typeId !== "minecraft:snow_layer" && targetBlock.typeId !== "minecraft:short_grass" && targetBlock.typeId !== "minecraft:tall_grass" && targetBlock.typeId !== "minecraft:lantern" && targetBlock.typeId !== "minecraft:soul_lantern" && targetBlock.typeId !== "minecraft:torch" && targetBlock.typeId !== "minecraft:soul_torch" && targetBlock.typeId !== "minecraft:potates" && targetBlock.typeId !== "minecraft:beetroot" && targetBlock.typeId !== "minecraft:carrots" && targetBlock.typeId !== "minecraft:wheat" && targetBlock.typeId !== "minecraft:pumpkin_stem" && targetBlock.typeId !== "minecraft:melon_stem" && !targetBlock.typeId.includes("flower") && !targetBlock.typeId.includes("dandelion") && !targetBlock.typeId.includes("poppy") && !targetBlock.typeId.includes("blue_orchid") && !targetBlock.typeId.includes("allium") && !targetBlock.typeId.includes("azure_bluet") && !targetBlock.typeId.includes("red_tulip") && !targetBlock.typeId.includes("orange_tulip") && !targetBlock.typeId.includes("white_tulip") && !targetBlock.typeId.includes("pink_tulip") && !targetBlock.typeId.includes("oxeye_daisy") && !targetBlock.typeId.includes("cornflower") && !targetBlock.typeId.includes("lily_of_the_valley") && !targetBlock.typeId.includes("sunflower") && !targetBlock.typeId.includes("lilac") && !targetBlock.typeId.includes("rose_bush") && !targetBlock.typeId.includes("peony") && !targetBlock.typeId.includes("pitcher_plant") && !targetBlock.typeId.includes("pink_petals") && !targetBlock.typeId.includes("torchflower") && !targetBlock.typeId.includes("fern") && !targetBlock.typeId.includes("deadbush") && !targetBlock.typeId.includes("sapling") && !targetBlock.typeId.includes("amethyst_cluster") && !targetBlock.typeId.includes("amethyst_bud") && !targetBlock.typeId.includes("banner") && !targetBlock.isLiquid) {
      return targetBlock;
    } else {
      return;
    }
  }
};

// data/system_template_esbuild/subscripts/decay.ts
import {
  system as system10,
  ItemStack as ItemStack7
} from "@minecraft/server";
var Decay = class {
  constructor() {
    __publicField(this, "UTILITIES");
    __publicField(this, "DATA");
    this.UTILITIES = new Utilities();
    this.DATA = new Data2();
  }
  // Methods
  decayState(block) {
    if (this.stopDecay(block))
      return;
    let decayState = block.permutation.getState("ods_orch:decay_state");
    if (decayState === this.DATA.MAX_DECAY_STATE) {
      let loot = [];
      if (block.typeId.includes("leaves")) {
        let type = block.typeId.replace("_leaves", "").replace("ods_orch:", "");
        let saplingDropChance = 5;
        this.DATA.TREES.forEach((element) => {
          if (type == element.typeId) {
            saplingDropChance = element.saplingDropChance;
          }
        });
        if (this.UTILITIES.randInt(0, 100) < saplingDropChance) {
          let saplingTypeId = block.typeId.replace(
            "_leaves",
            "_sapling_placer"
          );
          let sapling = new ItemStack7(saplingTypeId, 1);
          loot.push(sapling);
        }
        if (this.UTILITIES.randInt(0, 100) < 5) {
          let stick = new ItemStack7(
            "minecraft:stick",
            this.UTILITIES.randInt(1, 2)
          );
          loot.push(stick);
        }
      }
      if (block.typeId.includes("fruit")) {
        if (this.UTILITIES.randInt(0, 100) < 50) {
          let fruitTypeId = block.typeId.replace("maple_tree_fruit_down", "maple_syrup").replace("maple_tree_fruit_side", "maple_syrup").replace("_tree_fruit_down", "").replace("_tree_fruit_side", "");
          let fruit = new ItemStack7(fruitTypeId, 1);
          loot.push(fruit);
        }
      }
      loot.forEach((drop) => {
        block.dimension.spawnItem(drop, block.location);
      });
      if (block.typeId.includes("leaves")) {
        switch (true) {
          case block.below(1)?.typeId.includes("fruit"):
            let blockBelow = block.below(1);
            if (blockBelow === void 0)
              return;
            block.below(1)?.permutation.withState(
              "ods_orch:decay_state",
              this.DATA.MAX_DECAY_STATE
            );
            this.decayState(blockBelow);
            break;
          case block.north(1)?.typeId.includes("fruit"):
            let blockNorth = block.north(1);
            if (blockNorth === void 0)
              return;
            block.north(1)?.permutation.withState(
              "ods_orch:decay_state",
              this.DATA.MAX_DECAY_STATE
            );
            this.decayState(blockNorth);
            break;
          case block.south(1)?.typeId.includes("fruit"):
            let blockSouth = block.south(1);
            if (blockSouth === void 0)
              return;
            block.south(1)?.permutation.withState(
              "ods_orch:decay_state",
              this.DATA.MAX_DECAY_STATE
            );
            this.decayState(blockSouth);
            break;
          case block.east(1)?.typeId.includes("fruit"):
            let blockEast = block.east(1);
            if (blockEast === void 0)
              return;
            block.east(1)?.permutation.withState(
              "ods_orch:decay_state",
              this.DATA.MAX_DECAY_STATE
            );
            this.decayState(blockEast);
            break;
          case block.west(1)?.typeId.includes("fruit"):
            let blockWest = block.west(1);
            if (blockWest === void 0)
              return;
            block.west(1)?.permutation.withState(
              "ods_orch:decay_state",
              this.DATA.MAX_DECAY_STATE
            );
            this.decayState(blockWest);
            break;
          default:
            break;
        }
      }
      block.setType("minecraft:air");
    } else if (decayState < this.DATA.MAX_DECAY_STATE) {
      decayState++;
      block.setPermutation(
        block.permutation.withState("ods_orch:decay_state", decayState)
      );
    }
  }
  startDecay(block) {
    let volumeSize = 10;
    const volumeMinialPosition = {
      x: block.location.x - volumeSize / 2,
      y: block.location.y - volumeSize / 2,
      z: block.location.z - volumeSize / 2
    };
    let coordinatesToCheck = volumeMinialPosition;
    for (let dx = 0; dx < volumeSize + 1; dx++) {
      for (let dy = 0; dy < volumeSize + 1; dy++) {
        for (let dz = 0; dz < volumeSize + 1; dz++) {
          coordinatesToCheck = {
            x: volumeMinialPosition.x + dx,
            y: volumeMinialPosition.y + dy,
            z: volumeMinialPosition.z + dz
          };
          let blockToCheck = block.dimension.getBlock(coordinatesToCheck);
          if (!blockToCheck)
            break;
          let checkOdyssey = blockToCheck.typeId.includes("ods_orch:");
          let checkLeaves = blockToCheck.typeId.includes("leaves");
          let checkFruits = blockToCheck.typeId.includes("fruit");
          if (checkOdyssey && (checkLeaves || checkFruits)) {
            if (blockToCheck.permutation.getState("ods_orch:decay_state") === 0) {
              blockToCheck.setPermutation(
                blockToCheck.permutation.withState("ods_orch:decay_state", 1)
              );
            }
          }
        }
      }
    }
  }
  stopDecay(block) {
    let sourceBlock = block;
    let volumeSize = 6;
    const volumeMinialPosition = {
      x: sourceBlock.location.x - volumeSize / 2,
      y: sourceBlock.location.y - volumeSize / 2,
      z: sourceBlock.location.z - volumeSize / 2
    };
    let coordinatesToCheck = volumeMinialPosition;
    for (let dx = 0; dx < volumeSize + 1; dx++) {
      for (let dy = 0; dy < volumeSize + 1; dy++) {
        for (let dz = 0; dz < volumeSize + 1; dz++) {
          coordinatesToCheck = {
            x: volumeMinialPosition.x + dx,
            y: volumeMinialPosition.y + dy,
            z: volumeMinialPosition.z + dz
          };
          let blockToCheck = sourceBlock.dimension.getBlock(coordinatesToCheck);
          if (!blockToCheck)
            return;
          let checkOdyssey = blockToCheck.typeId.includes("ods_orch:");
          let checkLog = blockToCheck.typeId.includes("log");
          let checkWood = blockToCheck.typeId.includes("wood");
          if (checkOdyssey && (checkLog || checkWood)) {
            sourceBlock.setPermutation(
              sourceBlock.permutation.withState("ods_orch:decay_state", 0)
            );
            return true;
          }
        }
      }
    }
    return false;
  }
  // Fruit destroying after destroying leaves by hand
  leavesDestroyed(sourceBlock) {
    let blocks = [
      sourceBlock.below(1),
      sourceBlock.north(1),
      sourceBlock.south(1),
      sourceBlock.east(1),
      sourceBlock.west(1)
    ];
    blocks.forEach((block) => {
      if (block?.typeId.includes("fruit") && block?.typeId.includes("ods_orch:")) {
        let dimension = block.dimension;
        let location = block.location;
        system10.run(() => {
          dimension.runCommandAsync(
            `/setblock ${location.x} ${location.y} ${location.z} minecraft:air [] destroy`
          );
        });
      }
    });
  }
};

// data/system_template_esbuild/subscripts/fruits.ts
var Fruits = class {
  constructor() {
    __publicField(this, "DATA");
    __publicField(this, "UTILITIES");
    this.DATA = new Data2();
    this.UTILITIES = new Utilities();
  }
  // Methods
  growFruit(block) {
    let decayState = block.permutation.getState("ods_orch:decay_state");
    if (decayState === 2)
      return;
    let fruitsState = block.permutation.getState("ods_orch:fruits_state");
    if (fruitsState === this.DATA.MAX_FRUIT_STATE) {
      if (this.checkIfFruit(block)) {
        block.setPermutation(
          block.permutation.withState("ods_orch:fruits_state", 0)
        );
        return;
      } else {
        switch ("minecraft:air") {
          case block.below(1)?.typeId:
            this.setFruit(block.below(1)?.location, "below", block);
            break;
          case block.north(1)?.typeId:
            this.setFruit(block.north(1)?.location, "south", block);
            break;
          case block.south(1)?.typeId:
            this.setFruit(block.south(1)?.location, "north", block);
            break;
          case block.east(1)?.typeId:
            this.setFruit(block.east(1)?.location, "west", block);
            break;
          case block.west(1)?.typeId:
            this.setFruit(block.west(1)?.location, "east", block);
            break;
          default:
            break;
        }
        block.setPermutation(
          block.permutation.withState("ods_orch:fruits_state", 0)
        );
      }
    } else if (fruitsState < this.DATA.MAX_FRUIT_STATE) {
      fruitsState++;
      block.setPermutation(
        block.permutation.withState("ods_orch:fruits_state", fruitsState)
      );
    }
  }
  checkIfFruit(block) {
    let volumeSize = 2;
    const volumeMinialPosition = {
      x: block.location.x - volumeSize / 2,
      y: block.location.y - volumeSize / 2,
      z: block.location.z - volumeSize / 2
    };
    let coordinatesToCheck = volumeMinialPosition;
    for (let dx = 0; dx < volumeSize + 1; dx++) {
      for (let dy = 0; dy < volumeSize + 1; dy++) {
        for (let dz = 0; dz < volumeSize + 1; dz++) {
          coordinatesToCheck = {
            x: volumeMinialPosition.x + dx,
            y: volumeMinialPosition.y + dy,
            z: volumeMinialPosition.z + dz
          };
          let blockToCheck = block.dimension.getBlock(coordinatesToCheck);
          if (!blockToCheck)
            return true;
          let checkFruit = blockToCheck.typeId.includes("fruit");
          if (checkFruit) {
            return true;
          }
        }
      }
    }
    return false;
  }
  setFruit(targetlocation, direction, block) {
    if (targetlocation) {
      const fruitType = direction === "below" ? "fruit_down" : "fruit_side";
      block.dimension.setBlockType(
        targetlocation,
        block.typeId.replace("leaves", fruitType).replace("log", fruitType)
      );
      let fruit = block.dimension.getBlock(targetlocation);
      if (direction !== "below") {
        fruit?.setPermutation(
          fruit.permutation.withState("minecraft:cardinal_direction", direction)
        );
      } else if (direction == "below") {
        let randomInt = this.UTILITIES.randInt(0, 100);
        let newDirection = "north";
        if (randomInt <= 25) {
          newDirection = "north";
        } else if (randomInt > 25 && randomInt <= 50) {
          newDirection = "south";
        } else if (randomInt > 50 && randomInt <= 75) {
          newDirection = "east";
        } else if (randomInt > 75 && randomInt <= 100) {
          newDirection = "west";
        }
        fruit?.setPermutation(
          fruit.permutation.withState(
            "minecraft:cardinal_direction",
            newDirection
          )
        );
      }
    }
  }
};

// data/system_template_esbuild/subscripts/trees_events.ts
var GROWING_MODIFIER = 3;
var FRUIT_MODIFIER = 5;
var GROWING_OBJECT = new Growing();
var TOOLS_USAGE_OBJECT = new ToolsUsage();
var DERIVED_BLOCKS_OBJECT = new DerivedBlocks();
var DECAY_OBJECT = new Decay();
var FRUITS_OBJECT = new Fruits();
var UTILITIES = new Utilities();
var DATA = new Data2();
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "ods_orch:component_growing_state_tree",
    {
      onRandomTick(event2) {
        if (UTILITIES.randInt(0, 100) < GROWING_MODIFIER) {
          let block = event2.block;
          GROWING_OBJECT.growingState(block);
        }
      }
    }
  );
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent("ods_orch:leaves", {
    beforeOnPlayerPlace(event2) {
      let sourceBlockTypeId = event2.permutationToPlace.type.id;
      let location = event2.block.location;
      let dimension = event2.block.dimension;
      let player = event2.player;
      event2.cancel = true;
      system11.run(() => {
        dimension.setBlockType(location, sourceBlockTypeId);
        let newBlock = dimension.getBlock(location);
        newBlock?.dimension.playSound("dig.grass", location);
        if (newBlock === void 0)
          return;
        if (player?.hasTag("ODS_ORCH_BUILDER")) {
          newBlock.setPermutation(
            newBlock.permutation.withState("ods_orch:decay_state", 0)
          );
        } else {
          newBlock.setPermutation(
            newBlock.permutation.withState("ods_orch:decay_state", 2)
          );
        }
      });
    },
    onRandomTick(event2) {
      let block = event2.block;
      let decayState = event2.block.permutation.getState("ods_orch:decay_state");
      if (decayState > 0) {
        DECAY_OBJECT.decayState(block);
      }
      if (UTILITIES.randInt(0, 100) < 101 && block.below(1)?.isAir) {
        block.dimension.spawnParticle(block.typeId, block.bottomCenter());
      }
      if (UTILITIES.randInt(0, 100) < FRUIT_MODIFIER && decayState !== 2) {
        let treeType = block.typeId.replace("_leaves", "").replace("ods_orch:", "");
        if (treeType.includes("maple"))
          return;
        let dataObject = DATA.TREES.find((item) => item.typeId === treeType);
        if (dataObject === void 0)
          return;
        if (UTILITIES.randInt(0, 100) < dataObject.fruitGrowth) {
          FRUITS_OBJECT.growFruit(block);
        }
      }
    }
  });
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent("ods_orch:fruit", {
    beforeOnPlayerPlace(event2) {
      let sourceBlockTypeId = event2.permutationToPlace.type.id;
      let location = event2.block.location;
      let dimension = event2.block.dimension;
      let player = event2.player;
      event2.cancel = true;
      system11.run(() => {
        dimension.setBlockType(location, sourceBlockTypeId);
        let newBlock = dimension.getBlock(location);
        newBlock?.dimension.playSound("dig.grass", location);
        if (newBlock === void 0)
          return;
        if (player?.hasTag("ODS_ORCH_BUILDER")) {
          newBlock.setPermutation(
            newBlock.permutation.withState("ods_orch:decay_state", 0)
          );
        } else {
          newBlock.setPermutation(
            newBlock.permutation.withState("ods_orch:decay_state", 2)
          );
        }
      });
    },
    onRandomTick(event2) {
      let block = event2.block;
      let decayState = event2.block.permutation.getState("ods_orch:decay_state");
      if (decayState > 0) {
        DECAY_OBJECT.decayState(block);
      }
    }
  });
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent("ods_orch:log", {
    onPlayerDestroy(event2) {
      let block = event2.block;
      DECAY_OBJECT.startDecay(block);
    },
    onRandomTick(event2) {
      let block = event2.block;
      if (UTILITIES.randInt(0, 100) < FRUIT_MODIFIER) {
        let treeType = block.typeId.replace("_log", "").replace("ods_orch:", "");
        if (!treeType.includes("maple"))
          return;
        let dataObject = DATA.TREES.find((item) => item.typeId === treeType);
        if (dataObject === void 0)
          return;
        if (UTILITIES.randInt(0, 100) < dataObject.fruitGrowth) {
          FRUITS_OBJECT.growFruit(block);
        }
      }
    }
  });
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent("ods_orch:wood", {
    onPlayerDestroy(event2) {
      let block = event2.block;
      DECAY_OBJECT.startDecay(block);
    }
  });
});
world11.afterEvents.entityHitBlock.subscribe((event) => {
  let checkOdyssey = event.hitBlock.typeId.includes("ods_orch:");
  let checkLeaves = event.hitBlock.typeId.includes("leaves");
  if (checkOdyssey && checkLeaves) {
    if (event.damagingEntity.typeId == "minecraft:player") {
      DECAY_OBJECT.leavesDestroyed(event.hitBlock);
      let player = event.damagingEntity;
      let shears = UTILITIES.getItemHeld(player);
      if (shears?.typeId === "minecraft:shears") {
        TOOLS_USAGE_OBJECT.shears(event.hitBlock, player, shears);
      }
    }
  }
});
world11.beforeEvents.playerBreakBlock.subscribe((event) => {
  let checkOdyssey = event.block.typeId.includes("ods_orch:");
  let checkLeaves = event.block.typeId.includes("leaves");
  let checkLogs = event.block.typeId.includes("log");
  if (checkOdyssey && (checkLeaves || checkLogs)) {
    DECAY_OBJECT.leavesDestroyed(event.block);
    let shears = UTILITIES.getItemHeld(event.player);
    if (shears?.typeId === "minecraft:shears") {
      TOOLS_USAGE_OBJECT.shears(event.block, event.player, shears);
    }
  }
});
world11.beforeEvents.itemUseOn.subscribe((event) => {
  GROWING_OBJECT.bonemeal(event);
});
world11.beforeEvents.itemUseOn.subscribe((event) => {
  GROWING_OBJECT.checkForSoil(event);
});
world11.beforeEvents.itemUseOn.subscribe((event) => {
  TOOLS_USAGE_OBJECT.stripping(event);
});
world11.beforeEvents.itemUseOn.subscribe((event) => {
  let checkOdyssey = event.itemStack.typeId.includes("ods_orch:");
  let checkLog = event.itemStack.typeId.includes("log");
  if (checkOdyssey === false)
    return;
  if (checkLog) {
    event.cancel = true;
    system11.run(() => {
      DERIVED_BLOCKS_OBJECT.logPlacing(event);
    });
  }
});
world11.beforeEvents.itemUseOn.subscribe((event) => {
  let face = event.blockFace;
  if (event.source.isSneaking)
    return;
  let checkItemOdyssey = event.itemStack.typeId.includes("ods_orch:");
  let checkItemSlab = event.itemStack.typeId.includes("tree_slab") || event.itemStack.typeId.includes("tree_vertical_slab");
  let checkBlockOdyssey = event.block.typeId.includes("ods_orch:");
  let checkBlockSlab = event.block.typeId.includes("tree_slab") || event.block.typeId.includes("tree_vertical_slab");
  if (checkItemOdyssey === false || checkBlockOdyssey === false)
    return;
  if (checkItemSlab && checkBlockSlab) {
    if (event.block.typeId.includes("vertical") && (face === Direction3.Up || face === Direction3.Down))
      return;
    let cardinalDirection = event.block.permutation.getState(
      "minecraft:cardinal_direction"
    );
    if (event.block.typeId.includes("vertical") && (face === Direction3.North && cardinalDirection !== "south" || face === Direction3.South && cardinalDirection !== "north" || face === Direction3.East && cardinalDirection !== "west" || face === Direction3.West && cardinalDirection !== "east"))
      return;
    if (!event.block.typeId.includes("vertical") && (face === Direction3.North || face === Direction3.South || face === Direction3.East || face === Direction3.West || face === Direction3.Down))
      return;
    event.cancel = true;
    if (event.itemStack.typeId != event.block.typeId)
      return;
    let vertical = event.block.typeId.includes("vertical");
    event.source.runCommandAsync(`/clear @s ${event.itemStack.typeId} 0 1`);
    system11.run(() => {
      DERIVED_BLOCKS_OBJECT.doubleSlabPlacing(event, vertical);
    });
  }
});
world11.beforeEvents.itemUseOn.subscribe((event) => {
  let face = event.blockFace;
  if (event.source.isSneaking)
    return;
  let checkItemOdyssey = event.itemStack.typeId.includes("ods_orch:");
  let checkItemTile = event.itemStack.typeId.includes("tile");
  let checkBlockOdyssey = event.block.typeId.includes("ods_orch:");
  let checkBlockTile = event.block.typeId.includes("tile");
  if (checkItemOdyssey === false || checkBlockOdyssey === false)
    return;
  if (checkItemTile && checkBlockTile) {
    let tilePart = event.block.permutation.getState("ods_orch:tile_part");
    if (face !== Direction3.Up || tilePart === 8)
      return;
    event.cancel = true;
    if (event.itemStack.typeId != event.block.typeId)
      return;
    let direction = event.block.permutation.getState("minecraft:cardinal_direction");
    event.source.runCommandAsync(`/clear @s ${event.itemStack.typeId} 0 1`);
    system11.run(() => {
      DERIVED_BLOCKS_OBJECT.tilePlacing(event, tilePart, direction);
    });
  }
});
world11.afterEvents.playerPlaceBlock.subscribe((event) => {
  if (event.block) {
    DERIVED_BLOCKS_OBJECT.fencePlacing(event.block, true);
  }
});
world11.beforeEvents.playerBreakBlock.subscribe((event) => {
  if (event.block) {
    let typeId = event.block.typeId;
    let location = event.block.location;
    let dimension = event.block.dimension;
    system11.run(() => {
      DERIVED_BLOCKS_OBJECT.fenceDestroying(typeId, location, dimension, true);
    });
  }
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "ods_orch:vanilla_trapdoor",
    {
      onPlayerInteract({ block, dimension }) {
        const isOpen = block.permutation.getState("ods_orch:open");
        const sound = isOpen ? "close.wooden_trapdoor" : "open.wooden_trapdoor";
        block.setPermutation(
          block.permutation.withState("ods_orch:open", !isOpen)
        );
        dimension.playSound(sound, block.center(), {
          pitch: 0.9,
          volume: 0.9
        });
      }
    }
  );
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "ods_orch:vanilla_fence_gate",
    {
      // This has to be done to display item icon nd the block separately without 1 tick delay. Comments in the section of doors, search for beforeOnPlayerPlace
      beforeOnPlayerPlace(event2) {
        event2.cancel = true;
        let player = event2.player;
        if (player === void 0)
          return;
        let gateTypeId = UTILITIES.getItemHeld(player);
        if (gateTypeId === void 0)
          return;
        event2.block.dimension.setBlockType(
          event2.block.location,
          gateTypeId.typeId
        );
        let placedBlock = event2.block.dimension.getBlock(event2.block.location);
        if (placedBlock === void 0)
          return;
        placedBlock.setPermutation(
          event2.block.permutation.withState("ods_orch:placed", true)
        );
        let rotation = player.getRotation().y;
        let direction = "north";
        if (rotation >= -180 && rotation < -135) {
          direction = "north";
        }
        if (rotation >= -135 && rotation < -45) {
          direction = "east";
        }
        if (rotation >= -45 && rotation < 45) {
          direction = "south";
        }
        if (rotation >= 45 && rotation < 135) {
          direction = "west";
        }
        if (rotation >= 135 && rotation < 180) {
          direction = "north";
        }
        placedBlock.setPermutation(
          event2.block.permutation.withState(
            "minecraft:cardinal_direction",
            direction
          )
        );
        placedBlock.dimension.playSound("dig.wood", placedBlock.center());
        DERIVED_BLOCKS_OBJECT.fencePlacing(event2.block, true);
      },
      onPlayerInteract({ block, dimension }) {
        const isOpen = block.permutation.getState("ods_orch:open");
        const sound = isOpen ? "close.fence_gate" : "open.fence_gate";
        block.setPermutation(
          block.permutation.withState("ods_orch:open", !isOpen)
        );
        dimension.playSound(sound, block.center(), {
          pitch: 0.9,
          volume: 0.9
        });
      }
    }
  );
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "ods_orch:vanilla_door",
    {
      // This has to be done to place two door pieces at once without 1 tick delay
      beforeOnPlayerPlace(event2) {
        event2.cancel = true;
        let player = event2.player;
        if (player === void 0)
          return;
        let itemStack = UTILITIES.getItemHeld(player);
        if (itemStack === void 0)
          return;
        let doorBottomTypeId = itemStack.typeId.replace("_placer", "_bottom");
        let doorTopTypeId = itemStack.typeId.replace("_placer", "_top");
        event2.block.dimension.setBlockType(
          event2.block.location,
          doorBottomTypeId
        );
        let blockAbove = event2.block.above(1);
        if (blockAbove === void 0)
          return;
        event2.block.dimension.setBlockType(blockAbove.location, doorTopTypeId);
        let doorBottom = event2.block.dimension.getBlock(event2.block.location);
        let doorTop = event2.block.dimension.getBlock(blockAbove.location);
        if (doorBottom === void 0 || doorTop === void 0)
          return;
        let rotation = player.getRotation().y;
        let direction = "north";
        if (rotation >= -180 && rotation < -135) {
          direction = "north";
        }
        if (rotation >= -135 && rotation < -45) {
          direction = "east";
        }
        if (rotation >= -45 && rotation < 45) {
          direction = "south";
        }
        if (rotation >= 45 && rotation < 135) {
          direction = "west";
        }
        if (rotation >= 135 && rotation < 180) {
          direction = "north";
        }
        doorBottom.setPermutation(
          doorBottom.permutation.withState(
            "minecraft:cardinal_direction",
            direction
          )
        );
        doorTop.setPermutation(
          doorTop.permutation.withState(
            "minecraft:cardinal_direction",
            direction
          )
        );
        doorBottom.dimension.playSound("dig.wood", doorBottom.center());
      },
      onPlayerInteract({ block, dimension }) {
        let sourceDoor = block;
        const isOpen = sourceDoor.permutation.getState("ods_orch:open");
        const sound = isOpen ? "close.wooden_door" : "open.wooden_door";
        let otherDoor;
        if (sourceDoor.typeId.includes("top")) {
          otherDoor = sourceDoor.below(1);
        }
        if (sourceDoor.typeId.includes("bottom")) {
          otherDoor = sourceDoor.above(1);
        }
        if (otherDoor === void 0)
          return;
        otherDoor.setPermutation(
          otherDoor.permutation.withState("ods_orch:open", !isOpen)
        );
        sourceDoor.setPermutation(
          sourceDoor.permutation.withState("ods_orch:open", !isOpen)
        );
        dimension.playSound(sound, sourceDoor.center(), {
          pitch: 0.9,
          volume: 0.9
        });
      }
    }
  );
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "ods_orch:vanilla_door_bottom",
    {
      onTick(event2) {
        let block = event2.block;
        if (!block.typeId.includes("_vanilla_door_bottom"))
          return;
        let dimension = event2.dimension;
        let currentSignal = block.getRedstonePower();
        if (currentSignal === void 0) {
          currentSignal = 0;
        }
        let oldSignal = block.permutation.getState("ods_orch:redstone_power");
        if (currentSignal - oldSignal === 0)
          return;
        let sourceDoor = block;
        sourceDoor.setPermutation(
          sourceDoor.permutation.withState(
            "ods_orch:redstone_power",
            currentSignal
          )
        );
        const isOpen = sourceDoor.permutation.getState("ods_orch:open");
        const sound = isOpen ? "close.wooden_door" : "open.wooden_door";
        let otherDoor;
        if (sourceDoor.typeId.includes("top")) {
          otherDoor = sourceDoor.below(1);
        }
        if (sourceDoor.typeId.includes("bottom")) {
          otherDoor = sourceDoor.above(1);
        }
        if (otherDoor === void 0)
          return;
        otherDoor.setPermutation(
          otherDoor.permutation.withState("ods_orch:open", !isOpen)
        );
        sourceDoor.setPermutation(
          sourceDoor.permutation.withState("ods_orch:open", !isOpen)
        );
        dimension.playSound(sound, sourceDoor.center(), {
          pitch: 0.9,
          volume: 0.9
        });
      }
    }
  );
});
world11.beforeEvents.playerBreakBlock.subscribe((event) => {
  let block = event.block;
  let checkOdyssey = event.block.typeId.includes("ods_orch:");
  let checkDoor = event.block.typeId.includes("vanilla_door");
  if (checkDoor && checkOdyssey) {
    if (block.typeId.includes("top")) {
      block.dimension.runCommandAsync(
        `/setblock ${block.location.x} ${block.location.y - 1} ${block.location.z} minecraft:air destroy`
      );
    }
    if (block.typeId.includes("bottom")) {
      block.dimension.runCommandAsync(
        `/setblock ${block.location.x} ${block.location.y + 1} ${block.location.z} minecraft:air destroy`
      );
    }
    let location = block.location;
    let dimension = block.dimension;
    let dropTypeId = block.typeId.replace("top", "").replace("bottom", "") + "placer";
    system11.run(() => {
      let drop = new ItemStack8(dropTypeId);
      dimension.spawnItem(drop, location);
    });
  }
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "ods_orch:vanilla_stairs",
    {
      // This has to be done to display item icon nd the block separately without 1 tick delay.
      beforeOnPlayerPlace(event2) {
        event2.cancel = true;
        let player = event2.player;
        if (player === void 0)
          return;
        let stairsId = UTILITIES.getItemHeld(player);
        if (stairsId === void 0)
          return;
        event2.block.dimension.setBlockType(
          event2.block.location,
          stairsId.typeId
        );
        let placedBlock = event2.block.dimension.getBlock(event2.block.location);
        if (placedBlock === void 0)
          return;
        placedBlock.setPermutation(
          event2.block.permutation.withState("ods_orch:placed", true)
        );
        let rotationX = player.getRotation().x;
        let rotationY = player.getRotation().y;
        let cardinalDirection = "north";
        let facingDirection = "up";
        if (rotationX >= 0 && rotationX < 90) {
          facingDirection = "down";
          if (rotationY >= -180 && rotationY < -135) {
            cardinalDirection = "north";
          } else if (rotationY >= -135 && rotationY < -45) {
            cardinalDirection = "east";
          } else if (rotationY >= -45 && rotationY < 45) {
            cardinalDirection = "south";
          } else if (rotationY >= 45 && rotationY < 135) {
            cardinalDirection = "west";
          } else if (rotationY >= 135 && rotationY < 180) {
            cardinalDirection = "north";
          }
        }
        if (rotationX >= -90 && rotationX < 0) {
          facingDirection = "up";
          if (rotationY >= -180 && rotationY < -135) {
            cardinalDirection = "north";
          } else if (rotationY >= -135 && rotationY < -45) {
            cardinalDirection = "west";
          } else if (rotationY >= -45 && rotationY < 45) {
            cardinalDirection = "south";
          } else if (rotationY >= 45 && rotationY < 135) {
            cardinalDirection = "east";
          } else if (rotationY >= 135 && rotationY < 180) {
            cardinalDirection = "north";
          }
        }
        placedBlock.setPermutation(
          event2.block.permutation.withState(
            "minecraft:cardinal_direction",
            cardinalDirection
          )
        );
        placedBlock.setPermutation(
          event2.block.permutation.withState(
            "minecraft:facing_direction",
            facingDirection
          )
        );
        placedBlock.dimension.playSound("dig.wood", placedBlock.center());
      }
    }
  );
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent("ods_orch:lantern", {
    onRandomTick(event2) {
      let block = event2.block;
      if (UTILITIES.randInt(0, 100) < 100) {
        if (world11.getTimeOfDay() > 12500 && world11.getTimeOfDay() < 23e3) {
          block.dimension.spawnParticle("ods_orch:fireflies", {
            x: block.bottomCenter().x,
            y: block.bottomCenter().y + 0.3,
            z: block.bottomCenter().z
          });
        }
      }
    }
  });
});
world11.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent("ods_orch:birdhouse", {
    onRandomTick(event2) {
      let block = event2.block;
      if (UTILITIES.randInt(0, 100) < 100) {
        if (world11.getTimeOfDay() < 12500 || world11.getTimeOfDay() > 23e3) {
          block.dimension.playSound("ods_orch.birdhouse", block.center(), {
            pitch: 1,
            volume: 1
          });
        }
      }
    }
  });
});
