import { world, system } from "@minecraft/server";
export default function growTreePine(location, fruit, playerplaced, dimension) {
  const overworld = world.getDimension("overworld");
  const rotations = ["0_degrees", "180_degrees", "270_degrees", "90_degrees"];
  const offsets = [0, 0, 1, 2];
  var treernd, randomIndex, fruitParts, fruitName;
  try {
    if (location != undefined) {
      dimension.runCommand(`setblock ${location.x} ${location.y} ${location.z} air replace`);
      randomIndex = Math.floor(Math.random() * 4.0);
      if (playerplaced) {
        treernd = Math.floor(Math.random() * 12.0);
      } else {
        treernd = Math.floor(Math.random() * 12.0);
      }
      fruitParts = fruit.split(":");
      fruitName = fruitParts.length > 1 ? fruitParts[1].split("_")[0] : fruitParts[0];
      if (treernd == 0) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_13x13_1" ${location.x - 7} ${location.y - 1} ${location.z - 7} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 1) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_13x13_2" ${location.x - 7} ${location.y - 1} ${location.z - 7} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 2) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_15x15_3" ${location.x - 8} ${location.y - 1} ${location.z - 8} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 3) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_15x15_4" ${location.x - 8} ${location.y - 1} ${location.z - 8} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 4) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_5x5_5" ${location.x - 3} ${location.y - 1} ${location.z - 3} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 5) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_5x5_6" ${location.x - 3} ${location.y - 1} ${location.z - 3} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 6) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_7x7_7" ${location.x - 4} ${location.y - 1} ${location.z - 4} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 7) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_9x9_8" ${location.x - 5} ${location.y - 1} ${location.z - 5} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 8) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_9x9_9" ${location.x - 5} ${location.y - 1} ${location.z - 5} ${
            rotations[randomIndex]
          } none layer_by_layer 3`
        );
      } else if (treernd == 9) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_21x21_10" ${location.x - 11} ${location.y - 1} ${
            location.z - 11
          } ${rotations[randomIndex]} none layer_by_layer 3`
        );
      } else if (treernd == 10) {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_21x21_11" ${location.x - 11} ${location.y - 1} ${
            location.z - 11
          } ${rotations[randomIndex]} none layer_by_layer 3`
        );
      } else {
        dimension.runCommand(
          `structure load "float_fc/${fruitName}_tree_21x21_12" ${location.x - 11} ${location.y - 1} ${
            location.z - 11
          } ${rotations[randomIndex]} none layer_by_layer 3`
        );
      }
    }
  } catch (e) {}
  treernd = randomIndex = fruitParts = fruitName = undefined;
  return null;
}
