private void Generate_Tree(Block start) { BlockGroup tree = new BlockGroup("Tree", BlockGroup.GroupType.Tree); tree.Add(start); int max_height = Size_Y - start.Coordinates.Y; if (max_height <= 1) { return; } int height = max_height; if (max_height > 2) { height = Mathf.RoundToInt(2 + (max_height - 2) * RNG.Instance.Next_F()); } if (height == 2) { Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start][start.Coordinates.Y + 1].Change_To(BlockPrototypes.Instance.Get("leaves")); return; } for (int h = start.Coordinates.Y + 1; h < start.Coordinates.Y + height; h++) { if (h < start.Coordinates.Y + height - 1) { Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start][h].Change_To(BlockPrototypes.Instance.Get("trunk")); } else { Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start][h].Change_To(BlockPrototypes.Instance.Get("leaves")); } tree.Add(Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start][h]); } int top = start.Coordinates.Y + height - 1; if (start.Coordinates.X - X_Start - 1 >= 0 && Temp_Data.All_Blocks[start.Coordinates.X - X_Start - 1][start.Coordinates.Z - Z_Start][top].Is_Air) { Temp_Data.All_Blocks[start.Coordinates.X - X_Start - 1][start.Coordinates.Z - Z_Start][top].Change_To(BlockPrototypes.Instance.Get("leaves")); tree.Add(Temp_Data.All_Blocks[start.Coordinates.X - X_Start - 1][start.Coordinates.Z - Z_Start][top]); } if (start.Coordinates.Z - Z_Start - 1 >= 0 && Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start - 1][top].Is_Air) { Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start - 1][top].Change_To(BlockPrototypes.Instance.Get("leaves")); tree.Add(Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start - 1][top]); } if (start.Coordinates.X - X_Start + 1 < SIZE_X && Temp_Data.All_Blocks[start.Coordinates.X - X_Start + 1][start.Coordinates.Z - Z_Start][top].Is_Air) { Temp_Data.All_Blocks[start.Coordinates.X - X_Start + 1][start.Coordinates.Z - Z_Start][top].Change_To(BlockPrototypes.Instance.Get("leaves")); tree.Add(Temp_Data.All_Blocks[start.Coordinates.X - X_Start + 1][start.Coordinates.Z - Z_Start][top]); } if (start.Coordinates.Z - Z_Start + 1 < SIZE_Z && Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start + 1][top].Is_Air) { Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start + 1][top].Change_To(BlockPrototypes.Instance.Get("leaves")); tree.Add(Temp_Data.All_Blocks[start.Coordinates.X - X_Start][start.Coordinates.Z - Z_Start + 1][top]); } //TODO: grass end up in here? Because index errors? tree.Blocks = tree.Blocks.Where(x => x.Internal_Name == "trunk" || x.Internal_Name == "leaves").ToList(); Block_Groups.Add(tree); }