import { world, system } from "@minecraft/server";
export default function growTreeLarge(location, fruit, playerplaced, dimension) {
  var treernd,
    randomRotation,
    fruitParts,
    fruitName = undefined;
  try {
    if (location != undefined) {
      const overworld = world.getDimension("overworld");
      dimension.runCommand(`setblock ${location.x} ${location.y} ${location.z} air replace`);
      const randomIndex = Math.floor(Math.random() * 4.0);
      randomRotation = ["0_degrees", "180_degrees", "270_degrees", "90_degrees"][randomIndex];
      treernd = playerplaced ? Math.floor(Math.random() * 2.0) + 1 : Math.floor(Math.random() * 4.0) + 1;
      const leaf = fruit.replace("sapling", "leaf");
      fruitParts = fruit.split(":");
      fruitName = fruitParts.length > 1 ? fruitParts[1].split("_")[0] : fruitParts[0];
      dimension.runCommand(
        `structure load "float_fc/${fruitName}_tree_23x23_${treernd}" ${location.x - 11} ${location.y - 3} ${
          location.z - 11
        } ${randomRotation} none layer_by_layer 3`
      );
      if (fruitName == "rainbow") {
        return `event entity @e[type=${leaf},x=${location.x - 11},y=${location.y},z=${
          location.z - 11
        },r=40] float_fc:fully_grown`;
      }
    }
  } catch (e) {}
  treernd = randomRotation = fruitParts = fruitName = undefined;
  return null;
}
