Disable treespawning on mapgen
[minetest_hades.git] / mods / default / trees.lua
blobedb8133f62fe0e3a7bfc1636339c937ca70d8df7
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)
9 --[[
10 NOTE: Tree-placing code is currently duplicated in the engine
11 and in games that have saplings; both are deprecated but not
12 replaced yet
13 ]]--
14 local pr = PseudoRandom(seed)
15 local th = pr:next(4, 6)
16 local x, y, z = pos.x, pos.y, pos.z
17 for yy = y, y+th-1 do
18 local vi = a:index(x, yy, z)
19 if a:contains(x, yy, z) and (data[vi] == c_air or yy == y) then
20 data[vi] = c_tree
21 end
22 end
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
28 local d = 1
29 for xi = -d, d do
30 for yi = -d, d do
31 for zi = -d, d do
32 leaves_buffer[leaves_a:index(xi, yi, zi)] = true
33 end
34 end
35 end
37 -- Add leaves randomly
38 for iii = 1, 8 do
39 local d = 1
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)
44 for xi = 0, d do
45 for yi = 0, d do
46 for zi = 0, d do
47 leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true
48 end
49 end
50 end
51 end
53 -- Add the leaves
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)
62 data[vi] = c_apple
63 else
64 data[vi] = c_leaves
65 end
66 end
67 end
68 end
69 end
70 end
71 end
72 end
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)
80 --[[
81 NOTE: Tree-placing code is currently duplicated in the engine
82 and in games that have saplings; both are deprecated but not
83 replaced yet
84 ]]--
85 local pr = PseudoRandom(seed)
86 local x, y, z = pos.x, pos.y, pos.z
87 -- for xi = -1, 1 do
88 -- for zi = -1, 1 do
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
96 -- end
97 -- end
98 -- end
99 -- end
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
113 local d = 1
114 for xi = -d, d do
115 for yi = -d, d do
116 for zi = -d, d do
117 leaves_buffer[leaves_a:index(xi, yi, zi)] = true
122 -- Add leaves randomly
123 for iii = 1, 30 do
124 local d = 1
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)
129 for xi = 0, d do
130 for yi = 0, d do
131 for zi = 0, d do
132 leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true
138 -- Add the leaves
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