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/botanic_spawner.ts
import { world } from "@minecraft/server";
world.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:botanic_spawner",
    {
      onTick(event2) {
        const block = event2.block;
        const location = block.location;
        block.dimension.runCommand(`/execute if entity @p unless entity @a[tag=dev] unless entity @e[type=botany_nat:botanic,r=2] run summon botany_nat:botanic ${location.x} ${location.y} ${location.z}`);
        block.dimension.runCommand(`/execute if entity @p unless entity @a[tag=dev] unless entity @e[type=botany_nat:botanic,r=2] run setblock ${location.x} ${location.y} ${location.z} minecraft:air`);
      }
    }
  );
});

// data/system_template_esbuild/subscripts/bed.ts
import { world as world2, system as system2, BlockPermutation, ItemStack, TimeOfDay, WeatherType, EquipmentSlot } from "@minecraft/server";
var CAN_REPLACE = [
  "minecraft:air",
  "minecraft:short_grass",
  "minecraft:tall_grass",
  "minecraft:water",
  "minecraft:lava",
  "minecraft:red_flower",
  "minecraft:brown_mushroom",
  "minecraft:red_mushroom",
  "minecraft:deadbush",
  "minecraft:snow_layer"
];
var SLEEPING_TAG = "botany_nat:sleeping";
var OVERWORLD = world2.getDimension("overworld");
var WEATHER = "clear";
world2.afterEvents.weatherChange.subscribe((event) => {
  if (event.newWeather === WeatherType.Rain) {
    WEATHER = "rain";
  } else if (event.newWeather === WeatherType.Thunder) {
    WEATHER = "thunder";
  } else {
    WEATHER = "clear";
  }
});
world2.beforeEvents.worldInitialize.subscribe((eventData) => {
  eventData.blockComponentRegistry.registerCustomComponent("botany_nat:bed", {
    onPlayerInteract(event) {
      const { player, block } = event;
      if (!player || !block)
        return;
      const lastSpawnPoint = player.getSpawnPoint();
      const location = block.location;
      if (!lastSpawnPoint || lastSpawnPoint && getDistance(lastSpawnPoint, location) > 2) {
        player.setSpawnPoint({ "dimension": block.dimension, "x": location.x, "y": location.y, "z": location.z });
        player.sendMessage([{ text: "\xA77" }, { translate: "tile.bed.respawnSet" }]);
      }
      if (world2.getTimeOfDay() >= TimeOfDay.Night || WEATHER === "thunder") {
        if (!player.isSneaking) {
          initSleep(block, player);
        }
      } else {
        player.sendMessage([{ text: "\xA77" }, { translate: "tile.bed.noSleep" }]);
      }
    },
    beforeOnPlayerPlace(event) {
      const { player, block } = event;
      if (!player || !block)
        return;
      const direction = getCardinalDirection(player);
      let new_direction;
      let topHalfBlock;
      switch (direction) {
        case "north":
          new_direction = "south";
          topHalfBlock = block.south();
          break;
        case "south":
          new_direction = "north";
          topHalfBlock = block.north();
          break;
        case "east":
          new_direction = "west";
          topHalfBlock = block.west();
          break;
        case "west":
          new_direction = "east";
          topHalfBlock = block.east();
          break;
        default:
          event.cancel = true;
          return;
      }
      if (topHalfBlock && CAN_REPLACE.includes(topHalfBlock.typeId)) {
        topHalfBlock.setPermutation(BlockPermutation.resolve(event.permutationToPlace.type.id, { "botany_nat:bottom_half": false, "minecraft:cardinal_direction": new_direction }));
      } else {
        event.cancel = true;
        return;
      }
    },
    onRandomTick(event) {
      const { block } = event;
      if (!isValidBed(block)) {
        block.setType("minecraft:air");
      }
    }
  });
});
var SLEEPING_THROUGH_NIGHT = 0;
var ACTION_SLEEP = 0;
var INTERVAL = 1;
system2.runInterval(() => {
  if (!(world2.getTimeOfDay() >= TimeOfDay.Night) && !(WEATHER === "thunder"))
    return;
  const players = world2.getAllPlayers();
  const minSleeping = world2.gameRules.playersSleepingPercentage;
  let sleepingPlayers = 0;
  for (let player of players) {
    if (player.isSleeping) {
      sleepingPlayers += 1;
    } else if (player.hasTag(SLEEPING_TAG)) {
      sleepingPlayers += 1;
      if (ACTION_SLEEP == 2)
        return;
      const location = player.location;
      const block = player.dimension.getBlock({ x: location.x, y: location.y - 0.5, z: location.z });
      if (player.isSneaking || player.isJumping || !block || !block.hasTag("botany_nat:bed")) {
        playerStopSleeping(player);
      }
    }
  }
  if (sleepingPlayers == 0) {
    if (SLEEPING_THROUGH_NIGHT != 0)
      SLEEPING_THROUGH_NIGHT = 0;
    return;
  }
  const totalPlayers = players.length;
  const playersNeededToSleep = Math.ceil(minSleeping / 100 * totalPlayers);
  if (sleepingPlayers >= playersNeededToSleep) {
    SLEEPING_THROUGH_NIGHT += 1;
    if (SLEEPING_THROUGH_NIGHT > 60 / INTERVAL) {
      if (ACTION_SLEEP == 0)
        ACTION_SLEEP = 1;
      for (let player of players) {
        if (player.hasTag(SLEEPING_TAG)) {
          player.onScreenDisplay.setActionBar({ translate: "multiplayer.playersSkippingNight" });
        }
      }
    }
  } else {
    if (ACTION_SLEEP != 2)
      ACTION_SLEEP = 0;
    if (SLEEPING_THROUGH_NIGHT != 0)
      SLEEPING_THROUGH_NIGHT = 0;
    for (let player of players) {
      if (player.hasTag(SLEEPING_TAG)) {
        player.onScreenDisplay.setActionBar({ translate: "chat.type.sleeping", with: [`${sleepingPlayers}`, `${playersNeededToSleep - sleepingPlayers}`] });
      }
    }
  }
  if (ACTION_SLEEP == 1) {
    ACTION_SLEEP = 2;
    let fade_in = 1;
    let hold = 0.5;
    let fade_out = 0.5;
    for (let player of players) {
      if (player.hasTag(SLEEPING_TAG)) {
        player.camera.fade({ fadeTime: { fadeInTime: fade_in, holdTime: hold, fadeOutTime: fade_out } });
      }
    }
    system2.runTimeout(() => {
      OVERWORLD.runCommand("/time set day");
      if (WEATHER === "thunder")
        OVERWORLD.runCommand("/weather clear");
      ACTION_SLEEP = 0;
      SLEEPING_THROUGH_NIGHT = 0;
    }, fade_in * 20 + hold * 20 / 2);
    system2.runTimeout(() => {
      for (let player of players) {
        if (player.hasTag(SLEEPING_TAG)) {
          playerStopSleeping(player);
        }
      }
    }, fade_in * 20 + hold * 20 + fade_out * 20 / 2);
  }
}, INTERVAL);
world2.afterEvents.playerSpawn.subscribe((event) => {
  const player = event.player;
  if (player.hasTag(SLEEPING_TAG)) {
    playerStopSleeping(player);
  }
});
function initSleep(block, player) {
  let sleep_block = block;
  const bottomHalf = block.permutation.getState("botany_nat:bottom_half");
  if (!bottomHalf) {
    sleep_block = getOtherPart(block);
  }
  const nearby_players = sleep_block.dimension.getEntities({ location: sleep_block.center(), maxDistance: 0.5 });
  for (let nearby_player of nearby_players) {
    if (nearby_player.hasTag(SLEEPING_TAG)) {
      return;
    }
  }
  let topHalf = block;
  if (bottomHalf) {
    topHalf = getOtherPart(block);
  }
  let direction = sleep_block.permutation.getState("minecraft:cardinal_direction");
  let directionBlock;
  let cameraAdjustX = 0;
  let cameraAdjustZ = 0;
  let posOffsetX = 0;
  let posOffsetZ = 0;
  switch (direction) {
    case "north":
      directionBlock = sleep_block.south();
      cameraAdjustZ = -0.5;
      posOffsetZ = 0.45;
      break;
    case "south":
      directionBlock = sleep_block.north();
      cameraAdjustZ = 0.25;
      posOffsetZ = -0.45;
      break;
    case "east":
      directionBlock = sleep_block.west();
      cameraAdjustX = 0.25;
      posOffsetX = -0.45;
      break;
    case "west":
      directionBlock = sleep_block.east();
      cameraAdjustX = -0.5;
      posOffsetX = 0.45;
      break;
    default:
      directionBlock = sleep_block;
      break;
  }
  const location = sleep_block.center();
  const directionBlockFacing = {
    x: directionBlock.center().x,
    y: directionBlock.center().y + 2,
    z: directionBlock.center().z
  };
  player.teleport({ x: location.x + posOffsetX, y: location.y + 0.5, z: location.z + posOffsetZ }, { facingLocation: directionBlockFacing });
  const topHalfCenter = topHalf.center();
  const cameraLocation = {
    x: topHalfCenter.x + cameraAdjustX,
    y: topHalfCenter.y + 0.7,
    z: topHalfCenter.z + cameraAdjustZ
  };
  playerStartSleeping(player, cameraLocation, direction);
}
function playerStartSleeping(player, cameraLocation, facing) {
  player.runCommand("/camera @s clear");
  player.runCommand(`/camera @s set minecraft:free pos ${cameraLocation.x} ${cameraLocation.y} ${cameraLocation.z}`);
  player.runCommand(`/camera @s set minecraft:free facing ${player.location.x} ${player.location.y + 0.5} ${player.location.z}`);
  player.runCommand("/camera @s set minecraft:free ease 5 out_back rot 10 ~");
  player.runCommand(`/playanimation @s animation.botany_nat.sleeping.${facing} null 1000000`);
  player.runCommand("/inputpermission set @s camera disabled");
  player.runCommand("/inputpermission set @s move_backward disabled");
  player.runCommand("/inputpermission set @s move_forward disabled");
  player.runCommand("/inputpermission set @s move_left disabled");
  player.runCommand("/inputpermission set @s move_right disabled");
  player.addTag(SLEEPING_TAG);
}
function playerStopSleeping(player) {
  player.runCommand("/playanimation @s sleeping null 0.1");
  player.runCommand("/camera @s clear");
  player.runCommand("/inputpermission set @s camera enabled");
  player.runCommand("/playanimation @s animation.botany_nat.sleeping.north null 0.2");
  player.runCommand("/playanimation @s animation.botany_nat.sleeping.south null 0.2");
  player.runCommand("/playanimation @s animation.botany_nat.sleeping.east null 0.2");
  player.runCommand("/playanimation @s animation.botany_nat.sleeping.west null 0.2");
  player.runCommand("/inputpermission set @s move_backward enabled");
  player.runCommand("/inputpermission set @s move_forward enabled");
  player.runCommand("/inputpermission set @s move_left enabled");
  player.runCommand("/inputpermission set @s move_right enabled");
  player.teleport(player.location, { rotation: { x: 0, y: player.getRotation().y } });
  player.removeTag(SLEEPING_TAG);
}
world2.beforeEvents.playerBreakBlock.subscribe((data) => {
  const block = data.block;
  if (block.hasTag("botany_nat:bed")) {
    data.cancel = true;
    let drop_item = false;
    if (isValidBed(block)) {
      drop_item = true;
    }
    if (data.player.getGameMode() === "creative")
      drop_item = false;
    breakBed(block, drop_item);
  }
});
world2.beforeEvents.explosion.subscribe((event) => {
  const bedBlocks = event.getImpactedBlocks().filter((block) => block.permutation.hasTag("botany_nat:bed"));
  for (const block of bedBlocks) {
    if (block.permutation.getState("botany_nat:bottom_half")) {
      if (isValidBed(block)) {
        breakBed(block, true);
      }
    }
  }
});
function breakBed(block, drop_item) {
  system2.runTimeout(() => {
    const otherPartBlock = getOtherPart(block);
    if (otherPartBlock) {
      otherPartBlock.setType("minecraft:air");
    }
    if (drop_item) {
      const item = new ItemStack(block.typeId + "_item", 1);
      block.dimension.spawnItem(item, block.location);
    }
    block.dimension.playSound("dig.wood", block.location);
    block.setType("minecraft:air");
    clearSpawnPoints(block);
  }, 1);
}
function getOtherPart(block) {
  const bottomHalf = block.permutation.getState("botany_nat:bottom_half");
  const direction = block.permutation.getState("minecraft:cardinal_direction");
  let otherPartBlock;
  if (!bottomHalf) {
    switch (direction) {
      case "north":
        otherPartBlock = block.south();
        break;
      case "south":
        otherPartBlock = block.north();
        break;
      case "east":
        otherPartBlock = block.west();
        break;
      case "west":
        otherPartBlock = block.east();
        break;
      default:
        return null;
    }
  } else {
    switch (direction) {
      case "north":
        otherPartBlock = block.north();
        break;
      case "south":
        otherPartBlock = block.south();
        break;
      case "east":
        otherPartBlock = block.east();
        break;
      case "west":
        otherPartBlock = block.west();
        break;
      default:
        return null;
    }
  }
  return otherPartBlock;
}
function isValidBed(block) {
  const bottomHalf = block.permutation.getState("botany_nat:bottom_half");
  const otherPartBlock = getOtherPart(block);
  if (!otherPartBlock || !otherPartBlock.hasTag("botany_nat:bed")) {
    return false;
  }
  const otherPartBlockHalf = otherPartBlock.permutation.getState("botany_nat:bottom_half");
  if (!(bottomHalf && !otherPartBlockHalf || !bottomHalf && otherPartBlockHalf)) {
    return false;
  }
  return true;
}
function getCardinalDirection(player) {
  const yaw = player.getRotation().y;
  if (yaw >= -45 && yaw < 45)
    return "north";
  else if (yaw >= 45 && yaw < 135)
    return "east";
  else if (yaw >= 135 || yaw < -135)
    return "south";
  else
    return "west";
}
function getDistance(v1, v2) {
  return Math.sqrt(
    (v1.x - v2.x) ** 2 + (v1.y - v2.y) ** 2 + (v1.z - v2.z) ** 2
  );
}
function clearSpawnPoints(block) {
  const players = world2.getAllPlayers();
  for (let player of players) {
    const spawnPoint = player.getSpawnPoint();
    if (spawnPoint && getDistance(spawnPoint, block.location) < 2) {
      player.runCommand("/clearspawnpoint @s");
    }
  }
}
var BED_BLOCKS = [
  "botany_nat:white_botanic_bed",
  "botany_nat:orange_botanic_bed",
  "botany_nat:magenta_botanic_bed",
  "botany_nat:light_blue_botanic_bed",
  "botany_nat:yellow_botanic_bed",
  "botany_nat:lime_botanic_bed",
  "botany_nat:pink_botanic_bed",
  "botany_nat:gray_botanic_bed",
  "botany_nat:light_gray_botanic_bed",
  "botany_nat:cyan_botanic_bed",
  "botany_nat:purple_botanic_bed",
  "botany_nat:blue_botanic_bed",
  "botany_nat:brown_botanic_bed",
  "botany_nat:green_botanic_bed",
  "botany_nat:red_botanic_bed",
  "botany_nat:black_botanic_bed"
];
system2.runInterval(() => {
  const players = world2.getPlayers();
  for (let player of players) {
    const equippable = player.getComponent("minecraft:equippable");
    const mainhand = equippable?.getEquipmentSlot(EquipmentSlot.Mainhand);
    if (!mainhand)
      return;
    const selected_item = mainhand.getItem();
    if (selected_item && BED_BLOCKS.includes(selected_item.typeId)) {
      const amount = selected_item.amount;
      const bed_item = new ItemStack(`${selected_item.typeId}_item`, amount);
      mainhand.setItem(bed_item);
    }
  }
}, 5);

// data/system_template_esbuild/subscripts/default_init.ts
import { world as world3 } from "@minecraft/server";
function defaultInit() {
  let scoreboard = world3.scoreboard.getObjective("botany_nat_rng");
  if (scoreboard == void 0) {
    world3.getDimension("overworld").runCommandAsync("function botany/nat/init");
  }
}
defaultInit();

