import { world, system } from "@minecraft/server";
export default function growTreePinkOleander(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;
  console.error("Pink Oleander Tree Spawned");
  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() * 4.0);
    } else {
      treernd = Math.floor(Math.random() * 4.0);
    }
    fruitParts = fruit.split(":")[1].split("_");
    fruitName = `${fruitParts[0]}_${fruitParts[1]}`;
    console.error(fruitName);
    if (treernd == 0) {
      dimension.runCommand(
        `structure load "float_fc/${fruitName}_tree_9x9_1" ${location.x - 4} ${location.y - 1} ${location.z - 4} ${
          rotations[randomIndex]
        } none layer_by_layer 3`
      );
    } else if (treernd == 1) {
      dimension.runCommand(
        `structure load "float_fc/${fruitName}_tree_11x11_2" ${location.x - 5} ${location.y - 1} ${location.z - 5} ${
          rotations[randomIndex]
        } none layer_by_layer 3`
      );
    } else if (treernd == 2) {
      dimension.runCommand(
        `structure load "float_fc/${fruitName}_tree_13x13_3" ${location.x - 6} ${location.y - 1} ${location.z - 6} ${
          rotations[randomIndex]
        } none layer_by_layer 3`
      );
    } else {
      dimension.runCommand(
        `structure load "float_fc/${fruitName}_tree_13x13_4" ${location.x - 6} ${location.y - 1} ${location.z - 6} ${
          rotations[randomIndex]
        } none layer_by_layer 3`
      );
    }
  }
  treernd = randomIndex = fruitParts = fruitName = undefined;
  return null;
}
