1 local c_air = minetest.get_content_id("air")
2 local c_ignore = minetest.get_content_id("ignore")
3 local c_tree = minetest.get_content_id("default:tree")
4 local c_leaves = minetest.get_content_id("default:leaves")
5 local c_apple = minetest.get_content_id("default:apple")
7 function default.grow_tree(data, a, pos, is_apple_tree, seed)
9 NOTE: Tree-placing code is currently duplicated in the engine
10 and in games that have saplings; both are deprecated but not
13 local pr = PseudoRandom(seed)
14 local th = pr:next(4, 5)
15 local x, y, z = pos.x, pos.y, pos.z
17 local vi = a:index(x, yy, z)
18 if a:contains(x, yy, z) and (data[vi] == c_air or yy == y) then
22 y = y+th-1 -- (x, y, z) is now last piece of trunk
23 local leaves_a = VoxelArea:new{MinEdge={x=-2, y=-1, z=-2}, MaxEdge={x=2, y=2, z=2}}
24 local leaves_buffer = {}
26 -- Force leaves near the trunk
31 leaves_buffer[leaves_a:index(xi, yi, zi)] = true
36 -- Add leaves randomly
39 local xx = pr:next(leaves_a.MinEdge.x, leaves_a.MaxEdge.x - d)
40 local yy = pr:next(leaves_a.MinEdge.y, leaves_a.MaxEdge.y - d)
41 local zz = pr:next(leaves_a.MinEdge.z, leaves_a.MaxEdge.z - d)
46 leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true
53 for xi = leaves_a.MinEdge.x, leaves_a.MaxEdge.x do
54 for yi = leaves_a.MinEdge.y, leaves_a.MaxEdge.y do
55 for zi = leaves_a.MinEdge.z, leaves_a.MaxEdge.z do
56 if a:contains(x+xi, y+yi, z+zi) then
57 local vi = a:index(x+xi, y+yi, z+zi)
58 if data[vi] == c_air or data[vi] == c_ignore then
59 if leaves_buffer[leaves_a:index(xi, yi, zi)] then
60 if is_apple_tree and pr:next(1, 100) <= 10 then
73 local c_jungletree = minetest.get_content_id("default:jungletree")
74 local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
76 function default.grow_jungletree(data, a, pos, seed)
78 NOTE: Tree-placing code is currently duplicated in the engine
79 and in games that have saplings; both are deprecated but not
82 local pr = PseudoRandom(seed)
83 local x, y, z = pos.x, pos.y, pos.z
86 if pr:next(1, 3) >= 2 then
87 local vi1 = a:index(x+xi, y, z+zi)
88 local vi2 = a:index(x+xi, y-1, z+zi)
89 if a:contains(x+xi, y-1, z+zi) and data[vi2] == c_air then
90 data[vi2] = c_jungletree
91 elseif a:contains(x+xi, y, z+zi) and data[vi1] == c_air then
92 data[vi1] = c_jungletree
98 local th = pr:next(8, 12)
100 local vi = a:index(x, yy, z)
101 if a:contains(x, yy, z) and (data[vi] == c_air or yy == y) then
102 data[vi] = c_jungletree
105 y = y+th-1 -- (x, y, z) is now last piece of trunk
106 local leaves_a = VoxelArea:new{MinEdge={x=-3, y=-2, z=-3}, MaxEdge={x=3, y=2, z=3}}
107 local leaves_buffer = {}
109 -- Force leaves near the trunk
114 leaves_buffer[leaves_a:index(xi, yi, zi)] = true
119 -- Add leaves randomly
122 local xx = pr:next(leaves_a.MinEdge.x, leaves_a.MaxEdge.x - d)
123 local yy = pr:next(leaves_a.MinEdge.y, leaves_a.MaxEdge.y - d)
124 local zz = pr:next(leaves_a.MinEdge.z, leaves_a.MaxEdge.z - d)
129 leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true
136 for xi = leaves_a.MinEdge.x, leaves_a.MaxEdge.x do
137 for yi = leaves_a.MinEdge.y, leaves_a.MaxEdge.y do
138 for zi = leaves_a.MinEdge.z, leaves_a.MaxEdge.z do
139 if a:contains(x+xi, y+yi, z+zi) then
140 local vi = a:index(x+xi, y+yi, z+zi)
141 if data[vi] == c_air or data[vi] == c_ignore then
142 if leaves_buffer[leaves_a:index(xi, yi, zi)] then
143 data[vi] = c_jungleleaves