// data/system_template_esbuild/subscripts/display_item.ts
import { EquipmentSlot as EquipmentSlot2, ItemStack as ItemStack2, world as world4 } from "@minecraft/server";
var DisplayItem = class {
  constructor(display_items) {
    this.display_items = display_items;
  }
  init() {
    try {
      world4.beforeEvents.worldInitialize.subscribe((ev) => {
        ev.blockComponentRegistry.registerCustomComponent(
          "botany_nat:display_item_block_on_interact",
          {
            onPlayerInteract: (event) => {
              this.update_display_item(event);
            },
            onPlayerDestroy: (event) => {
              this.release_display_item(event);
            }
          }
        );
      });
    } catch {
    }
  }
  // Find the key for a given category and variant
  // Return current item attached to block / undefined
  find_display_item(flower_type, variant) {
    return Object.entries(this.display_items).find(
      ([key, value]) => value.flower_type === flower_type && value.variant === variant
    )?.[0];
  }
  // Get the current item attached to block
  // Return current item attached to block / undefined
  get_display_item(permutation) {
    return this.find_display_item(permutation.getState("botany_nat:flower_type"), permutation.getState("botany_nat:flower"));
  }
  // Check for updates to the display block state
  update_display_item(event) {
    const { block, dimension, player } = event;
    const equippable = player.getComponent("minecraft:equippable");
    if (!equippable)
      return;
    const mainhand = equippable.getEquipmentSlot(EquipmentSlot2.Mainhand);
    let current_item = this.get_display_item(block.permutation);
    if (!mainhand.hasItem()) {
      if (current_item != void 0 && current_item != "empty") {
        dimension.spawnItem(new ItemStack2(current_item), block.center());
        block.setPermutation(block.permutation.withState("botany_nat:flower_type", 0).withState("botany_nat:flower", 0));
      }
    } else {
      const display_item = this.display_items[mainhand.typeId];
      if (!display_item)
        return;
      if (current_item != void 0 && current_item != "empty") {
        if (mainhand.typeId == current_item)
          return;
        dimension.playSound("random.pop", block.center());
        dimension.spawnItem(new ItemStack2(current_item), block.center());
      }
      block.setPermutation(block.permutation.withState("botany_nat:flower_type", display_item.flower_type).withState("botany_nat:flower", display_item.variant));
      dimension.playSound(display_item.sound, block.center(), { volume: 0.5 });
      if (player.getGameMode() === "survival") {
        if (mainhand.amount > 1) {
          mainhand.amount--;
        } else {
          mainhand.setItem(void 0);
        }
      }
    }
  }
  // Check for update the block states
  release_display_item(event) {
    const { block, destroyedBlockPermutation, dimension } = event;
    let current_item = this.get_display_item(destroyedBlockPermutation);
    if (current_item != void 0 && current_item != "empty") {
      dimension.spawnItem(new ItemStack2(current_item), block.center());
    }
  }
};

// data/system_template_esbuild/subscripts/items.ts
var flower_pot_items = {
  "empty": { flower_type: 0, variant: 0, sound: "dig.grass" },
  "minecraft:azalea": { flower_type: 0, variant: 1, sound: "dig.grass" },
  "minecraft:flowering_azalea": { flower_type: 0, variant: 2, sound: "dig.grass" },
  "minecraft:cactus": { flower_type: 0, variant: 3, sound: "dig.grass" },
  "minecraft:bamboo": { flower_type: 0, variant: 4, sound: "dig.grass" },
  "minecraft:dandelion": { flower_type: 1, variant: 0, sound: "dig.grass" },
  "minecraft:azure_bluet": { flower_type: 1, variant: 1, sound: "dig.grass" },
  "minecraft:poppy": { flower_type: 1, variant: 2, sound: "dig.grass" },
  "minecraft:blue_orchid": { flower_type: 1, variant: 3, sound: "dig.grass" },
  "minecraft:allium": { flower_type: 1, variant: 4, sound: "dig.grass" },
  "minecraft:red_tulip": { flower_type: 1, variant: 5, sound: "dig.grass" },
  "minecraft:orange_tulip": { flower_type: 1, variant: 6, sound: "dig.grass" },
  "minecraft:white_tulip": { flower_type: 1, variant: 7, sound: "dig.grass" },
  "minecraft:pink_tulip": { flower_type: 1, variant: 8, sound: "dig.grass" },
  "minecraft:lily_of_the_valley": { flower_type: 1, variant: 9, sound: "dig.grass" },
  "minecraft:cornflower": { flower_type: 1, variant: 10, sound: "dig.grass" },
  "minecraft:wither_rose": { flower_type: 1, variant: 11, sound: "dig.grass" },
  "minecraft:torchflower": { flower_type: 1, variant: 12, sound: "dig.grass" },
  "minecraft:deadbush": { flower_type: 1, variant: 13, sound: "dig.grass" },
  "minecraft:fern": { flower_type: 1, variant: 14, sound: "dig.grass" },
  "minecraft:oxeye_daisy": { flower_type: 1, variant: 15, sound: "dig.grass" },
  "minecraft:oak_sapling": { flower_type: 2, variant: 0, sound: "dig.grass" },
  "minecraft:dark_oak_sapling": { flower_type: 2, variant: 1, sound: "dig.grass" },
  "minecraft:spruce_sapling": { flower_type: 2, variant: 2, sound: "dig.grass" },
  "minecraft:jungle_sapling": { flower_type: 2, variant: 3, sound: "dig.grass" },
  "minecraft:acacia_sapling": { flower_type: 2, variant: 4, sound: "dig.grass" },
  "minecraft:cherry_sapling": { flower_type: 2, variant: 5, sound: "dig.grass" },
  "minecraft:birch_sapling": { flower_type: 2, variant: 6, sound: "dig.grass" },
  "minecraft:mangrove_propagule": { flower_type: 2, variant: 7, sound: "dig.grass" },
  "minecraft:crimson_fungus": { flower_type: 2, variant: 8, sound: "dig.grass" },
  "minecraft:warped_fungus": { flower_type: 2, variant: 9, sound: "dig.grass" },
  "minecraft:brown_mushroom": { flower_type: 2, variant: 10, sound: "dig.grass" },
  "minecraft:red_mushroom": { flower_type: 2, variant: 11, sound: "dig.grass" },
  "minecraft:crimson_roots": { flower_type: 2, variant: 12, sound: "dig.grass" },
  "minecraft:warped_roots": { flower_type: 2, variant: 13, sound: "dig.grass" },
  "minecraft:pale_oak_sapling": { flower_type: 2, variant: 14, sound: "dig.grass" },
  "botany_nat:cosmos": { flower_type: 3, variant: 0, sound: "dig.grass" },
  "botany_nat:hibiscus": { flower_type: 3, variant: 1, sound: "dig.grass" },
  "botany_nat:hydrangea": { flower_type: 3, variant: 2, sound: "dig.grass" },
  "botany_nat:lavender": { flower_type: 3, variant: 3, sound: "dig.grass" },
  "botany_nat:primrose": { flower_type: 3, variant: 4, sound: "dig.grass" },
  "botany_nat:snapdragon": { flower_type: 3, variant: 5, sound: "dig.grass" },
  "botany_nat:ash_sapling_item": { flower_type: 3, variant: 6, sound: "dig.grass" },
  "botany_nat:baobab_sapling_item": { flower_type: 3, variant: 7, sound: "dig.grass" },
  "botany_nat:chestnut_sapling_item": { flower_type: 3, variant: 8, sound: "dig.grass" },
  "botany_nat:jacaranda_sapling_item": { flower_type: 3, variant: 9, sound: "dig.grass" },
  "botany_nat:maple_sapling_item": { flower_type: 3, variant: 10, sound: "dig.grass" },
  "botany_nat:redwood_sapling_item": { flower_type: 3, variant: 11, sound: "dig.grass" },
  "botany_nat:willow_sapling_item": { flower_type: 3, variant: 12, sound: "dig.grass" },
  "botany_nat:cherry_sapling_item": { flower_type: 3, variant: 13, sound: "dig.grass" },
  "botany_nat:mango_sapling_item": { flower_type: 3, variant: 14, sound: "dig.grass" },
  "botany_nat:orange_sapling_item": { flower_type: 3, variant: 15, sound: "dig.grass" },
  "botany_nat:peach_sapling_item": { flower_type: 4, variant: 0, sound: "dig.grass" },
  "botany_nat:coconut_sapling_item": { flower_type: 4, variant: 1, sound: "dig.grass" },
  "botany_nat:cactus_flower": { flower_type: 4, variant: 2, sound: "dig.grass" }
};
var flower_pot = new DisplayItem(flower_pot_items);
flower_pot.init();

// data/system_template_esbuild/subscripts/rotation.ts
import { world as world5 } from "@minecraft/server";
world5.beforeEvents.worldInitialize.subscribe((initEvent) => {
  initEvent.blockComponentRegistry.registerCustomComponent("botany_nat:flower_random_rotation", {
    onPlace: (customBlock) => {
      const randomRotation = Math.floor(Math.random() * 4);
      const setState = customBlock.block.permutation.withState("botany_nat:random_rotation", randomRotation);
      customBlock.block.setPermutation(setState);
    }
  });
  initEvent.blockComponentRegistry.registerCustomComponent("botany_nat:flower_random_texture", {
    onPlace: (customBlock) => {
      const randomRotation = Math.floor(Math.random() * 3);
      const setState = customBlock.block.permutation.withState("botany_nat:random_texture", randomRotation);
      customBlock.block.setPermutation(setState);
    }
  });
  initEvent.blockComponentRegistry.registerCustomComponent("botany_nat:random_rotation_lotus", {
    onPlace: (customBlock) => {
      const randomRotation = Math.floor(Math.random() * 7);
      const setState = customBlock.block.permutation.withState("botany_nat:random_rotation_lotus", randomRotation);
      customBlock.block.setPermutation(setState);
    }
  });
});

