+ for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++)
+ for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) {
+ v3s16 pmin(leaves_a.MinEdge.X, y, z);
+ u32 i = leaves_a.index(pmin);
+ u32 vi = vmanip.m_area.index(pmin + p1);
+ for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) {
+ v3s16 p(x, y, z);
+ if (vmanip.m_area.contains(p + p1) == true &&
+ (vmanip.m_data[vi].getContent() == CONTENT_AIR ||
+ vmanip.m_data[vi].getContent() == CONTENT_IGNORE)) {
+ if (leaves_d[i] == 1)
+ vmanip.m_data[vi] = leavesnode;
+ }
+ vi++;
+ i++;
+ }
+ }
+}
+
+
+void make_pine_tree(MMVManip &vmanip, v3s16 p0, INodeDefManager *ndef, s32 seed)
+{
+ /*
+ NOTE: Tree-placing code is currently duplicated in the engine
+ and in games that have saplings; both are deprecated but not
+ replaced yet
+ */
+ content_t c_tree = ndef->getId("mapgen_pine_tree");
+ content_t c_leaves = ndef->getId("mapgen_pine_needles");
+ content_t c_snow = ndef->getId("mapgen_snow");
+ if (c_tree == CONTENT_IGNORE)
+ c_tree = ndef->getId("mapgen_tree");
+ if (c_leaves == CONTENT_IGNORE)
+ c_leaves = ndef->getId("mapgen_leaves");
+ if (c_snow == CONTENT_IGNORE)
+ c_snow = CONTENT_AIR;
+
+ MapNode treenode(c_tree);
+ MapNode leavesnode(c_leaves);
+ MapNode snownode(c_snow);
+
+ PseudoRandom pr(seed);
+ u16 trunk_h = pr.range(9, 13);
+ v3s16 p1 = p0;
+ for (u16 ii = 0; ii < trunk_h; ii++) {
+ if (vmanip.m_area.contains(p1)) {
+ u32 vi = vmanip.m_area.index(p1);
+ vmanip.m_data[vi] = treenode;
+ }
+ p1.Y++;
+ }
+
+ // Make p1 the top node of the trunk
+ p1.Y -= 1;
+
+ VoxelArea leaves_a(v3s16(-3, -6, -3), v3s16(3, 3, 3));
+ //SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
+ Buffer<u8> leaves_d(leaves_a.getVolume());
+ for (s32 i = 0; i < leaves_a.getVolume(); i++)
+ leaves_d[i] = 0;
+
+ // Upper branches
+ u16 dev = 3;
+ for (s16 yy = -1; yy <= 1; yy++) {
+ for (s16 zz = -dev; zz <= dev; zz++) {
+ u32 i = leaves_a.index(v3s16(-dev, yy, zz));
+ u32 ia = leaves_a.index(v3s16(-dev, yy+1, zz));
+ for (s16 xx = -dev; xx <= dev; xx++) {
+ if (pr.range(0, 20) <= 19 - dev) {
+ leaves_d[i] = 1;
+ leaves_d[ia] = 2;
+ }
+ i++;
+ ia++;
+ }
+ }
+ dev--;
+ }
+
+ // Centre top nodes
+ u32 i = leaves_a.index(v3s16(0, 1, 0));
+ leaves_d[i] = 1;
+ i = leaves_a.index(v3s16(0, 2, 0));
+ leaves_d[i] = 1;
+ i = leaves_a.index(v3s16(0, 3, 0));
+ leaves_d[i] = 2;
+
+ // Lower branches
+ s16 my = -6;
+ for (u32 iii = 0; iii < 20; iii++) {
+ s16 xi = pr.range(-3, 2);
+ s16 yy = pr.range(-6, -5);
+ s16 zi = pr.range(-3, 2);
+ if (yy > my)
+ my = yy;
+ for (s16 zz = zi; zz <= zi + 1; zz++) {
+ u32 i = leaves_a.index(v3s16(xi, yy, zz));
+ u32 ia = leaves_a.index(v3s16(xi, yy + 1, zz));
+ for (s16 xx = xi; xx <= xi + 1; xx++) {
+ leaves_d[i] = 1;
+ if (leaves_d[ia] == 0)
+ leaves_d[ia] = 2;
+ i++;
+ ia++;
+ }
+ }
+ }
+
+ dev = 2;
+ for (s16 yy = my + 1; yy <= my + 2; yy++) {
+ for (s16 zz = -dev; zz <= dev; zz++) {
+ u32 i = leaves_a.index(v3s16(-dev, yy, zz));
+ u32 ia = leaves_a.index(v3s16(-dev, yy + 1, zz));
+ for (s16 xx = -dev; xx <= dev; xx++) {
+ if (pr.range(0, 20) <= 19 - dev) {
+ leaves_d[i] = 1;
+ leaves_d[ia] = 2;
+ }
+ i++;
+ ia++;
+ }
+ }
+ dev--;
+ }
+
+ // Blit leaves to vmanip
+ for (s16 z = leaves_a.MinEdge.Z; z <= leaves_a.MaxEdge.Z; z++)
+ for (s16 y = leaves_a.MinEdge.Y; y <= leaves_a.MaxEdge.Y; y++) {
+ v3s16 pmin(leaves_a.MinEdge.X, y, z);
+ u32 i = leaves_a.index(pmin);
+ u32 vi = vmanip.m_area.index(pmin + p1);
+ for (s16 x = leaves_a.MinEdge.X; x <= leaves_a.MaxEdge.X; x++) {
+ v3s16 p(x, y, z);
+ if (vmanip.m_area.contains(p + p1) == true &&
+ (vmanip.m_data[vi].getContent() == CONTENT_AIR ||
+ vmanip.m_data[vi].getContent() == CONTENT_IGNORE ||
+ vmanip.m_data[vi] == snownode)) {
+ if (leaves_d[i] == 1)
+ vmanip.m_data[vi] = leavesnode;
+ else if (leaves_d[i] == 2)
+ vmanip.m_data[vi] = snownode;
+ }
+ vi++;
+ i++;
+ }