/
jungletree.lua
149 lines (142 loc) · 5.2 KB
/
jungletree.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
local function add_tree_branch(pos)
local leaves = {"green","yellow","red"}
local leave = "trees:leaves_"..leaves[math.random(1,3)]
minetest.env:add_node(pos, {name="default:jungletree"})
--height
local height = 2 + math.random(3)
for y = height , 0, -1 do
if y <= 0 then return end
for x = y, -y, -1 do
for z = y, -y, -1 do
if math.abs(x)+math.abs(z) <= 4 then
local p = {x=pos.x+x, y=pos.y+height-1-y, z=pos.z+z}
local n = minetest.env:get_node(p)
if (n.name=="air") then
minetest.env:add_node(p, {name=leave})
elseif (n.name=="ignore") then
minetest.after(20, function()
minetest.env:add_node(p, {name=leave})
end)
end
end
end
end
end
end
abstract_trees.grow_jungletree = function(pos)
minetest.after(5, function()
local size = 5+math.random(15)
if size < 10 then
for i = size, -2, -1 do
local p = {x=pos.x, y=pos.y+i, z=pos.z}
minetest.env:add_node(p, {name="default:jungletree"})
if i == size then
add_tree_branch({x=pos.x, y=pos.y+size+math.random(0, 1), z=pos.z})
add_tree_branch({x=pos.x+1, y=pos.y+i-math.random(2), z=pos.z})
add_tree_branch({x=pos.x-1, y=pos.y+i-math.random(2), z=pos.z})
add_tree_branch({x=pos.x, y=pos.y+i-math.random(2), z=pos.z+1})
add_tree_branch({x=pos.x, y=pos.y+i-math.random(2), z=pos.z-1})
end
if i < 0 then
minetest.env:add_node({x=pos.x+1, y=pos.y+i-math.random(2), z=pos.z}, {name="default:jungletree"})
minetest.env:add_node({x=pos.x, y=pos.y+i-math.random(2), z=pos.z+1}, {name="default:jungletree"})
minetest.env:add_node({x=pos.x-1, y=pos.y+i-math.random(2), z=pos.z}, {name="default:jungletree"})
minetest.env:add_node({x=pos.x, y=pos.y+i-math.random(2), z=pos.z-1}, {name="default:jungletree"})
end
if (math.sin(i/size*i) < 0.2 and i > 3 and math.random(0,2) < 1.5) then
branch_pos = {x=pos.x+math.random(0,1), y=pos.y+i, z=pos.z-math.random(0,1)}
add_tree_branch(branch_pos)
end
end
else
for i = size, -1, -1 do
if (math.sin(i/size*i) < 0.2 and i > 3 and math.random(0,2) < 1.5) then
branch_pos = {x=pos.x-1+math.random(0,2), y=pos.y+i, z=pos.z-1-math.random(0,2)}
add_tree_branch(branch_pos)
end
if i < math.random(2) then
add_tree_branch({x=pos.x+1, y=pos.y+i, z=pos.z+1})
add_tree_branch({x=pos.x+2, y=pos.y+i, z=pos.z-1})
add_tree_branch({x=pos.x, y=pos.y+i, z=pos.z-2})
add_tree_branch({x=pos.x-1, y=pos.y+i, z=pos.z})
end
if i == size then
add_tree_branch({x=pos.x+1, y=pos.y+i, z=pos.z+1})
add_tree_branch({x=pos.x+2, y=pos.y+i, z=pos.z-1})
add_tree_branch({x=pos.x, y=pos.y+i, z=pos.z-2})
add_tree_branch({x=pos.x-1, y=pos.y+i, z=pos.z})
add_tree_branch({x=pos.x+1, y=pos.y+i, z=pos.z+2})
add_tree_branch({x=pos.x+3, y=pos.y+i, z=pos.z-1})
add_tree_branch({x=pos.x, y=pos.y+i, z=pos.z-3})
add_tree_branch({x=pos.x-2, y=pos.y+i, z=pos.z})
add_tree_branch({x=pos.x+1, y=pos.y+i, z=pos.z})
add_tree_branch({x=pos.x+1, y=pos.y+i, z=pos.z-1})
add_tree_branch({x=pos.x, y=pos.y+i, z=pos.z-1})
add_tree_branch({x=pos.x, y=pos.y+i, z=pos.z})
else
minetest.env:add_node({x=pos.x+1, y=pos.y+i, z=pos.z}, {name="default:jungletree"})
minetest.env:add_node({x=pos.x+1, y=pos.y+i, z=pos.z-1}, {name="default:jungletree"})
minetest.env:add_node({x=pos.x, y=pos.y+i, z=pos.z-1}, {name="default:jungletree"})
minetest.env:add_node({x=pos.x, y=pos.y+i, z=pos.z}, {name="default:jungletree"})
end
end
end
end)
end
--nodes
local leaves = {"green","yellow","red"}
for color = 1, 3 do
local leave_name = "trees:leaves_"..leaves[color]
minetest.register_node(leave_name, {
description = "Jungle Tree Leaves",
drawtype = "allfaces_optional",
tiles = {"trees_leaves_"..leaves[color]..".png"},
paramtype = "light",
groups = {snappy=3, leafdecay=3, flammable=2},
drop = {
max_items = 1,
items = {
{items = {'trees:jungletree_sapling'},rarity = 20},
}
},
sounds = default.node_sound_leaves_defaults(),
})
end
minetest.register_node("trees:jungletree_sapling", {
description = "Jungle Tree Sapling",
drawtype = "plantlike",
visual_scale = 1.0,
tiles = {"trees_jungletree_sapling.png"},
inventory_image = "trees_jungletree_sapling.png",
wield_image = "trees_jungletree_sapling.png",
paramtype = "light",
walkable = false,
groups = {snappy=2,dig_immediate=3,flammable=2},
})
--abm
minetest.register_abm({
nodenames = {"trees:jungletree_sapling"},
interval = 300,
chance = 20,
action = function(pos, node)
abstract_trees.grow_jungletree(pos)
end,
})
--spawn
biome_lib:register_generate_plant({
surface = "default:dirt_with_grass",
max_count = 30,
avoid_nodes = {"group:tree"},
avoid_radius = 2,
rarity = 40,
seed_diff = 112,
min_elevation = -1,
max_elevation = 40,
plantlife_limit = -0.6,
humidity_max = -0.9,
humidity_min = 0.4,
temp_max = -0.9,
temp_min = -0.3,
},
"abstract_trees.grow_jungletree"
)