// data/system_template_esbuild/subscripts/bonemeal.ts
import { system as system3, world as world6 } from "@minecraft/server";
world6.beforeEvents.playerInteractWithBlock.subscribe(({ player, itemStack, block }) => {
  const item = itemStack?.typeId;
  const target = block?.typeId;
  let blockLocation = block.location;
  blockLocation = {
    x: block.location.x + (Math.floor(Math.random() * 6) - 2),
    y: block.location.y + 1,
    z: block.location.z + (Math.floor(Math.random() * 6) - 2)
  };
  const blockOverGrass = block.above(1)?.typeId;
  if (item === "minecraft:bone_meal" && target === "minecraft:grass_block" && blockOverGrass === "minecraft:air") {
    if (Math.random() > 0.5) {
      system3.run(() => {
        const spawnCustomFlower = Math.floor(Math.random() * 6);
        switch (spawnCustomFlower) {
          case 0:
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} air if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:lavender`);
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} short_grass if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:lavender`);
            break;
          case 1:
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} air if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:hibiscus`);
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} short_grass if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:hibiscus`);
            break;
          case 2:
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} air if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:hydrangea`);
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} short_grass if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:hydrangea`);
            break;
          case 3:
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} air if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:snapdragon`);
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} short_grass if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:snapdragon`);
            break;
          case 4:
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} air if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:cosmos`);
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} short_grass if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:cosmos`);
            break;
          case 5:
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} air if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:primrose`);
            player.runCommand(`execute if block ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} short_grass if block ${blockLocation.x} ${blockLocation.y - 0.5} ${blockLocation.z} grass_block run setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:primrose`);
            break;
          default:
            return;
        }
      });
    }
  }
});

// data/system_template_esbuild/subscripts/lotus_placing.ts
import { system as system4, world as world7 } from "@minecraft/server";
world7.beforeEvents.playerInteractWithBlock.subscribe(({ player, itemStack, block }) => {
  const item = itemStack?.typeId;
  const target = block.typeId;
  let blockLocation = block.location;
  blockLocation = {
    x: block.location.x,
    y: block.location.y + 1,
    z: block.location.z
  };
  if (item === "botany_nat:lotus_item" && target === "minecraft:water") {
    system4.run(() => {
      player.runCommand(`setblock ${blockLocation.x} ${blockLocation.y} ${blockLocation.z} botany_nat:lotus`);
      player.runCommand(`clear @s botany_nat:lotus_item 0 1`);
    });
  }
});

// data/system_template_esbuild/subscripts/guide.ts
import { world as world8, system as system5 } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
world8.beforeEvents.itemUse.subscribe((data) => {
  let player = data.source;
  if (data.itemStack.typeId == "botany_nat:guide_book")
    system5.run(() => botany_nat_main(player));
});
function botany_nat_main(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.title.main" }).body({ translate: "botany_nat.guide.body.main", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.about" }
    // "textures/botany/nat/ui/crops",
  ).button(
    { translate: "botany_nat.guide.button.crops" }
    // "textures/botany/nat/ui/crops",
  ).button(
    { translate: "botany_nat.guide.button.trees" }
    // "textures/botany/nat/ui/crops",
  ).button(
    { translate: "botany_nat.guide.button.botanic" }
    // "textures/botany/nat/ui/crops",
  ).button(
    { translate: "botany_nat.guide.button.flowers" }
    // "textures/botany/nat/ui/crops",
  ).button(
    { translate: "botany_nat.guide.button.insects" }
    // "textures/botany/nat/ui/crops",
  ).button(
    { translate: "botany_nat.guide.button.other" }
    // "textures/botany/nat/ui/crops",
  ).button(
    { translate: "botany_nat.guide.button.exit" }
    // "textures/botany/nat/ui/exit",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      about(player);
    if (r.selection == 1)
      crops(player);
    if (r.selection == 2)
      trees(player);
    if (r.selection == 3)
      botanic(player);
    if (r.selection == 4)
      flowers(player);
    if (r.selection == 5)
      insects(player);
    if (r.selection == 6)
      other(player);
  });
}
function about(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.about.title" }).body({ translate: "botany_nat.guide.about.body", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      botany_nat_main(player);
  });
}
function crops(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title" }).body({ translate: "botany_nat.guide.crops.body", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  ).button(
    { translate: "botany_nat.guide.crops.button.tomato" },
    "textures/botany/nat/items/tomato"
  ).button(
    { translate: "botany_nat.guide.crops.button.corn" },
    "textures/botany/nat/items/corn"
  ).button(
    { translate: "botany_nat.guide.crops.button.pepper" },
    "textures/botany/nat/items/pepper"
  ).button(
    { translate: "botany_nat.guide.crops.button.lettuce" },
    "textures/botany/nat/items/lettuce"
  ).button(
    { translate: "botany_nat.guide.crops.button.pineapple" },
    "textures/botany/nat/items/pineapple"
  ).button(
    { translate: "botany_nat.guide.crops.button.blueberry" },
    "textures/botany/nat/items/blueberries"
  ).button(
    { translate: "botany_nat.guide.crops.button.strawberry" },
    "textures/botany/nat/items/strawberries"
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      botany_nat_main(player);
    if (r.selection == 1)
      tomato(player);
    if (r.selection == 2)
      corn(player);
    if (r.selection == 3)
      pepper(player);
    if (r.selection == 4)
      lettuce(player);
    if (r.selection == 5)
      pineapple(player);
    if (r.selection == 6)
      blueberry(player);
    if (r.selection == 7)
      strawberry(player);
  });
}
function tomato(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title.tomato" }).body({ translate: "botany_nat.guide.crops.body.tomato", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      crops(player);
  });
}
function corn(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title.corn" }).body({ translate: "botany_nat.guide.crops.body.corn", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      crops(player);
  });
}
function pepper(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title.pepper" }).body({ translate: "botany_nat.guide.crops.body.pepper", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      crops(player);
  });
}
function lettuce(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title.lettuce" }).body({ translate: "botany_nat.guide.crops.body.lettuce", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      crops(player);
  });
}
function pineapple(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title.pineapple" }).body({ translate: "botany_nat.guide.crops.body.pineapple", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      crops(player);
  });
}
function blueberry(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title.blueberry" }).body({ translate: "botany_nat.guide.crops.body.blueberry", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      crops(player);
  });
}
function strawberry(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.crops.title.strawberry" }).body({ translate: "botany_nat.guide.crops.body.strawberry", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      crops(player);
  });
}
function trees(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title" }).body({ translate: "botany_nat.guide.trees.body", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  ).button(
    { translate: "botany_nat.guide.trees.button.mangoe_tree" },
    "textures/botany/nat/blocks/sapling_mango"
  ).button(
    { translate: "botany_nat.guide.trees.button.orange_tree" },
    "textures/botany/nat/blocks/sapling_orange"
  ).button(
    { translate: "botany_nat.guide.trees.button.peache_tree" },
    "textures/botany/nat/blocks/sapling_peach"
  ).button(
    { translate: "botany_nat.guide.trees.button.cherry_tree" },
    "textures/botany/nat/blocks/sapling_cherry"
  ).button(
    { translate: "botany_nat.guide.trees.button.coconut_tree" },
    "textures/botany/nat/blocks/sapling_coconut"
  ).button(
    { translate: "botany_nat.guide.trees.button.willow_tree" },
    "textures/botany/nat/blocks/sapling_willow"
  ).button(
    { translate: "botany_nat.guide.trees.button.baobab_tree" },
    "textures/botany/nat/blocks/sapling_baobab"
  ).button(
    { translate: "botany_nat.guide.trees.button.maple_tree" },
    "textures/botany/nat/blocks/sapling_maple"
  ).button(
    { translate: "botany_nat.guide.trees.button.redwood_tree" },
    "textures/botany/nat/blocks/sapling_redwood"
  ).button(
    { translate: "botany_nat.guide.trees.button.jacaranda_tree" },
    "textures/botany/nat/blocks/sapling_jacaranda"
  ).button(
    { translate: "botany_nat.guide.trees.button.chestnut_tree" },
    "textures/botany/nat/blocks/sapling_chestnut"
  ).button(
    { translate: "botany_nat.guide.trees.button.ash_tree" },
    "textures/botany/nat/blocks/sapling_ash"
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      botany_nat_main(player);
    if (r.selection == 1)
      mangoe_tree(player);
    if (r.selection == 2)
      orange_tree(player);
    if (r.selection == 3)
      peache_tree(player);
    if (r.selection == 4)
      cherry_tree(player);
    if (r.selection == 5)
      coconut_tree(player);
    if (r.selection == 6)
      willow_tree(player);
    if (r.selection == 7)
      baobab_tree(player);
    if (r.selection == 8)
      maple_tree(player);
    if (r.selection == 9)
      redwood_tree(player);
    if (r.selection == 10)
      jacaranda_tree(player);
    if (r.selection == 11)
      chestnut_tree(player);
    if (r.selection == 12)
      ash_tree(player);
  });
}
function botanic(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.botanic.title" }).body({ translate: "botany_nat.guide.botanic.body", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      botany_nat_main(player);
  });
}
function mangoe_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.mangoe_tree" }).body({ translate: "botany_nat.guide.trees.body.mangoe_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function orange_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.orange_tree" }).body({ translate: "botany_nat.guide.trees.body.orange_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function peache_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.peache_tree" }).body({ translate: "botany_nat.guide.trees.body.peache_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function cherry_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.cherry_tree" }).body({ translate: "botany_nat.guide.trees.body.cherry_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function coconut_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.coconut_tree" }).body({ translate: "botany_nat.guide.trees.body.coconut_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function willow_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.willow_tree" }).body({ translate: "botany_nat.guide.trees.body.willow_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function baobab_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.baobab_tree" }).body({ translate: "botany_nat.guide.trees.body.baobab_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function maple_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.maple_tree" }).body({ translate: "botany_nat.guide.trees.body.maple_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function redwood_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.redwood_tree" }).body({ translate: "botany_nat.guide.trees.body.redwood_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function jacaranda_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.jacaranda_tree" }).body({ translate: "botany_nat.guide.trees.body.jacaranda_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function chestnut_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.chestnut_tree" }).body({ translate: "botany_nat.guide.trees.body.chestnut_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function ash_tree(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.trees.title.ash_tree" }).body({ translate: "botany_nat.guide.trees.body.ash_tree", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      trees(player);
  });
}
function flowers(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title" }).body({ translate: "botany_nat.guide.flowers.body", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  ).button(
    { translate: "botany_nat.guide.flowers.button.lavender" },
    "textures/botany/nat/blocks/lavender"
  ).button(
    { translate: "botany_nat.guide.flowers.button.hibiscus" },
    "textures/botany/nat/blocks/hibiscus"
  ).button(
    { translate: "botany_nat.guide.flowers.button.lotus" },
    "textures/botany/nat/items/lotus_item"
  ).button(
    { translate: "botany_nat.guide.flowers.button.hydrangea" },
    "textures/botany/nat/blocks/hydrangea"
  ).button(
    { translate: "botany_nat.guide.flowers.button.snapdragon" },
    "textures/botany/nat/blocks/snapdragon"
  ).button(
    { translate: "botany_nat.guide.flowers.button.cosmos" },
    "textures/botany/nat/blocks/cosmos"
  ).button(
    { translate: "botany_nat.guide.flowers.button.primrose" },
    "textures/botany/nat/blocks/primrose"
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      botany_nat_main(player);
    if (r.selection == 1)
      lavender(player);
    if (r.selection == 2)
      hibiscus(player);
    if (r.selection == 3)
      lotus(player);
    if (r.selection == 4)
      hydrangea(player);
    if (r.selection == 5)
      snapdragon(player);
    if (r.selection == 6)
      cosmos(player);
    if (r.selection == 7)
      primrose(player);
  });
}
function lavender(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title.lavender" }).body({ translate: "botany_nat.guide.flowers.body.lavender", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      flowers(player);
  });
}
function hibiscus(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title.hibiscus" }).body({ translate: "botany_nat.guide.flowers.body.hibiscus", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      flowers(player);
  });
}
function lotus(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title.lotus" }).body({ translate: "botany_nat.guide.flowers.body.lotusato", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      flowers(player);
  });
}
function hydrangea(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title.hydrangea" }).body({ translate: "botany_nat.guide.flowers.body.hydrangea", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      flowers(player);
  });
}
function snapdragon(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title.snapdragon" }).body({ translate: "botany_nat.guide.flowers.body.snapdragon", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      flowers(player);
  });
}
function cosmos(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title.cosmos" }).body({ translate: "botany_nat.guide.flowers.body.cosmosato", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      flowers(player);
  });
}
function primrose(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.flowers.title.primrose" }).body({ translate: "botany_nat.guide.flowers.body.primrose", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      flowers(player);
  });
}
function insects(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.insects.title" }).body({ translate: "botany_nat.guide.insects.body", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  ).button(
    { translate: "botany_nat.guide.insects.button.butterfly" },
    "textures/botany/nat/items/butterfly"
  ).button(
    { translate: "botany_nat.guide.insects.button.dragonfly" },
    "textures/botany/nat/items/dragonfly"
  ).button(
    { translate: "botany_nat.guide.insects.button.firefly" },
    "textures/botany/nat/items/firefly"
  ).button(
    { translate: "botany_nat.guide.insects.button.ladybug" },
    "textures/botany/nat/items/ladybug"
  ).button(
    { translate: "botany_nat.guide.insects.button.ant" },
    "textures/botany/nat/items/ant"
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      botany_nat_main(player);
    if (r.selection == 1)
      butterfly(player);
    if (r.selection == 2)
      dragonfly(player);
    if (r.selection == 3)
      firefly(player);
    if (r.selection == 4)
      ladybug(player);
    if (r.selection == 5)
      ant(player);
  });
}
function butterfly(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.insects.title.butterfly" }).body({ translate: "botany_nat.guide.insects.body.butterfly", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      insects(player);
  });
}
function dragonfly(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.insects.title.dragonfly" }).body({ translate: "botany_nat.guide.insects.body.dragonfly", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      insects(player);
  });
}
function firefly(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.insects.title.firefly" }).body({ translate: "botany_nat.guide.insects.body.firefly", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      insects(player);
  });
}
function ladybug(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.insects.title.ladybug" }).body({ translate: "botany_nat.guide.insects.body.ladybug", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      insects(player);
  });
}
function ant(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.insects.title.ant" }).body({ translate: "botany_nat.guide.insects.body.ant", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      insects(player);
  });
}
function other(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title" }).body({ translate: "botany_nat.guide.other.body", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  ).button(
    { translate: "botany_nat.guide.other.button.picnic_basket" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.plate" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.picnic_carpet" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.picnic_table" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.hanging_flower_basket" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.mossy_stone_lantern" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.firefly_lantern" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.stone_path" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.mushroom" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.mushroom_on_logs" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.rocks" }
    // "textures/botany/nat/entity/empty",
  ).button(
    { translate: "botany_nat.guide.other.button.moss_on_top_of_logs" }
    // "textures/botany/nat/entity/empty",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      botany_nat_main(player);
    if (r.selection == 1)
      picnic_basket(player);
    if (r.selection == 2)
      plate(player);
    if (r.selection == 3)
      picnic_carpet(player);
    if (r.selection == 4)
      picnic_table(player);
    if (r.selection == 5)
      hanging_flower_basket(player);
    if (r.selection == 6)
      mossy_stone_lantern(player);
    if (r.selection == 7)
      firefly_lantern(player);
    if (r.selection == 8)
      stone_path(player);
    if (r.selection == 9)
      mushroom(player);
    if (r.selection == 10)
      mushroom_on_logs(player);
    if (r.selection == 11)
      rocks(player);
    if (r.selection == 12)
      moss_on_top_of_logs(player);
  });
}
function picnic_basket(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.picnic_basket" }).body({ translate: "botany_nat.guide.other.body.picnic_basket", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function plate(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.plate" }).body({ translate: "botany_nat.guide.other.body.plate", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function picnic_carpet(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.picnic_carpet" }).body({ translate: "botany_nat.guide.other.body.picnic_carpet", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function picnic_table(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.picnic_table" }).body({ translate: "botany_nat.guide.other.body.picnic_table", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function hanging_flower_basket(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.hanging_flower_basket" }).body({ translate: "botany_nat.guide.other.body.hanging_flower_basket", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function mossy_stone_lantern(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.mossy_stone_lantern" }).body({ translate: "botany_nat.guide.other.body.mossy_stone_lantern", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function firefly_lantern(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.firefly_lantern" }).body({ translate: "botany_nat.guide.other.body.firefly_lantern", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function stone_path(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.stone_path" }).body({ translate: "botany_nat.guide.other.body.stone_path", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function mushroom(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.mushroom" }).body({ translate: "botany_nat.guide.other.body.mushroom", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function mushroom_on_logs(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.mushroom_on_logs" }).body({ translate: "botany_nat.guide.other.body.mushroom_on_logs", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function rocks(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.rocks" }).body({ translate: "botany_nat.guide.other.body.rocks", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}
function moss_on_top_of_logs(player) {
  player.playSound("item.book.page_turn", { pitch: 1, volume: 1 });
  const form = new ActionFormData().title({ translate: "botany_nat.guide.other.title.moss_on_top_of_logs" }).body({ translate: "botany_nat.guide.other.body.moss_on_top_of_logs", with: ["\n"] }).button(
    { translate: "botany_nat.guide.button.back" }
    // "textures/botany/nat/ui/back",
  );
  form.show(player).then((r) => {
    if (r.selection == 0)
      other(player);
  });
}

// data/system_template_esbuild/subscripts/give_guide.ts
import { world as world9 } from "@minecraft/server";
var NAMESPACE = "botany_nat:";
var TAG = "guide_book";
var PATH_NAMESPACE = "botany/nat/";
world9.afterEvents.playerSpawn.subscribe((event) => {
  givePlayerEq(event.player);
});
function givePlayerEq(player) {
  player.runCommand(
    `execute as @s[tag=!${NAMESPACE.substring(
      0,
      NAMESPACE.length - 1
    )}_${TAG}] at @s run loot spawn ~ ~ ~ loot "${PATH_NAMESPACE}guide.loot"`
  );
  player.runCommand(
    `tag @s[tag=!${NAMESPACE.substring(
      0,
      NAMESPACE.length - 1
    )}] add ${NAMESPACE.substring(0, NAMESPACE.length - 1)}_${TAG}`
  );
}

// data/system_template_esbuild/subscripts/basket.ts
import { world as world10, ItemStack as ItemStack3 } from "@minecraft/server";
var DEBUG = false;
var foodTypes = {
  "botany_nat:pineapple": 1,
  "botany_nat:pepper": 2,
  "botany_nat:strawberries": 3,
  "botany_nat:corn": 4,
  "botany_nat:lettuce": 5,
  "botany_nat:tomato": 6,
  "botany_nat:mango": 7,
  "botany_nat:cherry": 8,
  "botany_nat:blueberries": 9,
  "botany_nat:peach": 10,
  "botany_nat:coconut": 11,
  "botany_nat:orange": 12,
  "minecraft:bread": 13,
  "minecraft:baked_potato": 14,
  "minecraft:cookie": 15,
  "minecraft:carrot": 16,
  "minecraft:apple": 17,
  "minecraft:melon_slice": 18,
  "minecraft:sweet_berries": 19,
  "minecraft:glow_berries": 20,
  "minecraft:beetroot": 21,
  "minecraft:golden_apple": 22,
  "minecraft:enchanted_golden_apple": 23,
  "minecraft:golden_carrot": 24,
  "minecraft:potato": 25,
  "minecraft:poisonous_potato": 26,
  "minecraft:dried_kelp": 27,
  "minecraft:cake": 28,
  "minecraft:cooked_beef": 29,
  "minecraft:cooked_chicken": 30,
  "minecraft:cooked_mutton": 31,
  "minecraft:cooked_porkchop": 32,
  "minecraft:cooked_rabbit": 33,
  "minecraft:cooked_cod": 34,
  "minecraft:cooked_salmon": 35,
  "minecraft:pumpkin_pie": 36,
  "minecraft:mushroom_stew": 37,
  "minecraft:rabbit_stew": 38,
  "minecraft:suspicious_stew": 39
};
world10.afterEvents.itemUse.subscribe(async (event) => {
  const { itemStack, source } = event;
  if (itemStack.typeId === "botany_nat:picnic_basket") {
    const item = itemStack;
    const player = source;
    const viewDirection = player.getViewDirection();
    const playerLocation = player.getHeadLocation();
    const raycastOptions = {
      includeLiquidBlocks: false,
      includePassableBlocks: false,
      maxDistance: 7
    };
    const hitBlock = player.dimension.getBlockFromRay(playerLocation, viewDirection, raycastOptions)?.block.center();
    let summonPosition;
    if (hitBlock) {
      summonPosition = {
        x: hitBlock.x - viewDirection.x * 0.1,
        // Lekko przed blokiem
        y: hitBlock.y - viewDirection.y * 0.6,
        z: hitBlock.z - viewDirection.z * 0.1
      };
    } else
      return;
    const entity = player.dimension.spawnEntity("botany_nat:picnic_basket_entity", summonPosition);
    let numberToFood = "";
    const inventory = entity.getComponent("inventory").container;
    for (let i = 0; i < inventory.size; i++) {
      const basketSlot = item.getDynamicProperty(`botany_nat:basket_slot_${i}`) ?? { x: 0, y: 0, z: 0 };
      for (const foodName in foodTypes) {
        if (basketSlot.x === foodTypes[foodName]) {
          numberToFood = foodName;
          break;
        }
      }
      if (basketSlot.y > 0)
        entity.runCommand(`/replaceitem entity @s slot.inventory ${i} ${numberToFood} ${basketSlot.y}`);
      if (DEBUG)
        console.warn(`Slot: ${i}, Food: ${numberToFood}, Number ${basketSlot.y}`);
    }
    player.runCommand("/replaceitem entity @s slot.weapon.mainhand 0 air");
  }
});
world10.afterEvents.entityHurt.subscribe((event) => {
  const entity = event.hurtEntity;
  const player = event.damageSource.damagingEntity;
  if (entity.typeId === "botany_nat:picnic_basket_entity") {
    const item = new ItemStack3("botany_nat:picnic_basket");
    const location = entity.location;
    let foodToNumber;
    const inventory = entity.getComponent("inventory").container;
    for (let i = 0; i < inventory.size; i++) {
      const itemInEq = inventory.getItem(i);
      if (itemInEq) {
        if (DEBUG)
          console.warn(`Slot ${i}: ${itemInEq.typeId} (${itemInEq.amount}x)`);
        if (itemInEq.typeId in foodTypes) {
          for (const foodName in foodTypes) {
            if (itemInEq.typeId === foodName) {
              foodToNumber = foodTypes[foodName];
              break;
            }
          }
          item.setDynamicProperty(`botany_nat:basket_slot_${i}`, { x: foodToNumber, y: itemInEq.amount, z: 0 });
          entity.runCommand(`/replaceitem entity @s slot.inventory ${i} air`);
        }
      }
    }
    world10.getDimension("overworld").spawnItem(item, location);
    entity.runCommand("event entity @s despawn_drop");
  }
});
world10.afterEvents.entitySpawn.subscribe((event) => {
  const entity = event.entity;
  if (entity.typeId === "botany_nat:picnic_basket_entity") {
    const name = BeforeEachChar(entity.typeId, "\xA7");
    entity.nameTag = name + "\xA7r";
  }
});
function BeforeEachChar(str, A) {
  return str.split("").map((char) => A + char).join("");
}

// data/system_template_esbuild/subscripts/blocks.ts
import { world as world11 } from "@minecraft/server";
world11.beforeEvents.worldInitialize.subscribe((initEvent) => {
  initEvent.blockComponentRegistry.registerCustomComponent("botany_nat:random_rotation_rock", {
    onPlace: (customBlock) => {
      const randomRotation = Math.floor(Math.random() * 3);
      const setState = customBlock.block.permutation.withState("botany_nat:random_rotation_rock", randomRotation);
      customBlock.block.setPermutation(setState);
    }
  });
  initEvent.blockComponentRegistry.registerCustomComponent("botany_nat:random_variant_two", {
    onPlace: (customBlock) => {
      const randomRotation = Math.floor(Math.random() * 2);
      const setState = customBlock.block.permutation.withState("botany_nat:random_variant_two", randomRotation);
      customBlock.block.setPermutation(setState);
    }
  });
});

// data/system_template_esbuild/subscripts/destroy_blocks.ts
import { world as world12 } from "@minecraft/server";
world12.afterEvents.playerBreakBlock.subscribe((event) => {
  const player = event.player;
  const block = event.block;
  const location = block.location;
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~ ~ ~-1 botany_nat:mushroom_log [ "minecraft:block_face" = "north", "botany_nat:random_variant_two" = 1] run setblock ~ ~ ~-1 air destroy`);
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~ ~ ~1 botany_nat:mushroom_log [ "minecraft:block_face" = "south", "botany_nat:random_variant_two" = 1] run setblock ~ ~ ~1 air destroy`);
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~1 ~ ~ botany_nat:mushroom_log [ "minecraft:block_face" = "east", "botany_nat:random_variant_two" = 1] run setblock ~1 ~ ~ air destroy`);
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~-1 ~ ~ botany_nat:mushroom_log [ "minecraft:block_face" = "west", "botany_nat:random_variant_two" = 1] run setblock ~-1 ~ ~ air destroy`);
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~ ~ ~-1 botany_nat:mushroom_log [ "minecraft:block_face" = "north", "botany_nat:random_variant_two" = 0] run setblock ~ ~ ~-1 air destroy`);
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~ ~ ~1 botany_nat:mushroom_log [ "minecraft:block_face" = "south", "botany_nat:random_variant_two" = 0] run setblock ~ ~ ~1 air destroy`);
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~1 ~ ~ botany_nat:mushroom_log [ "minecraft:block_face" = "east", "botany_nat:random_variant_two" = 0] run setblock ~1 ~ ~ air destroy`);
  player.runCommand(`/execute positioned ${location.x} ${location.y} ${location.z} if block ~-1 ~ ~ botany_nat:mushroom_log [ "minecraft:block_face" = "west", "botany_nat:random_variant_two" = 0] run setblock ~-1 ~ ~ air destroy`);
});

