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 content_t current_node = vmanip.m_data[vi].getContent();
546 if (current_node != CONTENT_AIR && current_node != CONTENT_IGNORE
547 && current_node != tree_definition.leavesnode.getContent()
548 && current_node != tree_definition.leaves2node.getContent()
549 && current_node != tree_definition.fruitnode.getContent())
551 vmanip.m_data[vi] = tree_definition.trunknode;
555 void tree_leaves_placement(MMVManip &vmanip, v3f p0,
556 PseudoRandom ps, TreeDef &tree_definition)
558 MapNode leavesnode = tree_definition.leavesnode;
559 if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance)
560 leavesnode = tree_definition.leaves2node;
561 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
562 if (vmanip.m_area.contains(p1) == false)
564 u32 vi = vmanip.m_area.index(p1);
565 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
566 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
568 if (tree_definition.fruit_chance > 0) {
569 if (ps.range(1, 100) > 100 - tree_definition.fruit_chance)
570 vmanip.m_data[vmanip.m_area.index(p1)] = tree_definition.fruitnode;
572 vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode;
573 } else if (ps.range(1, 100) > 20) {
574 vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode;
579 void tree_single_leaves_placement(MMVManip &vmanip, v3f p0,
580 PseudoRandom ps, TreeDef &tree_definition)
582 MapNode leavesnode = tree_definition.leavesnode;
583 if (ps.range(1, 100) > 100 - tree_definition.leaves2_chance)
584 leavesnode = tree_definition.leaves2node;
585 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
586 if (vmanip.m_area.contains(p1) == false)
588 u32 vi = vmanip.m_area.index(p1);
589 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
590 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
592 vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode;
596 void tree_fruit_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition)
598 v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
599 if (vmanip.m_area.contains(p1) == false)
601 u32 vi = vmanip.m_area.index(p1);
602 if (vmanip.m_data[vi].getContent() != CONTENT_AIR
603 && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
605 vmanip.m_data[vmanip.m_area.index(p1)] = tree_definition.fruitnode;
609 irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis)
611 double c = cos(angle);
612 double s = sin(angle);
615 double tx = t * axis.X;
616 double ty = t * axis.Y;
617 double tz = t * axis.Z;
618 double sx = s * axis.X;
619 double sy = s * axis.Y;
620 double sz = s * axis.Z;
622 M[0] = tx * axis.X + c;
623 M[1] = tx * axis.Y + sz;
624 M[2] = tx * axis.Z - sy;
626 M[4] = ty * axis.X - sz;
627 M[5] = ty * axis.Y + c;
628 M[6] = ty * axis.Z + sx;
630 M[8] = tz * axis.X + sy;
631 M[9] = tz * axis.Y - sx;
632 M[10] = tz * axis.Z + c;
637 v3f transposeMatrix(irr::core::matrix4 M, v3f v)
640 double x = M[0] * v.X + M[4] * v.Y + M[8] * v.Z +M[12];
641 double y = M[1] * v.X + M[5] * v.Y + M[9] * v.Z +M[13];
642 double z = M[2] * v.X + M[6] * v.Y + M[10] * v.Z +M[14];
650 void make_jungletree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
653 NOTE: Tree-placing code is currently duplicated in the engine
654 and in games that have saplings; both are deprecated but not
657 content_t c_tree = ndef->getId("mapgen_jungletree");
658 content_t c_leaves = ndef->getId("mapgen_jungleleaves");
659 if (c_tree == CONTENT_IGNORE)
660 c_tree = ndef->getId("mapgen_tree");
661 if (c_leaves == CONTENT_IGNORE)
662 c_leaves = ndef->getId("mapgen_leaves");
664 MapNode treenode(c_tree);
665 MapNode leavesnode(c_leaves);
667 PseudoRandom pr(seed);
668 for (s16 x= -1; x <= 1; x++)
669 for (s16 z= -1; z <= 1; z++) {
670 if (pr.range(0, 2) == 0)
672 v3s16 p1 = p0 + v3s16(x, 0, z);
673 v3s16 p2 = p0 + v3s16(x, -1, z);
674 u32 vi1 = vmanip.m_area.index(p1);
675 u32 vi2 = vmanip.m_area.index(p2);
677 if (vmanip.m_area.contains(p2) &&
678 vmanip.m_data[vi2].getContent() == CONTENT_AIR)
679 vmanip.m_data[vi2] = treenode;
680 else if (vmanip.m_area.contains(p1) &&
681 vmanip.m_data[vi1].getContent() == CONTENT_AIR)
682 vmanip.m_data[vi1] = treenode;
684 vmanip.m_data[vmanip.m_area.index(p0)] = treenode;
686 s16 trunk_h = pr.range(8, 12);
688 for (s16 ii = 0; ii < trunk_h; ii++) {
689 if (vmanip.m_area.contains(p1)) {
690 u32 vi = vmanip.m_area.index(p1);
691 vmanip.m_data[vi] = treenode;
696 // p1 is now the last piece of the trunk
699 VoxelArea leaves_a(v3s16(-3, -2, -3), v3s16(3, 2, 3));
700 //SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
701 Buffer<u8> leaves_d(leaves_a.getVolume());
702 for (s32 i = 0; i < leaves_a.getVolume(); i++)
705 // Force leaves at near the end of the trunk
707 for (s16 z = -d; z <= d; z++)
708 for (s16 y = -d; y <= d; y++)
709 for (s16 x = -d; x <= d; x++) {
710 leaves_d[leaves_a.index(v3s16(x,y,z))] = 1;
713 // Add leaves randomly
714 for (u32 iii = 0; iii < 30; iii++) {
716 pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X - d),
717 pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y - d),
718 pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z - d)
721 for (s16 z = 0; z <= d; z++)
722 for (s16 y = 0; y <= d; y++)
723 for (s16 x = 0; x <= d; x++) {
724 leaves_d[leaves_a.index(p + v3s16(x, y, z))] = 1;
728 // Blit leaves to vmanip
729 for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++)
730 for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) {
731 v3s16 pmin(leaves_a.MinEdge.X, y, z);
732 u32 i = leaves_a.index(pmin);
733 u32 vi = vmanip.m_area.index(pmin + p1);
734 for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) {
736 if (vmanip.m_area.contains(p + p1) == true &&
737 (vmanip.m_data[vi].getContent() == CONTENT_AIR ||
738 vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) {
739 if (leaves_d[i] == 1)
740 vmanip.m_data[vi] = leavesnode;
749 void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
752 NOTE: Tree-placing code is currently duplicated in the engine
753 and in games that have saplings; both are deprecated but not
756 content_t c_tree = ndef->getId("mapgen_pine_tree");
757 content_t c_leaves = ndef->getId("mapgen_pine_needles");
758 content_t c_snow = ndef->getId("mapgen_snow");
759 if (c_tree == CONTENT_IGNORE)
760 c_tree = ndef->getId("mapgen_tree");
761 if (c_leaves == CONTENT_IGNORE)
762 c_leaves = ndef->getId("mapgen_leaves");
763 if (c_snow == CONTENT_IGNORE)
764 c_snow = CONTENT_AIR;
766 MapNode treenode(c_tree);
767 MapNode leavesnode(c_leaves);
768 MapNode snownode(c_snow);
770 PseudoRandom pr(seed);
771 u16 trunk_h = pr.range(9, 13);
773 for (u16 ii = 0; ii < trunk_h; ii++) {
774 if (vmanip.m_area.contains(p1)) {
775 u32 vi = vmanip.m_area.index(p1);
776 vmanip.m_data[vi] = treenode;
781 // Make p1 the top node of the trunk
784 VoxelArea leaves_a(v3s16(-3, -6, -3), v3s16(3, 3, 3));
785 Buffer<u8> leaves_d(leaves_a.getVolume());
786 for (s32 i = 0; i < leaves_a.getVolume(); i++)
791 for (s16 yy = -1; yy <= 1; yy++) {
792 for (s16 zz = -dev; zz <= dev; zz++) {
793 u32 i = leaves_a.index(v3s16(-dev, yy, zz));
794 u32 ia = leaves_a.index(v3s16(-dev, yy+1, zz));
795 for (s16 xx = -dev; xx <= dev; xx++) {
796 if (pr.range(0, 20) <= 19 - dev) {
808 leaves_d[leaves_a.index(v3s16(0, 1, 0))] = 1;
809 leaves_d[leaves_a.index(v3s16(0, 2, 0))] = 1;
810 leaves_d[leaves_a.index(v3s16(0, 3, 0))] = 2;
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 (s32 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