3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>,
4 2012-2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "util/pointer.h"
23 #include "util/numeric.h"
25 #include "serverenvironment.h"
28 #include "voxelalgorithms.h"
33 void make_tree(MMVManip &vmanip, v3s16 p0,
34 bool is_apple_tree, INodeDefManager *ndef, s32 seed)
37 NOTE: Tree-placing code is currently duplicated in the engine
38 and in games that have saplings; both are deprecated but not
41 MapNode treenode(ndef->getId("mapgen_tree"));
42 MapNode leavesnode(ndef->getId("mapgen_leaves"));
43 MapNode applenode(ndef->getId("mapgen_apple"));
45 PseudoRandom pr(seed);
46 s16 trunk_h = pr.range(4, 5);
48 for (s16 ii = 0; ii < trunk_h; ii++) {
49 if (vmanip.m_area.contains(p1)) {
50 u32 vi = vmanip.m_area.index(p1);
51 vmanip.m_data[vi] = treenode;
56 // p1 is now the last piece of the trunk
59 VoxelArea leaves_a(v3s16(-2, -1, -2), v3s16(2, 2, 2));
60 Buffer<u8> leaves_d(leaves_a.getVolume());
61 for (s32 i = 0; i < leaves_a.getVolume(); i++)
64 // Force leaves at near the end of the trunk
66 for (s16 z = -d; z <= d; z++)
67 for (s16 y = -d; y <= d; y++)
68 for (s16 x = -d; x <= d; x++) {
69 leaves_d[leaves_a.index(v3s16(x, y, z))] = 1;
72 // Add leaves randomly
73 for (u32 iii = 0; iii < 7; iii++) {
75 pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X - d),
76 pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y - d),
77 pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z - d)
80 for (s16 z = 0; z <= d; z++)
81 for (s16 y = 0; y <= d; y++)
82 for (s16 x = 0; x <= d; x++) {
83 leaves_d[leaves_a.index(p + v3s16(x, y, z))] = 1;
87 // Blit leaves to vmanip
88 for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++)
89 for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) {
90 v3s16 pmin(leaves_a.MinEdge.X, y, z);
91 u32 i = leaves_a.index(pmin);
92 u32 vi = vmanip.m_area.index(pmin + p1);
93 for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) {
95 if (vmanip.m_area.contains(p + p1) == true &&
96 (vmanip.m_data[vi].getContent() == CONTENT_AIR ||
97 vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) {
98 if (leaves_d[i] == 1) {
99 bool is_apple = pr.range(0, 99) < 10;
100 if (is_apple_tree && is_apple)
101 vmanip.m_data[vi] = applenode;
103 vmanip.m_data[vi] = leavesnode;
113 // L-System tree LUA spawner
114 treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
115 INodeDefManager *ndef, const TreeDef &tree_definition)
117 ServerMap *map = &env->getServerMap();
118 std::map<v3s16, MapBlock*> modified_blocks;
119 MMVManip vmanip(map);
120 v3s16 tree_blockp = getNodeBlockPos(p0);
123 vmanip.initialEmerge(tree_blockp - v3s16(1, 1, 1), tree_blockp + v3s16(1, 3, 1));
124 e = make_ltree(vmanip, p0, ndef, tree_definition);
128 voxalgo::blit_back_with_light(map, &vmanip, &modified_blocks);
130 // Send a MEET_OTHER event
132 event.type = MEET_OTHER;
133 for (std::map<v3s16, MapBlock*>::iterator
134 i = modified_blocks.begin();
135 i != modified_blocks.end(); ++i)
136 event.modified_blocks.insert(i->first);
137 map->dispatchEvent(&event);
142 //L-System tree generator
143 treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
144 INodeDefManager *ndef, TreeDef tree_definition)
146 MapNode dirtnode(ndef->getId("mapgen_dirt"));
148 if (tree_definition.explicit_seed)
149 seed = tree_definition.seed + 14002;
151 seed = p0.X * 2 + p0.Y * 4 + p0.Z; // use the tree position to seed PRNG
152 PseudoRandom ps(seed);
154 // chance of inserting abcd rules
160 //randomize tree growth level, minimum=2
161 s16 iterations = tree_definition.iterations;
162 if (tree_definition.iterations_random_level > 0)
163 iterations -= ps.range(0, tree_definition.iterations_random_level);
167 s16 MAX_ANGLE_OFFSET = 5;
168 double angle_in_radians = (double)tree_definition.angle * M_PI / 180;
169 double angleOffset_in_radians = (s16)(ps.range(0, 1) % MAX_ANGLE_OFFSET) * M_PI / 180;
171 //initialize rotation matrix, position and stacks for branches
172 core::matrix4 rotation;
173 rotation = setRotationAxisRadians(rotation, M_PI / 2, v3f(0, 0, 1));
178 std::stack <core::matrix4> stack_orientation;
179 std::stack <v3f> stack_position;
182 std::string axiom = tree_definition.initial_axiom;
183 for (s16 i = 0; i < iterations; i++) {
184 std::string temp = "";
185 for (s16 j = 0; j < (s16)axiom.size(); j++) {
186 char axiom_char = axiom.at(j);
187 switch (axiom_char) {
189 temp += tree_definition.rules_a;
192 temp += tree_definition.rules_b;
195 temp += tree_definition.rules_c;
198 temp += tree_definition.rules_d;
201 if (prop_a >= ps.range(1, 10))
202 temp += tree_definition.rules_a;
205 if (prop_b >= ps.range(1, 10))
206 temp += tree_definition.rules_b;
209 if (prop_c >= ps.range(1, 10))
210 temp += tree_definition.rules_c;
213 if (prop_d >= ps.range(1, 10))
214 temp += tree_definition.rules_d;
224 //make sure tree is not floating in the air
225 if (tree_definition.trunk_type == "double") {
228 v3f(position.X + 1, position.Y - 1, position.Z),
233 v3f(position.X, position.Y - 1, position.Z + 1),
238 v3f(position.X + 1, position.Y - 1, position.Z + 1),
241 } else if (tree_definition.trunk_type == "crossed") {
244 v3f(position.X + 1, position.Y - 1, position.Z),
249 v3f(position.X - 1, position.Y - 1, position.Z),
254 v3f(position.X, position.Y - 1, position.Z + 1),
259 v3f(position.X, position.Y - 1, position.Z - 1),
264 /* build tree out of generated axiom
266 Key for Special L-System Symbols used in Axioms
268 G - move forward one unit with the pen up
269 F - move forward one unit with the pen down drawing trunks and branches
270 f - move forward one unit with the pen down drawing leaves (100% chance)
271 T - move forward one unit with the pen down drawing trunks only
272 R - move forward one unit with the pen down placing fruit
273 A - replace with rules set A
274 B - replace with rules set B
275 C - replace with rules set C
276 D - replace with rules set D
277 a - replace with rules set A, chance 90%
278 b - replace with rules set B, chance 80%
279 c - replace with rules set C, chance 70%
280 d - replace with rules set D, chance 60%
281 + - yaw the turtle right by angle degrees
282 - - yaw the turtle left by angle degrees
283 & - pitch the turtle down by angle degrees
284 ^ - pitch the turtle up by angle degrees
285 / - roll the turtle to the right by angle degrees
286 * - roll the turtle to the left by angle degrees
287 [ - save in stack current state info
288 ] - recover from stack state info
293 for (s16 i = 0; i < (s16)axiom.size(); i++) {
294 char axiom_char = axiom.at(i);
295 core::matrix4 temp_rotation;
296 temp_rotation.makeIdentity();
298 switch (axiom_char) {
301 dir = transposeMatrix(rotation, dir);
305 tree_trunk_placement(
307 v3f(position.X, position.Y, position.Z),
310 if (tree_definition.trunk_type == "double" &&
311 !tree_definition.thin_branches) {
312 tree_trunk_placement(
314 v3f(position.X + 1, position.Y, position.Z),
317 tree_trunk_placement(
319 v3f(position.X, position.Y, position.Z + 1),
322 tree_trunk_placement(
324 v3f(position.X + 1, position.Y, position.Z + 1),
327 } else if (tree_definition.trunk_type == "crossed" &&
328 !tree_definition.thin_branches) {
329 tree_trunk_placement(
331 v3f(position.X + 1, position.Y, position.Z),
334 tree_trunk_placement(
336 v3f(position.X - 1, position.Y, position.Z),
339 tree_trunk_placement(
341 v3f(position.X, position.Y, position.Z + 1),
344 tree_trunk_placement(
346 v3f(position.X, position.Y, position.Z - 1),
351 dir = transposeMatrix(rotation, dir);
355 tree_trunk_placement(
357 v3f(position.X, position.Y, position.Z),
360 if ((stack_orientation.empty() &&
361 tree_definition.trunk_type == "double") ||
362 (!stack_orientation.empty() &&
363 tree_definition.trunk_type == "double" &&
364 !tree_definition.thin_branches)) {
365 tree_trunk_placement(
367 v3f(position.X +1 , position.Y, position.Z),
370 tree_trunk_placement(
372 v3f(position.X, position.Y, position.Z + 1),
375 tree_trunk_placement(
377 v3f(position.X + 1, position.Y, position.Z + 1),
380 } else if ((stack_orientation.empty() &&
381 tree_definition.trunk_type == "crossed") ||
382 (!stack_orientation.empty() &&
383 tree_definition.trunk_type == "crossed" &&
384 !tree_definition.thin_branches)) {
385 tree_trunk_placement(
387 v3f(position.X + 1, position.Y, position.Z),
390 tree_trunk_placement(
392 v3f(position.X - 1, position.Y, position.Z),
395 tree_trunk_placement(
397 v3f(position.X, position.Y, position.Z + 1),
400 tree_trunk_placement(
402 v3f(position.X, position.Y, position.Z - 1),
405 } if (stack_orientation.empty() == false) {
407 for (x = -size; x <= size; x++)
408 for (y = -size; y <= size; y++)
409 for (z = -size; z <= size; z++) {
410 if (abs(x) == size &&
413 tree_leaves_placement(
415 v3f(position.X + x + 1, position.Y + y,
420 tree_leaves_placement(
422 v3f(position.X + x - 1, position.Y + y,
427 tree_leaves_placement(
428 vmanip,v3f(position.X + x, position.Y + y,
433 tree_leaves_placement(
434 vmanip,v3f(position.X + x, position.Y + y,
443 dir = transposeMatrix(rotation, dir);
447 tree_single_leaves_placement(
449 v3f(position.X, position.Y, position.Z),
454 dir = transposeMatrix(rotation, dir);
458 tree_fruit_placement(
460 v3f(position.X, position.Y, position.Z),
464 dir = transposeMatrix(rotation, dir);
468 // turtle orientation commands
470 stack_orientation.push(rotation);
471 stack_position.push(position);
474 if (stack_orientation.empty())
475 return UNBALANCED_BRACKETS;
476 rotation = stack_orientation.top();
477 stack_orientation.pop();
478 position = stack_position.top();
479 stack_position.pop();
482 temp_rotation.makeIdentity();
483 temp_rotation = setRotationAxisRadians(temp_rotation,
484 angle_in_radians + angleOffset_in_radians, v3f(0, 0, 1));
485 rotation *= temp_rotation;
488 temp_rotation.makeIdentity();
489 temp_rotation = setRotationAxisRadians(temp_rotation,
490 angle_in_radians + angleOffset_in_radians, v3f(0, 0, -1));
491 rotation *= temp_rotation;
494 temp_rotation.makeIdentity();
495 temp_rotation = setRotationAxisRadians(temp_rotation,
496 angle_in_radians + angleOffset_in_radians, v3f(0, 1, 0));
497 rotation *= temp_rotation;
500 temp_rotation.makeIdentity();
501 temp_rotation = setRotationAxisRadians(temp_rotation,
502 angle_in_radians + angleOffset_in_radians, v3f(0, -1, 0));
503 rotation *= temp_rotation;
506 temp_rotation.makeIdentity();
507 temp_rotation = setRotationAxisRadians(temp_rotation,
508 angle_in_radians, v3f(1, 0, 0));
509 rotation *= temp_rotation;
512 temp_rotation.makeIdentity();
513 temp_rotation = setRotationAxisRadians(temp_rotation,
514 angle_in_radians, v3f(-1, 0, 0));
515 rotation *= temp_rotation;
526 void tree_node_placement(MMVManip &vmanip, v3f p0, MapNode node)
528 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
529 if (vmanip.m_area.contains(p1) == false)
531 u32 vi = vmanip.m_area.index(p1);
532 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
533 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
535 vmanip.m_data[vmanip.m_area.index(p1)] = node;
539 void tree_trunk_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition)
541 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
542 if (vmanip.m_area.contains(p1) == false)
544 u32 vi = vmanip.m_area.index(p1);
545 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
546 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
548 vmanip.m_data[vmanip.m_area.index(p1)] = tree_definition.trunknode;
552 void tree_leaves_placement(MMVManip &vmanip, v3f p0,
553 PseudoRandom ps, TreeDef &tree_definition)
555 MapNode leavesnode = tree_definition.leavesnode;
556 if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance)
557 leavesnode = tree_definition.leaves2node;
558 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
559 if (vmanip.m_area.contains(p1) == false)
561 u32 vi = vmanip.m_area.index(p1);
562 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
563 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
565 if (tree_definition.fruit_chance > 0) {
566 if (ps.range(1, 100) > 100 - tree_definition.fruit_chance)
567 vmanip.m_data[vmanip.m_area.index(p1)] = tree_definition.fruitnode;
569 vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode;
570 } else if (ps.range(1, 100) > 20) {
571 vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode;
576 void tree_single_leaves_placement(MMVManip &vmanip, v3f p0,
577 PseudoRandom ps, TreeDef &tree_definition)
579 MapNode leavesnode = tree_definition.leavesnode;
580 if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance)
581 leavesnode = tree_definition.leaves2node;
582 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
583 if (vmanip.m_area.contains(p1) == false)
585 u32 vi = vmanip.m_area.index(p1);
586 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
587 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
589 vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode;
593 void tree_fruit_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition)
595 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
596 if (vmanip.m_area.contains(p1) == false)
598 u32 vi = vmanip.m_area.index(p1);
599 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
600 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
602 vmanip.m_data[vmanip.m_area.index(p1)] = tree_definition.fruitnode;
606 irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis)
608 double c = cos(angle);
609 double s = sin(angle);
612 double tx = t * axis.X;
613 double ty = t * axis.Y;
614 double tz = t * axis.Z;
615 double sx = s * axis.X;
616 double sy = s * axis.Y;
617 double sz = s * axis.Z;
619 M[0] = tx * axis.X + c;
620 M[1] = tx * axis.Y + sz;
621 M[2] = tx * axis.Z - sy;
623 M[4] = ty * axis.X - sz;
624 M[5] = ty * axis.Y + c;
625 M[6] = ty * axis.Z + sx;
627 M[8] = tz * axis.X + sy;
628 M[9] = tz * axis.Y - sx;
629 M[10] = tz * axis.Z + c;
634 v3f transposeMatrix(irr::core::matrix4 M, v3f v)
637 double x = M[0] * v.X + M[4] * v.Y + M[8] * v.Z +M[12];
638 double y = M[1] * v.X + M[5] * v.Y + M[9] * v.Z +M[13];
639 double z = M[2] * v.X + M[6] * v.Y + M[10] * v.Z +M[14];
647 void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
650 NOTE: Tree-placing code is currently duplicated in the engine
651 and in games that have saplings; both are deprecated but not
654 content_t c_tree = ndef->getId("mapgen_jungletree");
655 content_t c_leaves = ndef->getId("mapgen_jungleleaves");
656 if (c_tree == CONTENT_IGNORE)
657 c_tree = ndef->getId("mapgen_tree");
658 if (c_leaves == CONTENT_IGNORE)
659 c_leaves = ndef->getId("mapgen_leaves");
661 MapNode treenode(c_tree);
662 MapNode leavesnode(c_leaves);
664 PseudoRandom pr(seed);
665 for (s16 x= -1; x <= 1; x++)
666 for (s16 z= -1; z <= 1; z++) {
667 if (pr.range(0, 2) == 0)
669 v3s16 p1 = p0 + v3s16(x, 0, z);
670 v3s16 p2 = p0 + v3s16(x, -1, z);
671 u32 vi1 = vmanip.m_area.index(p1);
672 u32 vi2 = vmanip.m_area.index(p2);
674 if (vmanip.m_area.contains(p2) &&
675 vmanip.m_data[vi2].getContent() == CONTENT_AIR)
676 vmanip.m_data[vi2] = treenode;
677 else if (vmanip.m_area.contains(p1) &&
678 vmanip.m_data[vi1].getContent() == CONTENT_AIR)
679 vmanip.m_data[vi1] = treenode;
681 vmanip.m_data[vmanip.m_area.index(p0)] = treenode;
683 s16 trunk_h = pr.range(8, 12);
685 for (s16 ii = 0; ii < trunk_h; ii++) {
686 if (vmanip.m_area.contains(p1)) {
687 u32 vi = vmanip.m_area.index(p1);
688 vmanip.m_data[vi] = treenode;
693 // p1 is now the last piece of the trunk
696 VoxelArea leaves_a(v3s16(-3, -2, -3), v3s16(3, 2, 3));
697 //SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
698 Buffer<u8> leaves_d(leaves_a.getVolume());
699 for (s32 i = 0; i < leaves_a.getVolume(); i++)
702 // Force leaves at near the end of the trunk
704 for (s16 z = -d; z <= d; z++)
705 for (s16 y = -d; y <= d; y++)
706 for (s16 x = -d; x <= d; x++) {
707 leaves_d[leaves_a.index(v3s16(x,y,z))] = 1;
710 // Add leaves randomly
711 for (u32 iii = 0; iii < 30; iii++) {
713 pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X - d),
714 pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y - d),
715 pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z - d)
718 for (s16 z = 0; z <= d; z++)
719 for (s16 y = 0; y <= d; y++)
720 for (s16 x = 0; x <= d; x++) {
721 leaves_d[leaves_a.index(p + v3s16(x, y, z))] = 1;
725 // Blit leaves to vmanip
726 for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++)
727 for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) {
728 v3s16 pmin(leaves_a.MinEdge.X, y, z);
729 u32 i = leaves_a.index(pmin);
730 u32 vi = vmanip.m_area.index(pmin + p1);
731 for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) {
733 if (vmanip.m_area.contains(p + p1) == true &&
734 (vmanip.m_data[vi].getContent() == CONTENT_AIR ||
735 vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) {
736 if (leaves_d[i] == 1)
737 vmanip.m_data[vi] = leavesnode;
746 void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
749 NOTE: Tree-placing code is currently duplicated in the engine
750 and in games that have saplings; both are deprecated but not
753 content_t c_tree = ndef->getId("mapgen_pine_tree");
754 content_t c_leaves = ndef->getId("mapgen_pine_needles");
755 content_t c_snow = ndef->getId("mapgen_snow");
756 if (c_tree == CONTENT_IGNORE)
757 c_tree = ndef->getId("mapgen_tree");
758 if (c_leaves == CONTENT_IGNORE)
759 c_leaves = ndef->getId("mapgen_leaves");
760 if (c_snow == CONTENT_IGNORE)
761 c_snow = CONTENT_AIR;
763 MapNode treenode(c_tree);
764 MapNode leavesnode(c_leaves);
765 MapNode snownode(c_snow);
767 PseudoRandom pr(seed);
768 u16 trunk_h = pr.range(9, 13);
770 for (u16 ii = 0; ii < trunk_h; ii++) {
771 if (vmanip.m_area.contains(p1)) {
772 u32 vi = vmanip.m_area.index(p1);
773 vmanip.m_data[vi] = treenode;
778 // Make p1 the top node of the trunk
781 VoxelArea leaves_a(v3s16(-3, -6, -3), v3s16(3, 3, 3));
782 Buffer<u8> leaves_d(leaves_a.getVolume());
783 for (s32 i = 0; i < leaves_a.getVolume(); i++)
788 for (s16 yy = -1; yy <= 1; yy++) {
789 for (s16 zz = -dev; zz <= dev; zz++) {
790 u32 i = leaves_a.index(v3s16(-dev, yy, zz));
791 u32 ia = leaves_a.index(v3s16(-dev, yy+1, zz));
792 for (s16 xx = -dev; xx <= dev; xx++) {
793 if (pr.range(0, 20) <= 19 - dev) {
805 u32 i = leaves_a.index(v3s16(0, 1, 0));
807 i = leaves_a.index(v3s16(0, 2, 0));
809 i = leaves_a.index(v3s16(0, 3, 0));
814 for (u32 iii = 0; iii < 20; iii++) {
815 s16 xi = pr.range(-3, 2);
816 s16 yy = pr.range(-6, -5);
817 s16 zi = pr.range(-3, 2);
820 for (s16 zz = zi; zz <= zi + 1; zz++) {
821 u32 i = leaves_a.index(v3s16(xi, yy, zz));
822 u32 ia = leaves_a.index(v3s16(xi, yy + 1, zz));
823 for (s16 xx = xi; xx <= xi + 1; xx++) {
825 if (leaves_d[ia] == 0)
834 for (s16 yy = my + 1; yy <= my + 2; yy++) {
835 for (s16 zz = -dev; zz <= dev; zz++) {
836 u32 i = leaves_a.index(v3s16(-dev, yy, zz));
837 u32 ia = leaves_a.index(v3s16(-dev, yy + 1, zz));
838 for (s16 xx = -dev; xx <= dev; xx++) {
839 if (pr.range(0, 20) <= 19 - dev) {
850 // Blit leaves to vmanip
851 for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++)
852 for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) {
853 v3s16 pmin(leaves_a.MinEdge.X, y, z);
854 u32 i = leaves_a.index(pmin);
855 u32 vi = vmanip.m_area.index(pmin + p1);
856 for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) {
858 if (vmanip.m_area.contains(p + p1) == true &&
859 (vmanip.m_data[vi].getContent() == CONTENT_AIR ||
860 vmanip.m_data[vi].getContent() == CONTENT_IGNORE ||
861 vmanip.m_data[vi] == snownode)) {
862 if (leaves_d[i] == 1)
863 vmanip.m_data[vi] = leavesnode;
864 else if (leaves_d[i] == 2)
865 vmanip.m_data[vi] = snownode;
873 }; // namespace treegen