// data/system_template_esbuild/subscripts/plants.ts
import { ItemEnchantableComponent, system as system7, world as world13 } from "@minecraft/server";
import { EquipmentSlot as EquipmentSlot3, GameMode as GameMode2 } from "@minecraft/server";
import { EntityEquippableComponent } from "@minecraft/server";
world13.beforeEvents.worldInitialize.subscribe((data) => {
  data.blockComponentRegistry.registerCustomComponent("botany_nat:plant_tomato", new PlantBlock("botany_nat:growth", 4, { numerator: 1, denominator: 5 }, true, false));
  data.blockComponentRegistry.registerCustomComponent("botany_nat:plant_corn", new PlantBlock("botany_nat:growth", 4, { numerator: 1, denominator: 5 }, true, false));
  data.blockComponentRegistry.registerCustomComponent("botany_nat:plant_pepper", new PlantBlock("botany_nat:growth", 4, { numerator: 1, denominator: 5 }, true, false));
  data.blockComponentRegistry.registerCustomComponent("botany_nat:plant_lettuce", new PlantBlock("botany_nat:growth", 4, { numerator: 1, denominator: 5 }, true, false));
  data.blockComponentRegistry.registerCustomComponent("botany_nat:plant_pineapple", new PlantBlock("botany_nat:growth", 4, { numerator: 1, denominator: 5 }, true, false));
  data.blockComponentRegistry.registerCustomComponent("botany_nat:plant_blueberries", new PlantBlock("botany_nat:growth", 4, { numerator: 1, denominator: 5 }, true, true));
  data.blockComponentRegistry.registerCustomComponent("botany_nat:plant_strawberries", new PlantBlock("botany_nat:growth", 4, { numerator: 1, denominator: 5 }, true, true));
});
function randomNumberInt(min, max) {
  let result = Math.random() * (max - min) + min;
  return Math.round(result);
}
function randomNumber(min, max) {
  return Math.random() * (max - min) + min;
}
world13.beforeEvents.playerBreakBlock.subscribe((data) => {
  const { block, itemStack, dimension } = data;
  if (!block.hasTag("botany_nat:disable_silk_touch"))
    return;
  if (!itemStack)
    return;
  const EnchancComponent = itemStack.getComponent(ItemEnchantableComponent.componentId);
  if (!EnchancComponent)
    return;
  if (!EnchancComponent.hasEnchantment("silk_touch"))
    return;
  data.cancel = true;
  system7.runTimeout(() => {
    BlockManager.destroyBlock(dimension, block.location);
  });
});
var PlantBlock = class {
  constructor(stateId, maxStage, growthChance, bonemealable, nonDestroyHarvest) {
    __publicField(this, "onRandomTick", (data) => {
      const { block } = data;
      const random = randomNumber(0, this.growthChance.denominator);
      if (random > this.growthChance.numerator)
        return;
      const state = block.permutation.getState(this.stateId);
      if (state >= this.maxStage)
        return;
      block.setPermutation(block.permutation.withState(this.stateId, state + 1));
    });
    __publicField(this, "onPlayerInteract", (data) => {
      if (!this.bonemealable)
        return;
      const { player, block, dimension } = data;
      if (!player)
        return;
      const state = block.permutation.getState(this.stateId);
      if (state == this.maxStage && this.nonDestroyHarvest) {
        let setStage2 = this.maxStage - 1;
        block.setPermutation(block.permutation.withState(this.stateId, setStage2));
        const blockType = block.typeId;
        if (blockType === "botany_nat:blueberries_block")
          BlockManager.spawnLootBlueberries(dimension, block.location);
        if (blockType === "botany_nat:strawberries_block")
          BlockManager.spawnLootStrawberries(dimension, block.location);
        return;
      }
      const mainhand = PlayerManager.getEquipmentSlot(player, EquipmentSlot3.Mainhand);
      const item = mainhand.getItem();
      if (item?.typeId != "minecraft:bone_meal")
        return;
      if (state >= this.maxStage)
        return;
      if (player.getGameMode() != GameMode2.creative)
        mainhand.setItem(ItemManager.decreaseStack(item));
      let setStage = state + randomNumberInt(1, 3);
      if (setStage > this.maxStage)
        setStage = this.maxStage;
      block.setPermutation(block.permutation.withState(this.stateId, setStage));
      const center = block.center();
      block.dimension.playSound("item.bone_meal.use", center);
      block.dimension.spawnParticle("minecraft:crop_growth_emitter", center);
    });
    __publicField(this, "maxStage", 0);
    __publicField(this, "stateId", "");
    __publicField(this, "growthChance", { numerator: 0, denominator: 0 });
    __publicField(this, "bonemealable");
    __publicField(this, "nonDestroyHarvest");
    this.stateId = stateId;
    this.maxStage = maxStage;
    this.growthChance = growthChance;
    this.bonemealable = bonemealable;
    this.nonDestroyHarvest = nonDestroyHarvest;
  }
};
var BlockManager = class {
  static getBlock(dimension, location) {
    try {
      return dimension.getBlock(location);
    } catch {
      return void 0;
    }
  }
  static destroyBlock(dimension, location) {
    const { x, y, z } = location;
    dimension.runCommand(`setblock ${x} ${y} ${z} air destroy`);
  }
  static spawnLootBlueberries(dimension, location) {
    const { x, y, z } = location;
    dimension.runCommand(`/loot spawn ${x} ${y} ${z} loot "botany/nat/blueberries_4.loot"`);
  }
  static spawnLootStrawberries(dimension, location) {
    const { x, y, z } = location;
    dimension.runCommand(`/loot spawn ${x} ${y} ${z} loot "botany/nat/strawberries_4.loot"`);
  }
};
var ItemManager = class {
  static decreaseStack(item) {
    if (item.amount > 1) {
      item.amount = item.amount - 1;
      return item;
    } else
      return void 0;
  }
};
var PlayerManager = class {
  static getEquipmentSlot(player, EquipmentSlot8) {
    return player.getComponent(EntityEquippableComponent.componentId).getEquipmentSlot(EquipmentSlot8);
  }
};

// data/system_template_esbuild/subscripts/leaves.ts
import { world as world14, system as system8, ItemStack as ItemStack4 } from "@minecraft/server";
var wood_types = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var log_blocks = wood_types.flatMap((wood) => [
  `botany_nat:${wood}_log`,
  `botany_nat:${wood}_wood`,
  `botany_nat:stripped_${wood}_log`,
  `botany_nat:stripped_${wood}_wood`
]);
var leaves_blocks = wood_types.map((wood) => `botany_nat:${wood}_leaves`);
var LEAVES_PROCCESS = 0;
world14.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:leaves",
    {
      onRandomTick(data) {
        if (LEAVES_PROCCESS > 20)
          return;
        LEAVES_PROCCESS += 1;
        const shouldDecay = data.block.permutation.getState("botany_nat:should_decay");
        if (!shouldDecay) {
          LEAVES_PROCCESS -= 1;
          return;
        }
        system8.runTimeout(() => {
          try {
            leafDecay(data.block);
          } catch {
          }
        }, LEAVES_PROCCESS);
        system8.runTimeout(() => {
          LEAVES_PROCCESS -= 1;
        }, 20);
      },
      beforeOnPlayerPlace(event2) {
        event2.permutationToPlace = event2.permutationToPlace.withState("botany_nat:should_decay", false);
      }
    }
  );
});
function leafDecay(block) {
  const currentTier = block.permutation.getState("botany_nat:decay_tier") || 0;
  const newDecayTier = getNewDecayTier(block, currentTier);
  if (newDecayTier === 0) {
    leafDrop(block);
  } else if (newDecayTier !== currentTier) {
    block.setPermutation(block.permutation.withState("botany_nat:decay_tier", newDecayTier));
  }
}
function getNewDecayTier(block, currentTier) {
  if (hasNearbyLog(block, 3)) {
    return currentTier;
  }
  let num = Math.random();
  if (num > 0.4) {
    return Math.max(0, currentTier - 1);
  } else if (num < 0.6) {
    leafDrop(block);
  }
  return currentTier;
}
function hasNearbyLog(block, radius) {
  const prevents_decaying = block.permutation.getState("botany_nat:prevent_decaying") ?? false;
  try {
    for (let dx = -radius; dx <= radius; dx++) {
      for (let dy = -radius; dy <= radius; dy++) {
        for (let dz = -radius; dz <= radius; dz++) {
          const checkLocation = {
            x: block.location.x + dx,
            y: block.location.y + dy,
            z: block.location.z + dz
          };
          const checkBlock = block.dimension.getBlock(checkLocation);
          if (checkBlock && log_blocks.includes(checkBlock.typeId)) {
            if (!prevents_decaying)
              block.setPermutation(block.permutation.withState("botany_nat:prevent_decaying", true));
            return true;
          }
          if (!prevents_decaying && checkBlock?.permutation?.getState("botany_nat:prevent_decaying")) {
            return true;
          }
        }
      }
    }
    if (prevents_decaying) {
      block.setPermutation(block.permutation.withState("botany_nat:prevent_decaying", false));
      return true;
    }
    return false;
  } catch (error) {
    return false;
  }
}
function leafDrop(block) {
  const block_id = block.typeId;
  const { x, y, z } = block.location;
  system8.runTimeout(() => {
    try {
      block.dimension.runCommand(`/fill ${x} ${y} ${z} ${x} ${y} ${z} air [] replace ${block.typeId}`);
      block.dimension.runCommand(`/loot spawn ${x} ${y} ${z} loot "botany/nat/${block_id.replace("botany_nat:", "")}.loot"`);
    } catch {
    }
  }, 1);
}
world14.beforeEvents.playerBreakBlock.subscribe((eventData) => {
  const { block, player } = eventData;
  if (!leaves_blocks.includes(block.typeId) || player.getGameMode() === "creative")
    return;
  const inventory = player.getComponent("inventory");
  const selectedItem = inventory?.container.getItem(player.selectedSlotIndex);
  const hasSilkTouch = getSilkTouchEnchantment(selectedItem);
  if (selectedItem && selectedItem.typeId === "minecraft:shears" && !hasSilkTouch) {
    const spawnItem = block.typeId;
    system8.runTimeout(() => {
      block.dimension.spawnItem(new ItemStack4(spawnItem, 1), block.location);
    }, 1);
  } else if (!hasSilkTouch) {
    const block_id = block.typeId;
    const { x, y, z } = block.location;
    system8.runTimeout(() => {
      block.dimension.runCommand(`/loot spawn ${x} ${y} ${z} loot "botany/nat/${block_id.replace("botany_nat:", "")}.loot"`);
    }, 1);
  }
});
function getSilkTouchEnchantment(item) {
  let hasSilkTouch = false;
  try {
    const enchantableComponent = item.getComponent("minecraft:enchantable");
    if (enchantableComponent) {
      const enchantments = enchantableComponent.getEnchantments();
      for (const enchant of enchantments) {
        if (enchant.type.id === "silk_touch") {
          hasSilkTouch = true;
        }
      }
    }
  } catch (error) {
  }
  return hasSilkTouch;
}

// data/system_template_esbuild/subscripts/leaves_particle.ts
import { world as world15, system as system9, LocationInUnloadedChunkError } from "@minecraft/server";
var PARTICLES = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var INTERVAL2 = 5;
system9.runInterval(() => {
  const players = world15.getPlayers();
  let alreadyProcessed = /* @__PURE__ */ new Set();
  for (let player of players) {
    try {
      if (alreadyProcessed.has(player))
        continue;
      const nearbyPlayers = player.dimension.getEntities({ location: player.location, maxDistance: 32, type: "minecraft:player" });
      for (let otherPlayer of nearbyPlayers) {
        if (otherPlayer.nameTag !== player.nameTag) {
          alreadyProcessed.add(otherPlayer);
        }
      }
      playParticle(player);
    } catch (error) {
      if (error.name !== LocationInUnloadedChunkError.name) {
        console.warn(error);
      }
    }
  }
}, INTERVAL2);
function playParticle(player) {
  for (let particle of PARTICLES) {
    player.dimension.spawnParticle(`botany_nat:${particle}_leaves_detector`, player.location);
  }
}

