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")
8 function default
.grow_tree(data
, a
, pos
, is_apple_tree
, seed
)
10 NOTE: Tree-placing code is currently duplicated in the engine
11 and in games that have saplings; both are deprecated but not
14 local pr
= PseudoRandom(seed
)
15 local th
= pr
:next(4, 6)
16 local x
, y
, z
= pos
.x
, pos
.y
, pos
.z
18 local vi
= a
:index(x
, yy
, z
)
19 if a
:contains(x
, yy
, z
) and (data
[vi
] == c_air
or yy
== y
) then
23 y
= y
+th
-1 -- (x, y, z) is now last piece of trunk
24 local leaves_a
= VoxelArea
:new
{MinEdge
={x
=-2, y
=-2, z
=-2}, MaxEdge
={x
=2, y
=2, z
=2}}
25 local leaves_buffer
= {}
27 -- Force leaves near the trunk
32 leaves_buffer
[leaves_a
:index(xi
, yi
, zi
)] = true
37 -- Add leaves randomly
40 local xx
= pr
:next(leaves_a
.MinEdge
.x
, leaves_a
.MaxEdge
.x
- d
)
41 local yy
= pr
:next(leaves_a
.MinEdge
.y
, leaves_a
.MaxEdge
.y
- d
)
42 local zz
= pr
:next(leaves_a
.MinEdge
.z
, leaves_a
.MaxEdge
.z
- d
)
47 leaves_buffer
[leaves_a
:index(xx
+xi
, yy
+yi
, zz
+zi
)] = true
54 for xi
= leaves_a
.MinEdge
.x
, leaves_a
.MaxEdge
.x
do
55 for yi
= leaves_a
.MinEdge
.y
, leaves_a
.MaxEdge
.y
do
56 for zi
= leaves_a
.MinEdge
.z
, leaves_a
.MaxEdge
.z
do
57 if a
:contains(x
+xi
, y
+yi
, z
+zi
) then
58 local vi
= a
:index(x
+xi
, y
+yi
, z
+zi
)
59 if data
[vi
] == c_air
or data
[vi
] == c_ignore
then
60 if leaves_buffer
[leaves_a
:index(xi
, yi
, zi
)] then
61 if pr
:next(1, 100) <= 3 then -- is_apple_tree and(zwischen if und pr:next)
75 local c_jungletree
= minetest
.get_content_id("default:jungletree")
76 local c_jungleleaves
= minetest
.get_content_id("default:jungleleaves")
79 function default
.grow_jungletree(data
, a
, pos
, seed
)
81 NOTE: Tree-placing code is currently duplicated in the engine
82 and in games that have saplings; both are deprecated but not
85 local pr
= PseudoRandom(seed
)
86 local x
, y
, z
= pos
.x
, pos
.y
, pos
.z
89 -- if pr:next(1, 3) >= 2 then
90 -- local vi1 = a:index(x+xi, y, z+zi)
91 -- local vi2 = a:index(x+xi, y-1, z+zi)
92 -- if a:contains(x+xi, y-1, z+zi) and data[vi2] == c_air then
93 -- data[vi2] = c_jungletree
94 -- elseif a:contains(x+xi, y, z+zi) and data[vi1] == c_air then
95 -- data[vi1] = c_jungletree
101 local th
= pr
:next(10, 14)
102 for yy
= y
, y
+th
-1 do
103 local vi
= a
:index(x
, yy
, z
)
104 if a
:contains(x
, yy
, z
) and (data
[vi
] == c_air
or yy
== y
) then
105 data
[vi
] = c_jungletree
108 y
= y
+th
-1 -- (x, y, z) is now last piece of trunk
109 local leaves_a
= VoxelArea
:new
{MinEdge
={x
=-3, y
=-4, z
=-3}, MaxEdge
={x
=3, y
=2, z
=3}}
110 local leaves_buffer
= {}
112 -- Force leaves near the trunk
117 leaves_buffer
[leaves_a
:index(xi
, yi
, zi
)] = true
122 -- Add leaves randomly
125 local xx
= pr
:next(leaves_a
.MinEdge
.x
, leaves_a
.MaxEdge
.x
- d
)
126 local yy
= pr
:next(leaves_a
.MinEdge
.y
, leaves_a
.MaxEdge
.y
- d
)
127 local zz
= pr
:next(leaves_a
.MinEdge
.z
, leaves_a
.MaxEdge
.z
- d
)
132 leaves_buffer
[leaves_a
:index(xx
+xi
, yy
+yi
, zz
+zi
)] = true
139 for xi
= leaves_a
.MinEdge
.x
, leaves_a
.MaxEdge
.x
do
140 for yi
= leaves_a
.MinEdge
.y
, leaves_a
.MaxEdge
.y
do
141 for zi
= leaves_a
.MinEdge
.z
, leaves_a
.MaxEdge
.z
do
142 if a
:contains(x
+xi
, y
+yi
, z
+zi
) then
143 local vi
= a
:index(x
+xi
, y
+yi
, z
+zi
)
144 if data
[vi
] == c_air
or data
[vi
] == c_ignore
then
145 if leaves_buffer
[leaves_a
:index(xi
, yi
, zi
)] then
146 data
[vi
] = c_jungleleaves