-
Notifications
You must be signed in to change notification settings - Fork 2
/
sapling.lua
153 lines (125 loc) · 3.41 KB
/
sapling.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
150
151
152
153
-- Register Saplings
local register_sapling = function(name, desc, texture, height)
minetest.register_node("redwood:redwood_sapling", {
description = desc .. " Tree Sapling",
drawtype = "plantlike",
tiles = {texture .. ".png"},
inventory_image = texture .. ".png",
wield_image = texture .. ".png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 7 / 16, 4 / 16}
},
groups = {
snappy = 2, dig_immediate = 3, flammable = 2,
attached_node = 1, sapling = 1
},
sounds = default.node_sound_leaves_defaults(),
grown_height = height,
})
minetest.register_node("redwood:redwood_sapling_ongen", {
description = desc .. " Tree Sapling (ongen)",
drawtype = "plantlike",
tiles = {texture .. ".png"},
inventory_image = texture .. ".png",
wield_image = texture .. ".png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
drop = "redwood:redwood_sapling",
selection_box = {
type = "fixed",
fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 7 / 16, 4 / 16}
},
groups = {
snappy = 2, dig_immediate = 3, flammable = 2,
attached_node = 1, sapling = 1
},
sounds = default.node_sound_leaves_defaults(),
grown_height = height,
})
end
register_sapling("redwood:redwood", "Redwood", "redwood_sapling", 31)
local add_tree = function (pos, ofx, ofy, ofz, schem, replace)
-- check for schematic
if not schem then
print ("Schematic not found")
return
end
-- remove sapling and place schematic
minetest.swap_node(pos, {name = "air"})
minetest.place_schematic(
{x = pos.x - ofx, y = pos.y - ofy, z = pos.z - ofz},
schem, 0, replace, false)
end
function redwood.grow_redwood_tree(pos)
add_tree(pos, 7, 0, 7, redwood.redwood_tree)
end
-- check if sapling has enough height room to grow
local enough_height = function(pos, height)
local nod = minetest.line_of_sight(
{x = pos.x, y = pos.y + 1, z = pos.z},
{x = pos.x, y = pos.y + height, z = pos.z})
if not nod then
return false -- obstructed
else
return true -- can grow
end
end
redwood.grow_sapling = function(pos)
local node = minetest.get_node(pos)
local under = minetest.get_node({
x = pos.x,
y = pos.y - 1,
z = pos.z
}).name
if not minetest.registered_nodes[node.name] then
return
end
local height = minetest.registered_nodes[node.name].grown_height
-- do we have enough height to grow sapling into tree?
if not height or not enough_height(pos, height) then
return
end
if under == "default:dirt_with_dry_grass"
or under == "default:dirt"
or under == "default:dry_dirt_with_dry_grass"
or under == "default:dry_dirt" then
redwood.grow_redwood_tree(pos)
end
end
-- Grow saplings
minetest.register_abm({
label = "redwood grow sapling",
nodenames = {"redwood:redwood_sapling"},
interval = 10,
chance = 50,
catch_up = false,
action = function(pos, node)
local light_level = minetest.get_node_light(pos) or 0
if light_level < 13 then
return
end
redwood.grow_sapling(pos, node)
end,
})
-- Grow saplings
minetest.register_abm({
label = "redwood grow sapling",
nodenames = {"redwood:redwood_sapling_ongen"},
interval = 1,
chance = 1,
catch_up = true,
action = function(pos, node)
local light_level = minetest.get_node_light(pos) or 0
if light_level < 13 then
return
end
redwood.grow_sapling(pos, node)
end,
})