// data/system_template_esbuild/subscripts/sapling.ts
import { world as world16, system as system10, ItemStack as ItemStack5, EquipmentSlot as EquipmentSlot4, EntityComponentTypes, GameMode as GameMode3 } from "@minecraft/server";
var wood_types2 = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var sapling_blocks = wood_types2.map((wood) => `botany_nat:${wood}_sapling`);
var STRUCTURES_DATA = {
  "willow": [
    { "width": 12, "height": 12, "sappling_offset_x": 5, "sappling_offset_z": 5 },
    { "width": 14, "height": 17, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 12, "height": 15, "sappling_offset_x": 5, "sappling_offset_z": 6 },
    { "width": 12, "height": 14, "sappling_offset_x": 5, "sappling_offset_z": 5 },
    { "width": 13, "height": 15, "sappling_offset_x": 6, "sappling_offset_z": 6 }
  ],
  "coconut": [
    { "width": 8, "height": 12, "sappling_offset_x": 4, "sappling_offset_z": 4 },
    { "width": 7, "height": 14, "sappling_offset_x": 3, "sappling_offset_z": 3 },
    { "width": 7, "height": 10, "sappling_offset_x": 3, "sappling_offset_z": 2 },
    { "width": 7, "height": 12, "sappling_offset_x": 3, "sappling_offset_z": 3 },
    { "width": 7, "height": 18, "sappling_offset_x": 3, "sappling_offset_z": 3 },
    { "width": 8, "height": 12, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 7, "height": 14, "sappling_offset_x": 2, "sappling_offset_z": 3 },
    { "width": 7, "height": 10, "sappling_offset_x": 3, "sappling_offset_z": 1 },
    { "width": 10, "height": 14, "sappling_offset_x": 3, "sappling_offset_z": 3 }
  ],
  "baobab": [
    { "width": 21, "height": 28, "sappling_offset_x": 10, "sappling_offset_z": 12 },
    { "width": 23, "height": 31, "sappling_offset_x": 11, "sappling_offset_z": 11 },
    { "width": 21, "height": 25, "sappling_offset_x": 9, "sappling_offset_z": 9 },
    { "width": 25, "height": 35, "sappling_offset_x": 10, "sappling_offset_z": 12 },
    { "width": 20, "height": 29, "sappling_offset_x": 10, "sappling_offset_z": 10 }
  ],
  "redwood": [
    { "width": 9, "height": 26, "sappling_offset_x": 3, "sappling_offset_z": 4 },
    { "width": 8, "height": 25, "sappling_offset_x": 3, "sappling_offset_z": 3 },
    { "width": 7, "height": 21, "sappling_offset_x": 3, "sappling_offset_z": 3 },
    { "width": 7, "height": 20, "sappling_offset_x": 3, "sappling_offset_z": 3 },
    { "width": 6, "height": 20, "sappling_offset_x": 2, "sappling_offset_z": 2 },
    { "width": 5, "height": 11, "sappling_offset_x": 2, "sappling_offset_z": 2 }
  ],
  "maple": [
    { "width": 9, "height": 17, "sappling_offset_x": 4, "sappling_offset_z": 3 },
    { "width": 11, "height": 15, "sappling_offset_x": 4, "sappling_offset_z": 5 },
    { "width": 10, "height": 15, "sappling_offset_x": 4, "sappling_offset_z": 4 },
    { "width": 9, "height": 15, "sappling_offset_x": 3, "sappling_offset_z": 4 },
    { "width": 10, "height": 17, "sappling_offset_x": 3, "sappling_offset_z": 4 }
  ],
  "chestnut": [
    { "width": 19, "height": 23, "sappling_offset_x": 9, "sappling_offset_z": 9 },
    { "width": 15, "height": 18, "sappling_offset_x": 7, "sappling_offset_z": 7 },
    { "width": 17, "height": 18, "sappling_offset_x": 7, "sappling_offset_z": 7 }
  ],
  "jacaranda": [
    { "width": 20, "height": 14, "sappling_offset_x": 9, "sappling_offset_z": 8 },
    { "width": 22, "height": 15, "sappling_offset_x": 10, "sappling_offset_z": 9 },
    { "width": 23, "height": 15, "sappling_offset_x": 11, "sappling_offset_z": 9 },
    { "width": 22, "height": 13, "sappling_offset_x": 10, "sappling_offset_z": 8 }
  ],
  "ash": [
    { "width": 14, "height": 19, "sappling_offset_x": 5, "sappling_offset_z": 7 },
    { "width": 18, "height": 21, "sappling_offset_x": 9, "sappling_offset_z": 8 },
    { "width": 17, "height": 19, "sappling_offset_x": 8, "sappling_offset_z": 7 },
    { "width": 16, "height": 20, "sappling_offset_x": 6, "sappling_offset_z": 6 }
  ],
  "mango": [
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 15, "height": 17, "sappling_offset_x": 7, "sappling_offset_z": 5 },
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 14, "height": 14, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 13, "height": 17, "sappling_offset_x": 6, "sappling_offset_z": 6 }
  ],
  "orange": [
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 15, "height": 17, "sappling_offset_x": 7, "sappling_offset_z": 5 },
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 14, "height": 14, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 13, "height": 17, "sappling_offset_x": 6, "sappling_offset_z": 6 }
  ],
  "peach": [
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 15, "height": 17, "sappling_offset_x": 7, "sappling_offset_z": 5 },
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 14, "height": 14, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 13, "height": 17, "sappling_offset_x": 6, "sappling_offset_z": 6 }
  ],
  "cherry": [
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 15, "height": 17, "sappling_offset_x": 7, "sappling_offset_z": 5 },
    { "width": 14, "height": 16, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 14, "height": 14, "sappling_offset_x": 6, "sappling_offset_z": 6 },
    { "width": 13, "height": 17, "sappling_offset_x": 6, "sappling_offset_z": 6 }
  ]
};
world16.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:sapling",
    {
      onRandomTick(data) {
        const { block } = data;
        if (!block)
          return;
        if (Math.random() < 0.45) {
          const currentStage = block.permutation.getState("botany_nat:growth_stage") || 0;
          const newStage = Math.min(currentStage + 1, 2);
          block.setPermutation(block.permutation.withState("botany_nat:growth_stage", newStage));
          if (newStage === 2) {
            tryGrow(block);
          }
        }
      },
      onPlayerInteract(data) {
        const { player, block } = data;
        if (!player)
          return;
        if (!block)
          return;
        const equipment = player.getComponent("equippable");
        const selectedItem = equipment?.getEquipment("Mainhand");
        if (!selectedItem)
          return;
        if (selectedItem.typeId === "minecraft:bone_meal") {
          const center = block.center();
          block.dimension.playSound("item.bone_meal.use", center);
          block.dimension.spawnParticle("minecraft:crop_growth_emitter", center);
          if (player.getGameMode() != GameMode3.creative) {
            equipment?.setEquipment("Mainhand", decreaseStack(selectedItem));
          }
          const currentStage = block.permutation.getState("botany_nat:growth_stage") || 0;
          if (Math.random() < 0.45) {
            const newStage = Math.min(currentStage + 1, 2);
            block.setPermutation(block.permutation.withState("botany_nat:growth_stage", newStage));
            if (newStage === 2) {
              tryGrow(block);
            }
          }
        }
      }
    }
  );
});
function decreaseStack(item) {
  if (item.amount > 1) {
    item.amount = item.amount - 1;
    return item;
  } else {
    return void 0;
  }
}
var replaceable_blocks = [
  "minecraft:short_grass",
  "minecraft:tall_grass",
  "minecraft:water",
  "minecraft:lava",
  "minecraft:red_flower",
  "minecraft:brown_mushroom",
  "minecraft:red_mushroom",
  "minecraft:deadbush",
  "minecraft:snow_layer"
];
function tryGrow(block) {
  if (!block.typeId.includes("sapling"))
    return;
  const name = block.typeId.replace("botany_nat:", "").replace("_sapling", "");
  if (!STRUCTURES_DATA[name]) {
    console.warn(`Structure properties for "${name}" not found.`);
    return;
  }
  const { index, structure } = getRandomStructure(name);
  const structure_name = `botany_nat:${name + "_tree_" + (index + 1)}`;
  const structure_rotation = getRandomRotation();
  let check = areaCheckFirst(block, structure.height);
  if (check === false) {
    return;
  }
  const { adjusted_x, adjusted_z } = adjustPositionForRotation(
    structure.width,
    structure.sappling_offset_x,
    structure.sappling_offset_z,
    structure_rotation
  );
  const location = block.location;
  const start = {
    x: location.x + adjusted_x - (structure.width - 1),
    y: location.y,
    z: location.z + adjusted_z - (structure.width - 1)
  };
  const end = {
    x: location.x + adjusted_x + (structure.width - 1),
    y: location.y + structure.height,
    z: location.z + adjusted_z + (structure.width - 1)
  };
  block.setType("minecraft:air");
  for (let replaceable_block of replaceable_blocks) {
    block.dimension.runCommand(
      `/fill 
			${location.x - 5} ${location.y} ${location.z - 5}
			${location.x + 5} ${location.y} ${location.z + 5}
			air replace ${replaceable_block}
			`
    );
  }
  block.dimension.runCommand(`/structure delete botany_nat:temp_tree`);
  for (let y = start.y; y <= end.y; y += 6) {
    const currentEndY = Math.min(y + 5, end.y);
    block.dimension.runCommand(`/fill ${start.x} ${y} ${start.z} ${end.x} ${currentEndY} ${end.z} minecraft:structure_void replace minecraft:air`);
  }
  block.dimension.runCommand(`/structure save botany_nat:temp_tree ${start.x} ${start.y} ${start.z} ${end.x} ${end.y} ${end.z} false memory`);
  for (let y = start.y; y <= end.y; y += 6) {
    const currentEndY = Math.min(y + 5, end.y);
    block.dimension.runCommand(`/fill ${start.x} ${y} ${start.z} ${end.x} ${currentEndY} ${end.z} minecraft:air replace minecraft:structure_void`);
  }
  block.dimension.runCommand(`/structure load "${structure_name}" ${location.x + adjusted_x} ${location.y} ${location.z + adjusted_z} ${structure_rotation}_degrees`);
  block.dimension.runCommand(`/structure load botany_nat:temp_tree ${start.x} ${start.y} ${start.z}`);
}
function areaCheckFirst(block, height) {
  const startY = block.location.y;
  const max_height = Math.max(height - 5, 5);
  try {
    for (let y = startY + 1; y <= startY + max_height; y++) {
      const checkBlock = block.dimension.getBlock({ x: block.location.x, y, z: block.location.z });
      if (checkBlock.typeId !== "minecraft:air" && !checkBlock.typeId.includes("_leaves")) {
        return false;
      }
    }
  } catch {
    return false;
  }
}
function getRandomStructure(name) {
  const structures = STRUCTURES_DATA[name];
  let index = Math.floor(Math.random() * structures.length);
  const structure = structures[index];
  return { index, structure };
}
function getRandomRotation() {
  const angles = [0, 90, 180, 270];
  const randomIndex = Math.floor(Math.random() * angles.length);
  return angles[randomIndex];
}
function adjustPositionForRotation(width, sappling_offset_x, sappling_offset_z, angle_degrees) {
  switch (angle_degrees) {
    case 0:
      return { adjusted_x: -sappling_offset_x, adjusted_z: -sappling_offset_z };
    case 90:
      return { adjusted_x: -(width - 1 - sappling_offset_z), adjusted_z: -sappling_offset_x };
    case 180:
      return { adjusted_x: -(width - 1 - sappling_offset_x), adjusted_z: -(width - 1 - sappling_offset_z) };
    case 270:
      return { adjusted_x: -sappling_offset_z, adjusted_z: -(width - 1 - sappling_offset_x) };
    default:
      throw new Error(`Invalid rotation angle: ${angle_degrees}`);
  }
}
world16.afterEvents.entitySpawn.subscribe((event) => {
  const entity = event.entity;
  if (!entity || entity.typeId !== "minecraft:item")
    return;
  const itemComponent = entity.getComponent(EntityComponentTypes.Item);
  if (!itemComponent)
    return;
  const item = itemComponent.itemStack;
  if (!item || !sapling_blocks.includes(item.typeId))
    return;
  const newItem = new ItemStack5(item.typeId + "_item", item.amount);
  entity.dimension.spawnItem(newItem, entity.location);
  entity.remove();
});
system10.runInterval(() => {
  const players = world16.getPlayers();
  for (let player of players) {
    const equippable = player.getComponent("minecraft:equippable");
    const mainhand = equippable?.getEquipmentSlot(EquipmentSlot4.Mainhand);
    if (!mainhand)
      return;
    const selected_item = mainhand.getItem();
    if (selected_item && sapling_blocks.includes(selected_item.typeId)) {
      const amount = selected_item.amount;
      const sapling_item = new ItemStack5(`${selected_item.typeId}_item`, amount);
      mainhand.setItem(sapling_item);
    }
  }
}, 5);

// data/system_template_esbuild/subscripts/trapdoor.ts
import { world as world17, BlockPermutation as BlockPermutation2 } from "@minecraft/server";
world17.beforeEvents.worldInitialize.subscribe((eventData) => {
  eventData.blockComponentRegistry.registerCustomComponent("botany_nat:trapdoor_interact", {
    onTick(event) {
      const block = event.block;
      if (!block || block.typeId === "minecraft:air") {
        return;
      }
      const powered = (block.getRedstonePower() || 0) > 0;
      if (block.permutation.getState("botany_nat:powered") === false) {
        if (powered) {
          block.setPermutation(block.permutation.withState("botany_nat:powered", true));
          if (block.permutation.getState("botany_nat:open") === true)
            return;
          block.dimension.playSound("open.wooden_trapdoor", block.location, { pitch: 1, volume: 1 });
          try {
            block.setPermutation(block.permutation.withState("botany_nat:open", true));
          } catch {
          }
        }
      } else {
        if (!powered) {
          block.setPermutation(block.permutation.withState("botany_nat:powered", false));
          block.dimension.playSound("close.wooden_trapdoor", block.location, { pitch: 1, volume: 1 });
          try {
            block.setPermutation(block.permutation.withState("botany_nat:open", false));
          } catch {
          }
        }
      }
    },
    onPlayerInteract(event) {
      const { block, player } = event;
      if (!player)
        return;
      const currentState = block.permutation.getState("botany_nat:open");
      const newOpenState = !currentState;
      const newPermutation = BlockPermutation2.resolve(block.typeId, {
        ...block.permutation.getAllStates(),
        "botany_nat:open": newOpenState
      });
      block.setPermutation(newPermutation);
      const sound = currentState ? "open.wooden_trapdoor" : "close.wooden_trapdoor";
      player.playSound(sound, { "location": block.location });
    }
  });
});

// data/system_template_esbuild/subscripts/wood_stripping.ts
import { world as world18, BlockPermutation as BlockPermutation3, GameMode as GameMode4 } from "@minecraft/server";
var wood_types3 = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var custom_wood_blocks = wood_types3.flatMap((wood) => [
  `botany_nat:${wood}_log`,
  `botany_nat:${wood}_wood`
]);
world18.beforeEvents.itemUseOn.subscribe(async (event) => {
  await null;
  const block = event.block;
  const player = event.source;
  const inventory = player.getComponent("inventory");
  const equipment = player.getComponent("equippable");
  const selectedItem = equipment?.getEquipment("Mainhand");
  if (selectedItem && selectedItem.hasTag("minecraft:is_axe")) {
    if (!custom_wood_blocks.includes(block.typeId))
      return;
    try {
      stripLog(
        player,
        block,
        selectedItem,
        inventory,
        player.selectedSlotIndex
      );
      return;
    } catch (error) {
      console.warn(`Error in Stripping Log: ${error.message}`);
    }
  }
});
function stripLog(player, block, selectedItem, inventory, selectedSlotIndex) {
  let strippedLogType = block.typeId.replace("botany_nat:", "botany_nat:stripped_");
  const currentPermutation = block.permutation;
  const blockStates = currentPermutation.getAllStates();
  const customBlockFace = blockStates["minecraft:block_face"];
  const strippedLogPermutation = BlockPermutation3.resolve(
    strippedLogType
  ).withState("minecraft:block_face", customBlockFace);
  block.setPermutation(strippedLogPermutation);
  player.playSound("hit.wood", { "location": block.location });
  if (player.getGameMode() !== GameMode4.creative)
    applyDurabilityDamage(player, selectedItem, inventory, selectedSlotIndex);
}
function applyDurabilityDamage(player, item, inventory, slotIndex) {
  const durabilityComponent = item.getComponent("minecraft:durability");
  if (durabilityComponent) {
    const { unbreakingLevel } = getRelevantEnchantments(item);
    if (Math.random() < 1 / (unbreakingLevel + 1)) {
      const newDamage = durabilityComponent.damage + 1;
      if (newDamage >= durabilityComponent.maxDurability) {
        inventory.container.setItem(slotIndex, void 0);
        player.playSound("random.break");
      } else {
        durabilityComponent.damage = newDamage;
        inventory.container.setItem(slotIndex, item);
      }
    }
  }
}
function getRelevantEnchantments(item) {
  let unbreakingLevel = 0;
  let hasSilkTouch = false;
  try {
    const enchantableComponent = item.getComponent("minecraft:enchantable");
    if (enchantableComponent) {
      const enchantments = enchantableComponent.getEnchantments();
      for (const enchant of enchantments) {
        if (enchant.type.id === "unbreaking") {
          unbreakingLevel = enchant.level;
        } else if (enchant.type.id === "silk_touch") {
          hasSilkTouch = true;
        }
      }
    }
  } catch (error) {
  }
  return { unbreakingLevel, hasSilkTouch };
}

// data/system_template_esbuild/subscripts/slabs.ts
import { world as world19, system as system11, BlockPermutation as BlockPermutation4, Direction, ItemStack as ItemStack6 } from "@minecraft/server";
var wood_types4 = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var isSlab = wood_types4.flatMap((wood) => [
  `botany_nat:${wood}_slab`
]);
world19.beforeEvents.playerBreakBlock.subscribe((eventData) => {
  const { block, player } = eventData;
  if (!isSlab.includes(block.typeId) || player.getGameMode() === "creative")
    return;
  const isDoubleSlab = block.permutation.getState("botany_nat:double");
  if (isDoubleSlab) {
    const blockItem = new ItemStack6(block.typeId, 1);
    const dimension = block.dimension;
    system11.runTimeout(() => {
      dimension.spawnItem(blockItem, block.location);
    }, 1);
  }
});
world19.beforeEvents.worldInitialize.subscribe((eventData) => {
  eventData.blockComponentRegistry.registerCustomComponent("botany_nat:slab", {
    onPlayerInteract(event) {
      const { block, player, face } = event;
      if (!player)
        return;
      const equipment = player.getComponent("equippable");
      const selectedItem = equipment?.getEquipment("Mainhand");
      if (!selectedItem || selectedItem === void 0)
        return;
      const result = getBlockStatesAndDirection(
        player,
        selectedItem,
        face
      );
      if (!result)
        return;
      const { stateName, stateValue } = result;
      let adjacentBlockPos;
      switch (face) {
        case "North":
          adjacentBlockPos = { x: block.x, y: block.y, z: block.z - 1 };
          break;
        case "South":
          adjacentBlockPos = { x: block.x, y: block.y, z: block.z + 1 };
          break;
        case "East":
          adjacentBlockPos = { x: block.x + 1, y: block.y, z: block.z };
          break;
        case "West":
          adjacentBlockPos = { x: block.x - 1, y: block.y, z: block.z };
          break;
        case "Up":
          adjacentBlockPos = { x: block.x, y: block.y + 1, z: block.z };
          break;
        case "Down":
          adjacentBlockPos = { x: block.x, y: block.y - 1, z: block.z };
          break;
      }
      const adjacentBlock = event.dimension.getBlock(adjacentBlockPos);
      if (["minecraft:air", "minecraft:water", "minecraft:lava"].includes(adjacentBlock.typeId)) {
        const verticalHalf = block.permutation.getState(
          "minecraft:vertical_half"
        );
        if (isSlab.includes(selectedItem.typeId)) {
          const isBottomUp = verticalHalf === "bottom" && face === "Up";
          const isTopDown = verticalHalf === "top" && face === "Down";
          if ((isBottomUp || isTopDown) && selectedItem.typeId === block.typeId) {
            if (!block.permutation.getState("botany_nat:double")) {
              block.setPermutation(block.permutation.withState("botany_nat:double", true));
              player.playSound("dig.wood", { "location": block.location, "volume": 0.4, "pitch": 0.8 });
              if (player.getGameMode() !== "creative") {
                if (selectedItem.amount === 1) {
                  equipment?.setEquipment("Mainhand", void 0);
                } else {
                  selectedItem.amount -= 1;
                  equipment?.setEquipment("Mainhand", selectedItem);
                }
              }
            } else {
              placeSlab(
                player,
                selectedItem,
                adjacentBlockPos,
                face,
                equipment,
                block,
                true
              );
            }
          } else if (block.permutation.getState("botany_nat:double")) {
            placeSlab(
              player,
              selectedItem,
              adjacentBlockPos,
              face,
              equipment,
              block,
              true
            );
          } else {
            placeSlab(
              player,
              selectedItem,
              adjacentBlockPos,
              face,
              equipment,
              block,
              false
            );
          }
        } else {
          const commandBlock = stateName ? `setblock ${adjacentBlockPos.x} ${adjacentBlockPos.y} ${adjacentBlockPos.z} ${selectedItem.typeId} ["${stateName}"="${stateValue}"]` : `setblock ${adjacentBlockPos.x} ${adjacentBlockPos.y} ${adjacentBlockPos.z} ${selectedItem.typeId}`;
          system11.runTimeout(() => {
            try {
              const current_equipment = player.getComponent("equippable");
              const current_selectedItem = current_equipment?.getEquipment("Mainhand");
              if (!current_selectedItem || current_selectedItem.typeId !== selectedItem.typeId)
                return;
              customBlockPlaysound(player, selectedItem.typeId, adjacentBlockPos);
              player.runCommand(commandBlock);
              if (player.getGameMode() !== "creative") {
                if (selectedItem.amount === 1) {
                  equipment.setEquipment("Mainhand", void 0);
                } else {
                  selectedItem.amount -= 1;
                  equipment.setEquipment("Mainhand", selectedItem);
                }
              }
            } catch (error) {
              console.warn(`Error: ${error.message}`);
            }
          }, 1);
        }
      }
    }
  });
});
function customBlockPlaysound(player, id, location) {
  if (id.endsWith("_log") || id.endsWith("_wood") || id.endsWith("_planks") || id.endsWith("_fence")) {
    player.playSound("dig.wood", { "location": location, "volume": 0.4, "pitch": 0.8 });
    return;
  }
  if (id === "minecraft:sand" || id.endsWith("_sand")) {
    player.playSound("dig.sand", { "location": location, "volume": 0.4, "pitch": 0.8 });
    return;
  }
  player.playSound("dig.stone", { "location": location, "volume": 0.4, "pitch": 0.8 });
}
function placeSlab(player, selectedItem, adjacentBlockPos, face, equipment, targetBlock, isDoubleSlab) {
  let verticalHalf;
  const raycastOptions = {
    maxDistance: 5,
    // Adjust as needed
    includePassableBlocks: false
  };
  const raycastHit = player.getBlockFromViewDirection(raycastOptions);
  if (raycastHit && isDoubleSlab) {
    const faceLocation = raycastHit.faceLocation;
    if (face === "Up" || face === "Down") {
      verticalHalf = face === "Up" ? "bottom" : "top";
    } else {
      verticalHalf = faceLocation.y > 0.5 ? "top" : "bottom";
    }
  } else {
    if (face === "Up") {
      verticalHalf = "bottom";
    } else if (face === "Down") {
      verticalHalf = "top";
    } else {
      if (isSlab.includes(targetBlock.typeId)) {
        verticalHalf = targetBlock.permutation.getState(
          "minecraft:vertical_half"
        );
      } else {
        verticalHalf = "bottom";
      }
    }
  }
  const command = `setblock ${adjacentBlockPos.x} ${adjacentBlockPos.y} ${adjacentBlockPos.z} ${selectedItem.typeId} ["minecraft:vertical_half"="${verticalHalf}"]`;
  system11.runTimeout(() => {
    try {
      const current_equipment = player.getComponent("equippable");
      const current_selectedItem = current_equipment?.getEquipment("Mainhand");
      if (!current_selectedItem || current_selectedItem.typeId !== selectedItem.typeId)
        return;
      player.runCommand(command);
      player.playSound("dig.wood", { "location": adjacentBlockPos.location, "volume": 0.4, "pitch": 0.8 });
      if (player.getGameMode() !== "creative") {
        if (selectedItem.amount === 1) {
          equipment.setEquipment("Mainhand", void 0);
        } else {
          selectedItem.amount -= 1;
          equipment.setEquipment("Mainhand", selectedItem);
        }
      }
    } catch (error) {
      console.warn(`Error: ${error.message}`);
    }
  }, 1);
}
function getBlockStatesAndDirection(player, selectedItem, face) {
  try {
    BlockPermutation4.resolve(selectedItem.typeId);
  } catch {
    return null;
  }
  const blockPermutation = BlockPermutation4.resolve(selectedItem.typeId);
  const blockStates = blockPermutation.getAllStates();
  let stateName;
  let stateValue;
  const statePriority = [
    "minecraft:block_face",
    "minecraft:cardinal_direction",
    "pillar_axis"
  ];
  for (const state of statePriority) {
    if (blockStates[state] !== void 0) {
      stateName = state;
      if (state === "pillar_axis") {
        if (["North", "South"].includes(face)) {
          stateValue = "z";
        } else if (["East", "West"].includes(face)) {
          stateValue = "x";
        } else {
          stateValue = "y";
        }
      } else if (state === "minecraft:cardinal_direction") {
        const rotation = player.getRotation();
        const rad = rotation.y * Math.PI / 180;
        const directionX = -Math.sin(rad);
        const directionZ = Math.cos(rad);
        if (Math.abs(directionX) > Math.abs(directionZ)) {
          stateValue = directionX > 0 ? "east" : "west";
        } else {
          stateValue = directionZ > 0 ? "south" : "north";
        }
      } else if (state === "minecraft:block_face") {
        stateValue = face.toLowerCase();
      } else {
        stateValue = blockStates[state];
      }
      break;
    }
  }
  return { stateName, stateValue };
}
var slabUseTimestamps = /* @__PURE__ */ new Map();
var minUseDelay = 2;
world19.beforeEvents.playerInteractWithBlock.subscribe((event) => {
  const block = event.block;
  const player = event.player;
  const item = event.itemStack;
  const playerId = player.id;
  const lastUseTimestamp = slabUseTimestamps.get(playerId) ?? 0;
  const currentTime = system11.currentTick;
  if (currentTime - lastUseTimestamp < minUseDelay && player.getGameMode() != "creative") {
    return;
  }
  slabUseTimestamps.set(playerId, currentTime);
  if (item && isSlab.includes(item.typeId)) {
    const raycastOptions = {
      maxDistance: 10,
      includePassableBlocks: false
    };
    const raycastHit = player.getBlockFromViewDirection(raycastOptions);
    if (raycastHit) {
      const face = raycastHit.face;
      if (raycastHit.block.typeId === item.typeId)
        return;
      let target_block;
      if (face === Direction.North)
        target_block = block.north();
      if (face === Direction.South)
        target_block = block.south();
      if (face === Direction.East)
        target_block = block.east();
      if (face === Direction.West)
        target_block = block.west();
      if (face === Direction.Up)
        target_block = block.above();
      if (face === Direction.Down)
        target_block = block.below();
      if (target_block && target_block.typeId === item.typeId) {
        system11.runTimeout(() => {
          const equipment = player.getComponent("equippable");
          const selectedItem = equipment?.getEquipment("Mainhand");
          if (!selectedItem || selectedItem === void 0)
            return;
          if (selectedItem.typeId === item.typeId) {
            if (target_block) {
              if (target_block.permutation.getState("botany_nat:double") === true)
                return;
              target_block.setPermutation(target_block.permutation.withState("botany_nat:double", true));
              player.playSound("dig.wood", { "location": target_block.location, "volume": 0.4, "pitch": 0.8 });
              try {
                if (player.getGameMode() !== "creative") {
                  if (selectedItem.amount === 1) {
                    equipment?.setEquipment("Mainhand", void 0);
                  } else {
                    selectedItem.amount -= 1;
                    equipment?.setEquipment("Mainhand", selectedItem);
                  }
                }
              } catch (error) {
                console.warn(`Error: ${error.message}`);
              }
            }
          }
        }, 1);
      }
    }
  }
});

// data/system_template_esbuild/subscripts/fence_gate.ts
import { system as system12, world as world20, BlockPermutation as BlockPermutation5, BlockTypes } from "@minecraft/server";
world20.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:fence_gate",
    {
      onTick(event2) {
        const block = event2.block;
        if (!block || block.typeId === "minecraft:air") {
          return;
        }
        const topHalf = block.permutation.getState("botany_nat:invisible");
        if (topHalf)
          return;
        let doorPart;
        try {
          doorPart = block.above(1);
        } catch {
        }
        const blocksToUpdate = [block, doorPart];
        const powered = (block.getRedstonePower() || 0) > 0;
        if (block.permutation.getState("botany_nat:powered") === false) {
          if (powered) {
            block.setPermutation(block.permutation.withState("botany_nat:powered", true));
            if (block.permutation.getState("botany_nat:open") === true)
              return;
            block.dimension.playSound("open.fence_gate", block.location, { pitch: 1, volume: 1 });
            for (const door of blocksToUpdate) {
              try {
                door.setPermutation(door.permutation.withState("botany_nat:open", true));
              } catch {
              }
            }
          }
        } else {
          if (!powered) {
            block.setPermutation(block.permutation.withState("botany_nat:powered", false));
            block.dimension.playSound("close.fence_gate", block.location, { pitch: 1, volume: 1 });
            for (const door of blocksToUpdate) {
              try {
                door.setPermutation(door.permutation.withState("botany_nat:open", false));
              } catch {
              }
            }
          }
        }
      },
      onPlace(event2) {
        const { block } = event2;
        const aboveBlock = block.above();
        const currentStates = block.permutation.getAllStates();
        const cardinalDirection = currentStates["minecraft:cardinal_direction"];
        if (aboveBlock && aboveBlock.typeId === "minecraft:air") {
          const newAboveStates = { ...currentStates };
          if (cardinalDirection === "south") {
            delete newAboveStates["minecraft:cardinal_direction"];
          }
          newAboveStates["botany_nat:invisible"] = true;
          const placeBlock = block.typeId;
          aboveBlock.setPermutation(BlockPermutation5.resolve(placeBlock, newAboveStates));
        }
      },
      onPlayerInteract(event2) {
        const { block, player, face } = event2;
        if (!player)
          return;
        const equipment = player.getComponent("equippable");
        const selectedItem = equipment?.getEquipment("Mainhand");
        if (!equipment)
          return;
        if (selectedItem && face === "Up" && BlockTypes.get(selectedItem.typeId)) {
          const aboveBlock2 = block.above();
          if (aboveBlock2 && aboveBlock2.permutation.hasTag("botany_nat:fence_gate") && aboveBlock2.permutation.getState("botany_nat:invisible")) {
            aboveBlock2.setType(selectedItem.typeId);
            customBlockPlaysound2(player, selectedItem.typeId, aboveBlock2.location);
            if (player.getGameMode() !== "creative") {
              if (selectedItem.amount > 1) {
                selectedItem.amount -= 1;
                equipment.setEquipment("Mainhand", selectedItem);
              } else {
                equipment.setEquipment("Mainhand", void 0);
              }
            }
            return;
          }
        }
        const currentState = block.permutation.getState("botany_nat:open");
        const newOpenState = !currentState;
        const sound = newOpenState ? "open.fence_gate" : "close.fence_gate";
        const rotationAngle = player.getRotation().y;
        const newCardinalDirection = getNewCardinalDirection(block.permutation.getState("minecraft:cardinal_direction"), rotationAngle);
        const newPermutation = BlockPermutation5.resolve(block.typeId, {
          ...block.permutation.getAllStates(),
          "botany_nat:open": newOpenState,
          "minecraft:cardinal_direction": newCardinalDirection
        });
        block.setPermutation(newPermutation);
        block.dimension.playSound(sound, block.location);
        const aboveBlock = block.above();
        if (aboveBlock && aboveBlock.permutation.getState("botany_nat:invisible")) {
          const aboveCurrentState = aboveBlock.permutation.getState("botany_nat:open");
          if (aboveCurrentState !== newOpenState) {
            const newAbovePermutation = BlockPermutation5.resolve(aboveBlock.typeId, {
              ...aboveBlock.permutation.getAllStates(),
              "botany_nat:open": newOpenState
            });
            aboveBlock.setPermutation(newAbovePermutation);
          }
        }
        if (aboveBlock && aboveBlock.typeId === "minecraft:air") {
          const currentStates = block.permutation.getAllStates();
          const cardinalDirection = currentStates["minecraft:cardinal_direction"];
          const newAboveStates = { ...currentStates };
          if (cardinalDirection === "south") {
            delete newAboveStates["minecraft:cardinal_direction"];
          }
          newAboveStates["botany_nat:invisible"] = true;
          const placeBlock = block.typeId;
          aboveBlock.setPermutation(BlockPermutation5.resolve(placeBlock, newAboveStates));
        }
      },
      onPlayerDestroy(event2) {
        const { block } = event2;
        const aboveBlock = block.above();
        if (aboveBlock && aboveBlock.permutation.getState("botany_nat:invisible")) {
          aboveBlock.setType("minecraft:air");
        }
      }
    }
  );
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:fence_gate_invisible",
    {
      onRandomTick(event2) {
        const { block } = event2;
        const belowBlock = block.below();
        if (!belowBlock || !belowBlock.permutation.hasTag("botany_nat:fence_gate")) {
          block.setType("minecraft:air");
        }
      }
    }
  );
});
function getNewCardinalDirection(currentDirection, angle) {
  if (["east", "west"].includes(currentDirection)) {
    if (angle > 0 && angle < 180) {
      return "west";
    } else {
      return "east";
    }
  }
  if (["north", "south"].includes(currentDirection)) {
    if (angle > -90 && angle < 90) {
      return "south";
    } else {
      return "north";
    }
  }
  return currentDirection;
}
world20.beforeEvents.explosion.subscribe((event) => {
  const fenceGateBlocks = event.getImpactedBlocks().filter((block) => block.permutation.hasTag("botany_nat:fence_gate"));
  for (const block of fenceGateBlocks) {
    const aboveBlock = block.above();
    if (aboveBlock?.permutation.getState("botany_nat:invisible")) {
      system12.runTimeout(() => {
        aboveBlock.setType("minecraft:air");
      }, 1);
    }
  }
});
world20.afterEvents.playerBreakBlock.subscribe((event) => {
  const block = event.block;
  const belowBlock = block.below();
  if (belowBlock && belowBlock.permutation.hasTag("botany_nat:fence_gate") && !belowBlock.permutation.getState("botany_nat:invisible")) {
    const currentStates = belowBlock.permutation.getAllStates();
    const cardinalDirection = currentStates["minecraft:cardinal_direction"];
    const newAboveStates = { ...currentStates };
    if (cardinalDirection === "south") {
      delete newAboveStates["minecraft:cardinal_direction"];
    }
    newAboveStates["botany_nat:invisible"] = true;
    const placeBlock = belowBlock.typeId;
    block.setPermutation(BlockPermutation5.resolve(placeBlock, newAboveStates));
  }
});
function customBlockPlaysound2(player, id, location) {
  if (id.endsWith("_log") || id.endsWith("_wood") || id.endsWith("_planks") || id.endsWith("_fence")) {
    player.playSound("dig.wood", { "location": location, "volume": 0.4, "pitch": 0.8 });
    return;
  }
  if (id === "minecraft:sand" || id.endsWith("_sand")) {
    player.playSound("dig.sand", { "location": location, "volume": 0.4, "pitch": 0.8 });
    return;
  }
  player.playSound("dig.stone", { "location": location, "volume": 0.4, "pitch": 0.8 });
}

// data/system_template_esbuild/subscripts/fence.ts
import { system as system13, world as world21, BlockPermutation as BlockPermutation6, ItemStack as ItemStack7, EntityComponentTypes as EntityComponentTypes2, EquipmentSlot as EquipmentSlot5 } from "@minecraft/server";
var wood_types5 = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var isFence = wood_types5.flatMap((wood) => [
  `botany_nat:${wood}_fence`
]);
var isFenceInventory = wood_types5.flatMap((wood) => [
  `botany_nat:${wood}_fence_inventory`
]);
world21.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:fence_inventory",
    {
      beforeOnPlayerPlace(event2) {
        event2.cancel = true;
        const { player, block } = event2;
        if (!player)
          return;
        const BlockToPlace = event2.permutationToPlace.type.id;
        const aboveBlock = block.above();
        const fenceBlockType = BlockToPlace.replace("_inventory", "");
        block.setType(fenceBlockType);
        update_connection(block);
        customBlockPlaysound3(player, fenceBlockType, block.location);
        if (aboveBlock && aboveBlock.typeId === "minecraft:air") {
          aboveBlock.setPermutation(
            BlockPermutation6.resolve(block.typeId + "_inventory", { "botany_nat:post": 1 })
          );
        }
        if (player.getGameMode() !== "creative") {
          const equipment = player.getComponent("equippable");
          const selectedItem = equipment?.getEquipment("Mainhand");
          if (selectedItem.amount > 1) {
            selectedItem.amount -= 1;
            equipment?.setEquipment("Mainhand", selectedItem);
          } else {
            equipment?.setEquipment("Mainhand", void 0);
          }
        }
      },
      onPlace(event2) {
        const { block } = event2;
        const aboveBlock = block.above();
        if (!aboveBlock)
          return;
        const fenceBlockType = block.typeId.replace("_inventory", "");
        event2.block.setType(fenceBlockType);
        if (aboveBlock.typeId === "minecraft:air") {
          aboveBlock.setPermutation(
            BlockPermutation6.resolve(block.typeId + "_inventory", { "botany_nat:post": 1 })
          );
        }
      }
    }
  );
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:fence_inventory_invisible",
    {
      onRandomTick(event2) {
        const { block } = event2;
        const belowBlock = block.below();
        if (!belowBlock || !belowBlock.permutation.hasTag("botany_nat:fence")) {
          block.setType("minecraft:air");
        }
      }
    }
  );
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:fence",
    {
      onPlace(event2) {
        const { block } = event2;
        update_connection(block);
        update_near_blocks(block);
      },
      onRandomTick(event2) {
        const { block } = event2;
        update_connection(block);
      },
      onPlayerDestroy(event2) {
        const { block } = event2;
        const aboveBlock = block.above();
        if (aboveBlock && aboveBlock.permutation.hasTag("botany_nat:fence_inventory")) {
          aboveBlock.setType("minecraft:air");
        }
      },
      onPlayerInteract(event2) {
        const { block, player, face } = event2;
        if (!player)
          return;
        const equipment = player.getComponent("equippable");
        const selectedItem = equipment?.getEquipment("Mainhand");
        const result = getBlockStatesAndDirection2(
          player,
          selectedItem,
          face
        );
        if (!result)
          return;
        const { stateName, stateValue } = result;
        let adjacentBlockPos;
        switch (face) {
          case "North":
            adjacentBlockPos = { x: block.x, y: block.y, z: block.z - 1 };
            break;
          case "South":
            adjacentBlockPos = { x: block.x, y: block.y, z: block.z + 1 };
            break;
          case "East":
            adjacentBlockPos = { x: block.x + 1, y: block.y, z: block.z };
            break;
          case "West":
            adjacentBlockPos = { x: block.x - 1, y: block.y, z: block.z };
            break;
          case "Up":
            adjacentBlockPos = { x: block.x, y: block.y + 1, z: block.z };
            break;
          case "Down":
            adjacentBlockPos = { x: block.x, y: block.y - 1, z: block.z };
            break;
        }
        const adjacentBlock = event2.dimension.getBlock(adjacentBlockPos);
        if (!adjacentBlock)
          return;
        if (face) {
          const aboveBlock = adjacentBlock.above();
          if (!aboveBlock)
            return;
          if (isFenceInventory.includes(selectedItem.typeId)) {
            if (adjacentBlock?.permutation?.hasTag("botany_nat:fence_inventory") || adjacentBlock.typeId === "minecraft:air") {
              const fenceBlockType = selectedItem.typeId.replace("_inventory", "");
              adjacentBlock.setType(fenceBlockType);
              update_near_blocks(adjacentBlock);
              customBlockPlaysound3(player, fenceBlockType, adjacentBlock.location);
              if (aboveBlock.typeId === "minecraft:air") {
                aboveBlock.setPermutation(
                  BlockPermutation6.resolve(selectedItem.typeId, {
                    "botany_nat:post": 1
                  })
                );
              }
              if (player.getGameMode() !== "creative") {
                if (selectedItem.amount > 1) {
                  selectedItem.amount -= 1;
                  equipment?.setEquipment("Mainhand", selectedItem);
                } else {
                  equipment?.setEquipment("Mainhand", void 0);
                }
              }
            }
          } else if (adjacentBlock.typeId === "minecraft:air" || adjacentBlock?.permutation?.hasTag("botany_nat:fence_inventory")) {
            const commandBlock = stateName ? `setblock ${adjacentBlockPos.x} ${adjacentBlockPos.y} ${adjacentBlockPos.z} ${selectedItem.typeId} ["${stateName}"="${stateValue}"]` : `setblock ${adjacentBlockPos.x} ${adjacentBlockPos.y} ${adjacentBlockPos.z} ${selectedItem.typeId}`;
            system13.runTimeout(() => {
              try {
                player.runCommand(commandBlock);
                update_near_blocks(adjacentBlock);
                customBlockPlaysound3(player, selectedItem.typeId, adjacentBlock.location);
                if (player.getGameMode() !== "creative") {
                  if (selectedItem.amount === 1) {
                    equipment?.setEquipment("Mainhand", void 0);
                  } else {
                    selectedItem.amount -= 1;
                    equipment?.setEquipment("Mainhand", selectedItem);
                  }
                }
              } catch (error) {
                console.warn(`Error: ${error.message}`);
              }
            }, 1);
          }
        }
      }
    }
  );
});
function getBlockStatesAndDirection2(player, selectedItem, face) {
  try {
    BlockPermutation6.resolve(selectedItem.typeId);
  } catch {
    return null;
  }
  const blockPermutation = BlockPermutation6.resolve(selectedItem.typeId);
  const blockStates = blockPermutation.getAllStates();
  let stateName;
  let stateValue;
  const statePriority = [
    "minecraft:vertical_half",
    "minecraft:block_face",
    "minecraft:cardinal_direction",
    "pillar_axis",
    "facing_direction"
  ];
  for (const state of statePriority) {
    if (blockStates[state] !== void 0) {
      stateName = state;
      if (state === "pillar_axis") {
        if (["North", "South"].includes(face)) {
          stateValue = "z";
        } else if (["East", "West"].includes(face)) {
          stateValue = "x";
        } else {
          stateValue = "y";
        }
      } else if (state === "minecraft:cardinal_direction") {
        const rotation = player.getRotation();
        const rad = rotation.y * Math.PI / 180;
        const directionX = -Math.sin(rad);
        const directionZ = Math.cos(rad);
        if (Math.abs(directionX) > Math.abs(directionZ)) {
          stateValue = directionX > 0 ? "east" : "west";
        } else {
          stateValue = directionZ > 0 ? "south" : "north";
        }
      } else if (state === "facing_direction") {
        const rotation = player.getRotation();
        const rad = rotation.y * Math.PI / 180;
        const directionX = -Math.sin(rad);
        const directionZ = Math.cos(rad);
        if (Math.abs(directionX) > Math.abs(directionZ)) {
          stateValue = directionX > 0 ? 2 : 3;
        } else {
          stateValue = directionZ > 0 ? 0 : 1;
        }
      } else if (state === "minecraft:block_face") {
        stateValue = face.toLowerCase();
      } else if (state === "minecraft:vertical_half") {
        const raycastOptions = {
          maxDistance: 5,
          // Adjust as needed
          includePassableBlocks: false
        };
        const raycastHit = player.getBlockFromViewDirection(raycastOptions);
        if (raycastHit) {
          const faceLocation = raycastHit.faceLocation;
          if (face === "Up" || face === "Down") {
            stateValue = face === "Up" ? "bottom" : "top";
          } else {
            stateValue = faceLocation.y > 0.5 ? "top" : "bottom";
          }
        } else {
          if (face === "Up") {
            stateValue = "bottom";
          } else if (face === "Down") {
            stateValue = "top";
          } else {
            stateValue = "bottom";
          }
        }
      } else {
        stateValue = blockStates[state];
      }
      break;
    }
  }
  return { stateName, stateValue };
}
world21.beforeEvents.explosion.subscribe((event) => {
  const fenceBlocks = event.getImpactedBlocks().filter((block) => block.permutation.hasTag("botany_nat:fence"));
  for (const block of fenceBlocks) {
    const aboveBlock = block.above();
    if (aboveBlock?.permutation.hasTag("botany_nat:fence_inventory")) {
      system13.runTimeout(() => {
        aboveBlock.setType("minecraft:air");
      }, 1);
    }
  }
});
world21.afterEvents.entitySpawn.subscribe((event) => {
  const entity = event.entity;
  if (!entity || entity.typeId !== "minecraft:item")
    return;
  const itemComponent = entity.getComponent(EntityComponentTypes2.Item);
  if (!itemComponent)
    return;
  const item = itemComponent.itemStack;
  if (!item || !isFence.includes(item.typeId))
    return;
  const newItem = new ItemStack7(item.typeId + "_inventory", item.amount);
  entity.dimension.spawnItem(newItem, entity.location);
  entity.remove();
});
system13.runInterval(() => {
  const players = world21.getPlayers();
  for (let player of players) {
    const equippable = player.getComponent("minecraft:equippable");
    const mainhand = equippable?.getEquipmentSlot(EquipmentSlot5.Mainhand);
    if (!mainhand)
      return;
    const selected_item = mainhand.getItem();
    if (selected_item && isFence.includes(selected_item.typeId)) {
      const amount = selected_item.amount;
      const fence_item = new ItemStack7(`${selected_item.typeId}_inventory`, amount);
      mainhand.setItem(fence_item);
    }
  }
}, 5);
world21.afterEvents.playerBreakBlock.subscribe((event) => {
  const { block } = event;
  const directions = [
    block.north(),
    block.south(),
    block.east(),
    block.west()
  ];
  for (let direction of directions) {
    if (direction && direction.permutation.hasTag("botany_nat:fence")) {
      update_connection(direction);
    }
  }
  const belowBlock = block.below();
  if (belowBlock && belowBlock.permutation.hasTag("botany_nat:fence")) {
    block.setPermutation(
      BlockPermutation6.resolve(belowBlock.typeId + "_inventory", { "botany_nat:post": 1 })
    );
  }
});
world21.afterEvents.playerPlaceBlock.subscribe((event) => {
  const block = event.block;
  const directions = [
    block.north(),
    block.south(),
    block.east(),
    block.west()
  ];
  for (let direction of directions) {
    if (direction && direction.permutation.hasTag("botany_nat:fence")) {
      update_connection(direction);
    }
  }
});
function update_near_blocks(block) {
  const directions = [
    block.north(),
    block.south(),
    block.east(),
    block.west()
  ];
  for (let direction of directions) {
    if (direction && direction.permutation.hasTag("botany_nat:fence")) {
      update_connection(direction);
    }
  }
}
function update_connection(block) {
  const directions = [
    { "name": "north", "block": block.north(), "collision_offset": { x: 0.5, y: 0.6, z: 0.9 } },
    { "name": "south", "block": block.south(), "collision_offset": { x: 0.5, y: 0.6, z: 0.1 } },
    { "name": "east", "block": block.east(), "collision_offset": { x: 0.1, y: 0.6, z: 0.5 } },
    { "name": "west", "block": block.west(), "collision_offset": { x: 0.9, y: 0.6, z: 0.5 } }
  ];
  for (let direction of directions) {
    let connect = false;
    if (direction.block && direction.block.typeId.endsWith("_fence")) {
      connect = true;
    }
    if (direction.block && direction.block.typeId.endsWith("_fence_gate") && direction.block.permutation.getState("botany_nat:open") === true) {
      connect = true;
    }
    if (direction.block && !direction.block.isAir && connect === false) {
      const block_location = direction.block.location;
      const collision_location = {
        x: block_location.x + direction.collision_offset.x,
        y: block_location.y + direction.collision_offset.y,
        z: block_location.z + direction.collision_offset.z
      };
      const ray_block = block.dimension.getBlockFromRay(collision_location, { x: 0, y: 1, z: 0 }, { "includePassableBlocks": false, "maxDistance": 1 });
      if (ray_block && ray_block.block.location.y === block_location.y)
        connect = true;
    }
    block.setPermutation(block.permutation.withState(`botany_nat:${direction.name}_picket`, connect ? 1 : 0));
    const aboveBlock = block.above();
    if (aboveBlock && aboveBlock.permutation.hasTag("botany_nat:fence_inventory")) {
      aboveBlock.setPermutation(aboveBlock.permutation.withState(`botany_nat:${direction.name}_picket`, connect ? 1 : 0));
    }
  }
}
function customBlockPlaysound3(player, id, location) {
  if (id.endsWith("_log") || id.endsWith("_wood") || id.endsWith("_planks") || id.endsWith("_fence")) {
    player.playSound("dig.wood", { "location": location, "volume": 0.4, "pitch": 0.8 });
    return;
  }
  if (id === "minecraft:sand" || id.endsWith("_sand")) {
    player.playSound("dig.sand", { "location": location, "volume": 0.4, "pitch": 0.8 });
    return;
  }
  player.playSound("dig.stone", { "location": location, "volume": 0.2, "pitch": 0.8 });
}

// data/system_template_esbuild/subscripts/door.ts
import { system as system14, world as world22, BlockPermutation as BlockPermutation7, ItemStack as ItemStack8, EquipmentSlot as EquipmentSlot6 } from "@minecraft/server";
var wood_types6 = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var door_blocks = wood_types6.map((wood) => `botany_nat:${wood}_door`);
world22.beforeEvents.worldInitialize.subscribe((eventData) => {
  eventData.blockComponentRegistry.registerCustomComponent("botany_nat:door", {
    onTick(event) {
      const block = event.block;
      if (!block || block.typeId === "minecraft:air") {
        return;
      }
      const topHalf = block.permutation.getState("botany_nat:upper_block_bit");
      if (topHalf)
        return;
      let doorPart;
      try {
        doorPart = block.above(1);
      } catch {
      }
      const blocksToUpdate = [block, doorPart];
      const powered = (block.getRedstonePower() || 0) > 0;
      if (block.permutation.getState("botany_nat:powered") === false) {
        if (powered) {
          block.setPermutation(block.permutation.withState("botany_nat:powered", true));
          if (block.permutation.getState("botany_nat:open_bit") === true)
            return;
          block.dimension.playSound("open.wooden_door", block.location, { pitch: 1, volume: 1 });
          for (const door of blocksToUpdate) {
            try {
              door.setPermutation(door.permutation.withState("botany_nat:open_bit", true));
            } catch {
            }
          }
        }
      } else {
        if (!powered) {
          block.setPermutation(block.permutation.withState("botany_nat:powered", false));
          block.dimension.playSound("close.wooden_door", block.location, { pitch: 1, volume: 1 });
          for (const door of blocksToUpdate) {
            try {
              door.setPermutation(door.permutation.withState("botany_nat:open_bit", false));
            } catch {
            }
          }
        }
      }
    },
    onPlayerInteract(event) {
      const { block, dimension } = event;
      const location = block.location;
      const topHalf = block.permutation.getState("botany_nat:upper_block_bit");
      const open = block.permutation.getState("botany_nat:open_bit");
      let doorPart;
      if (topHalf == false) {
        try {
          doorPart = block.above(1);
        } catch {
        }
      } else {
        try {
          doorPart = block.below(1);
        } catch {
        }
      }
      if (doorPart !== void 0) {
        let bool = !open;
        if (bool) {
          dimension.playSound("open.wooden_door", location, { pitch: 1, volume: 1 });
        } else {
          dimension.playSound("close.wooden_door", location, { pitch: 1, volume: 1 });
        }
        const blocksToUpdate = [block, doorPart];
        for (const door of blocksToUpdate) {
          try {
            door.setPermutation(door.permutation.withState("botany_nat:open_bit", bool));
          } catch {
          }
        }
      }
    },
    beforeOnPlayerPlace(event) {
      const { block, dimension } = event;
      const loc = block.location;
      if (loc.y + 1 >= dimension.heightRange.max) {
        event.cancel = true;
        return;
      }
      let blockAbove;
      let blockBelow;
      try {
        blockBelow = dimension.getBlock({
          x: loc.x,
          y: loc.y - 1,
          z: loc.z
        });
      } catch {
      }
      if (blockBelow == void 0) {
        event.cancel = true;
        return;
      }
      if (blockBelow.isAir || blockBelow.isLiquid) {
        event.cancel = true;
        return;
      }
      try {
        blockAbove = dimension.getBlock({
          x: loc.x,
          y: loc.y + 1,
          z: loc.z
        });
      } catch {
      }
      if (blockAbove == void 0) {
        event.cancel = true;
        return;
      }
      if (blockAbove.isAir || blockAbove.isLiquid) {
        system14.runTimeout(() => {
          placeDoor(block, blockAbove);
        }, 1);
      } else {
        event.cancel = true;
        return;
      }
    },
    onRandomTick(event) {
      const { block } = event;
      const aboveBlock = block.above();
      const belowBlock = block.below();
      if (!aboveBlock?.hasTag("botany_nat:door") && !belowBlock?.hasTag("botany_nat:door")) {
        block.setType("minecraft:air");
      }
    }
  });
});
function placeDoor(block, aboveBlock) {
  let reversed = false;
  let facing = block.permutation.getState("minecraft:cardinal_direction");
  if (!facing) {
    console.warn("Warning: Doors facing is missing.");
    facing = "north";
  }
  let adjacentDoor;
  let adjacentDirection;
  const checkAndUpdateAdjacentDoor = (direction) => {
    let otherBlock;
    switch (direction) {
      case "north":
        otherBlock = block.dimension.getBlock({ x: block.location.x, y: block.location.y, z: block.location.z - 1 });
        break;
      case "south":
        otherBlock = block.dimension.getBlock({ x: block.location.x, y: block.location.y, z: block.location.z + 1 });
        break;
      case "east":
        otherBlock = block.dimension.getBlock({ x: block.location.x + 1, y: block.location.y, z: block.location.z });
        break;
      case "west":
        otherBlock = block.dimension.getBlock({ x: block.location.x - 1, y: block.location.y, z: block.location.z });
        break;
    }
    if (otherBlock.hasTag("botany_nat:door")) {
      adjacentDoor = otherBlock;
      adjacentDirection = direction;
      reversed = shouldReverseDoor(facing, direction);
      return true;
    }
    return false;
  };
  const shouldReverseDoor = (facing2, adjacentDirection2) => {
    switch (facing2) {
      case "north":
        return adjacentDirection2 !== "east";
      case "south":
        return adjacentDirection2 !== "west";
      case "east":
        return adjacentDirection2 !== "south";
      case "west":
        return adjacentDirection2 !== "north";
      default:
        return true;
    }
  };
  ["north", "south", "east", "west"].forEach((direction) => {
    try {
      if (checkAndUpdateAdjacentDoor(direction)) {
      }
    } catch (error) {
      console.warn(`Error checking ${direction} direction: ${error}`);
    }
  });
  block.setPermutation(block.permutation.withState("botany_nat:reversed", reversed));
  aboveBlock.setPermutation(BlockPermutation7.resolve(block.typeId));
  aboveBlock.setPermutation(aboveBlock.permutation.withState("botany_nat:upper_block_bit", true));
  aboveBlock.setPermutation(aboveBlock.permutation.withState("minecraft:cardinal_direction", facing).withState("botany_nat:reversed", reversed));
  if (adjacentDoor) {
    const adjacentAboveBlock = block.dimension.getBlock({
      x: adjacentDoor.location.x,
      y: adjacentDoor.location.y + 1,
      z: adjacentDoor.location.z
    });
    const adjacentReversed = !reversed;
    adjacentDoor.setPermutation(adjacentDoor.permutation.withState("botany_nat:reversed", adjacentReversed));
    if (adjacentAboveBlock) {
      adjacentAboveBlock.setPermutation(adjacentAboveBlock.permutation.withState("botany_nat:reversed", adjacentReversed));
    }
  }
}
var doorBreakTimestamps = /* @__PURE__ */ new Map();
var minUseDelay2 = 2;
world22.beforeEvents.playerBreakBlock.subscribe((data) => {
  const block = data.block;
  const aboveBlock = block.above();
  const belowBlock = block.below();
  if (data.block.hasTag("botany_nat:door") || aboveBlock && aboveBlock.hasTag("botany_nat:door")) {
    const playerId = data.player.id;
    const lastUseTimestamp = doorBreakTimestamps.get(playerId) ?? 0;
    const currentTime = system14.currentTick;
    if (currentTime - lastUseTimestamp < minUseDelay2 && data.player.getGameMode() === "creative") {
      return;
    }
    doorBreakTimestamps.set(playerId, currentTime);
  } else {
    return;
  }
  if (block.hasTag("botany_nat:door")) {
    data.cancel = true;
    let drop_item = false;
    if (aboveBlock?.hasTag("botany_nat:door") || belowBlock?.hasTag("botany_nat:door")) {
      drop_item = true;
    }
    if (data.player.getGameMode() === "creative")
      drop_item = false;
    breakDoor(block.typeId, block, block.permutation.getState("botany_nat:upper_block_bit"), drop_item);
  }
});
function breakDoor(blockId, block, topHalf, drop_item) {
  system14.runTimeout(() => {
    let doorPart;
    if (topHalf == false) {
      try {
        doorPart = block.above(1);
      } catch {
      }
    } else
      try {
        doorPart = block.below(1);
      } catch {
      }
    if (doorPart !== void 0 && doorPart.hasTag("botany_nat:door"))
      doorPart.setPermutation(BlockPermutation7.resolve("minecraft:air"));
    if (drop_item) {
      const item = new ItemStack8(blockId + "_item", 1);
      block.dimension.spawnItem(item, block.location);
    }
    block.dimension.playSound("dig.wood", block.location);
    block.setPermutation(BlockPermutation7.resolve("minecraft:air"));
  }, 1);
}
world22.beforeEvents.explosion.subscribe((event) => {
  const doorBlocks = event.getImpactedBlocks().filter((block) => block.permutation.hasTag("botany_nat:door"));
  for (const block of doorBlocks) {
    const aboveBlock = block.above();
    if (aboveBlock?.permutation.hasTag("botany_nat:door")) {
      system14.runTimeout(() => {
        breakDoor(aboveBlock.typeId, aboveBlock, aboveBlock.permutation.getState("botany_nat:upper_block_bit"), true);
      }, 1);
    }
  }
});
system14.runInterval(() => {
  const players = world22.getPlayers();
  for (let player of players) {
    const equippable = player.getComponent("minecraft:equippable");
    const mainhand = equippable?.getEquipmentSlot(EquipmentSlot6.Mainhand);
    if (!mainhand)
      return;
    const selected_item = mainhand.getItem();
    if (selected_item && door_blocks.includes(selected_item.typeId)) {
      const amount = selected_item.amount;
      const door_item = new ItemStack8(`${selected_item.typeId}_item`, amount);
      mainhand.setItem(door_item);
    }
  }
}, 5);

// data/system_template_esbuild/subscripts/boat.ts
import { world as world23 } from "@minecraft/server";
var wood_types7 = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
var CHEST_BOATS = wood_types7.map((wood) => `botany_nat:${wood}_chest_boat`);
world23.afterEvents.entitySpawn.subscribe((event) => {
  const entity = event.entity;
  if (CHEST_BOATS.includes(entity.typeId)) {
    const name = BeforeEachChar2(entity.typeId, "\xA7");
    entity.nameTag = name + "\xA7r";
  }
});
function BeforeEachChar2(str, A) {
  return str.split("").map((char) => A + char).join("");
}

// data/system_template_esbuild/subscripts/debug.ts
import { system as system15 } from "@minecraft/server";
var wood_types8 = ["mango", "orange", "peach", "cherry", "coconut", "ash", "baobab", "chestnut", "jacaranda", "maple", "redwood", "willow"];
system15.afterEvents.scriptEventReceive.subscribe((event) => {
  const id = event.id;
  const player = event.sourceEntity;
  if (!player || player.typeId !== "minecraft:player")
    return;
  if (id === "botany_nat:tree_debug") {
    debug(player);
  }
});
function debug(player) {
  let location = player.location;
  for (let wood of wood_types8) {
    player.runCommand(`/setblock ${location.x} ${location.y} ${location.z} botany_nat:${wood}_sapling`);
    player.runCommand(`/fill ${location.x} ${location.y - 1} ${location.z} ${location.x + 2} ${location.y - 1} ${location.z + 5} minecraft:grass_block`);
    player.runCommand(`/setblock ${location.x} ${location.y} ${location.z + 1} botany_nat:${wood}_log`);
    player.runCommand(`/setblock ${location.x} ${location.y} ${location.z + 2} botany_nat:${wood}_wood`);
    player.runCommand(`/setblock ${location.x} ${location.y} ${location.z + 3} botany_nat:stripped_${wood}_log`);
    player.runCommand(`/setblock ${location.x} ${location.y} ${location.z + 4} botany_nat:stripped_${wood}_wood`);
    player.runCommand(`/setblock ${location.x} ${location.y} ${location.z + 5} botany_nat:${wood}_leaves`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y} ${location.z} botany_nat:${wood}_trapdoor`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y} ${location.z + 1} botany_nat:${wood}_slab`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y} ${location.z + 2} botany_nat:${wood}_planks`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y} ${location.z + 3} botany_nat:${wood}_fence_gate["minecraft:cardinal_direction"="east"]`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y} ${location.z + 4} botany_nat:${wood}_fence`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y} ${location.z + 5} botany_nat:${wood}_planks`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y + 1} ${location.z + 5} botany_nat:${wood}_door`);
    player.runCommand(`/setblock ${location.x + 1} ${location.y + 2} ${location.z + 5} botany_nat:${wood}_door["botany_nat:upper_block_bit"=true]`);
    location = {
      x: location.x + 3,
      y: location.y,
      z: location.z
    };
  }
}

// data/system_template_esbuild/subscripts/fruits.ts
import { ItemEnchantableComponent as ItemEnchantableComponent2, system as system16, world as world25, BlockPermutation as BlockPermutation8, GameMode as GameMode5 } from "@minecraft/server";
world25.beforeEvents.worldInitialize.subscribe((event) => {
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:fruit.random_rotation",
    {
      onPlace: (event2) => {
        if (!event2.block.hasTag("botany_nat:fruit"))
          return;
        const randomRotation = Math.floor(Math.random() * 4);
        const setState = event2.block.permutation.withState("botany_nat:random_rotation", randomRotation);
        event2.block.setPermutation(setState);
      }
    }
  );
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:cherry_block_0",
    {
      onRandomTick(data) {
        const { block } = data;
        const random = randomNumber2(0, 5);
        if (random > 1)
          return;
        block.setPermutation(BlockPermutation8.resolve("botany_nat:cherry_block_1"));
      },
      onPlayerInteract(data) {
        const { block, player } = data;
        if (!player)
          return;
        const equipment = player.getComponent("equippable");
        const item = equipment?.getEquipment("Mainhand");
        if (item?.typeId != "minecraft:bone_meal")
          return;
        const center = block.center();
        block.dimension.playSound("item.bone_meal.use", center);
        block.dimension.spawnParticle("minecraft:crop_growth_emitter", center);
        if (player.getGameMode() != GameMode5.creative) {
          equipment?.setEquipment("Mainhand", decreaseStack2(item));
        }
        const random = randomNumber2(0, 5);
        if (random > 1)
          return;
        block.setPermutation(BlockPermutation8.resolve("botany_nat:cherry_block_1"));
      }
    }
  );
  event.blockComponentRegistry.registerCustomComponent(
    "botany_nat:cherry_block_1",
    {
      onPlayerDestroy(data) {
        const { block } = data;
        block.setPermutation(BlockPermutation8.resolve("botany_nat:cherry_block_0"));
      }
    }
  );
});
function decreaseStack2(item) {
  if (item.amount > 1) {
    item.amount = item.amount - 1;
    return item;
  } else {
    return void 0;
  }
}
function randomNumber2(min, max) {
  return Math.random() * (max - min) + min;
}
world25.beforeEvents.playerBreakBlock.subscribe((data) => {
  const { block, itemStack, dimension } = data;
  if (!block.hasTag("botany_nat:fruits.disable_silk_touch"))
    return;
  if (!itemStack)
    return;
  const EnchancComponent = itemStack.getComponent(ItemEnchantableComponent2.componentId);
  if (!EnchancComponent)
    return;
  if (!EnchancComponent.hasEnchantment("silk_touch"))
    return;
  data.cancel = true;
  system16.runTimeout(() => {
    destroyBlock(dimension, block.location);
  });
});
function destroyBlock(dimension, location) {
  const { x, y, z } = location;
  dimension.runCommand(`setblock ${x} ${y} ${z} air destroy`);
}
