-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsapling.lua
More file actions
331 lines (248 loc) · 9.94 KB
/
sapling.lua
File metadata and controls
331 lines (248 loc) · 9.94 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
-- translator and protection check setting
local S = core.get_translator("ethereal")
local get_node = core.get_node
local sapling_protection_check = core.settings:get_bool(
"ethereal.sapling_protection_check", false)
-- sapling placement helper
local function prepare_on_place(itemstack, placer, pointed_thing, name, w, h)
if sapling_protection_check then
-- check if grown tree area intersects any players protected area
return default.sapling_on_place(itemstack, placer, pointed_thing,
name, {x = -w, y = 1, z = -w}, {x = w, y = h, z = w}, 4)
end
-- Position of sapling
local pos = pointed_thing.under
local node = get_node(pos)
local pdef = core.registered_nodes[node.name]
-- Check if node clicked on has it's own on_rightclick function
if pdef and pdef.on_rightclick
and not (placer and placer:is_player() and placer:get_player_control().sneak) then
return pdef.on_rightclick(pos, node, placer, itemstack, pointed_thing)
end
-- place normally
return core.item_place_node(itemstack, placer, pointed_thing)
end
-- Bamboo Sprout
core.register_node("ethereal:bamboo_sprout", {
description = S("Bamboo Sprout"),
drawtype = "plantlike",
tiles = {"ethereal_bamboo_sprout.png"},
inventory_image = "ethereal_bamboo_sprout.png",
wield_image = "ethereal_bamboo_sprout.png",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
groups = {
food_bamboo_sprout = 1, snappy = 3, attached_node = 1, flammable = 2,
dig_immediate = 3, ethereal_sapling = 1, sapling = 1,
},
sounds = default.node_sound_defaults(),
selection_box = {
type = "fixed", fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -0.1, 3 / 16}
},
on_use = core.item_eat(2),
grown_height = 11,
on_place = function(itemstack, placer, pointed_thing)
return prepare_on_place(itemstack, placer, pointed_thing,
"ethereal:bamboo_sprout", 1, 18)
end
})
-- register Sapling helper
local function add_sapling(name, desc, texture, width, height)
core.register_node("ethereal:" .. name .. "_sapling", {
description = S(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, 5 / 16, 4 / 16}
},
groups = {
snappy = 2, dig_immediate = 3, flammable = 2,
ethereal_sapling = 1, attached_node = 1, sapling = 1
},
sounds = default.node_sound_leaves_defaults(),
grown_height = height,
on_place = function(itemstack, placer, pointed_thing)
return prepare_on_place(itemstack, placer, pointed_thing,
name .. "_sapling", width, height)
end
})
end
-- register saplings
add_sapling("basandra_bush", "Basandra Bush", "ethereal_basandra_bush_sapling", 1, 2)
add_sapling("mangrove", "Mangrove", "mcl_mangrove_propagule", 5, 14)
add_sapling("willow", "Willow", "ethereal_willow_sapling", 5, 14)
add_sapling("yellow_tree", "Healing", "ethereal_yellow_tree_sapling", 4, 19)
add_sapling("big_tree", "Big", "ethereal_big_tree_sapling", 4, 7)
add_sapling("banana_tree", "Banana", "ethereal_banana_tree_sapling", 3, 8)
add_sapling("frost_tree", "Frost", "ethereal_frost_tree_sapling", 4, 19)
add_sapling("mushroom", "Mushroom", "ethereal_mushroom_sapling", 4, 11)
add_sapling("mushroom_brown", "Brown Mushroom", "ethereal_mushroom_brown_sapling", 1, 11)
add_sapling("palm", "Palm", "moretrees_palm_sapling", 4, 9)
add_sapling("giant_redwood", "Giant Redwood", "ethereal_giant_redwood_sapling", 7, 33)
add_sapling("redwood", "Redwood", "ethereal_redwood_sapling", 4, 21)
add_sapling("orange_tree", "Orange", "ethereal_orange_tree_sapling", 2, 6)
add_sapling("birch", "Birch", "moretrees_birch_sapling", 2, 9)
add_sapling("sakura", "Sakura", "ethereal_sakura_sapling", 4, 10)
add_sapling("lemon_tree", "Lemon", "ethereal_lemon_tree_sapling", 2, 7)
add_sapling("olive_tree", "Olive", "ethereal_olive_tree_sapling", 3, 10)
-- add tree schematic
local function add_tree(pos, schem, replace)
core.remove_node(pos)
core.place_schematic(
pos, schem, "random", replace, false, "place_center_x, place_center_z")
end
-- path to schematics folder
local path = core.get_modpath("ethereal") .. "/schematics/"
-- global tree grow functions
function ethereal.grow_mangrove_tree(pos)
add_tree(pos, ethereal.mangrove_tree)
end
function ethereal.grow_basandra_bush(pos)
add_tree(pos, ethereal.basandrabush)
end
function ethereal.grow_yellow_tree(pos)
add_tree(pos, ethereal.yellowtree)
end
function ethereal.grow_big_tree(pos)
add_tree(pos, ethereal.bigtree_from_sapling)
end
function ethereal.grow_banana_tree(pos)
if math.random(2) == 1 and core.find_node_near(pos, 1, {"farming:soil_wet"}) then
add_tree(pos, ethereal.bananatree, {{"ethereal:banana", "ethereal:banana_bunch"}})
else
add_tree(pos, ethereal.bananatree)
end
end
function ethereal.grow_frost_tree(pos)
add_tree(pos, ethereal.frosttrees_from_sapling)
end
function ethereal.grow_mushroom_tree(pos)
add_tree(pos, ethereal.mushroomone_from_sapling)
end
function ethereal.grow_mushroom_brown_tree(pos)
add_tree(pos, ethereal.mushroomtwo)
end
function ethereal.grow_palm_tree(pos)
add_tree(pos, ethereal.palmtree)
end
function ethereal.grow_willow_tree(pos)
add_tree(pos, ethereal.willow_from_sapling)
end
function ethereal.grow_redwood_tree(pos)
add_tree(pos, ethereal.redwood_small_tree_from_sapling)
end
function ethereal.grow_giant_redwood_tree(pos)
add_tree(pos, ethereal.redwood_tree_from_sapling)
end
function ethereal.grow_orange_tree(pos)
add_tree(pos, ethereal.orangetree)
end
function ethereal.grow_bamboo_tree(pos)
add_tree(pos, ethereal.bambootree)
end
function ethereal.grow_birch_tree(pos)
if core.find_node_near(pos, 1, {"ethereal:magical_dirt"}) then
local num = math.random(4)
if num > 1 then
add_tree(pos, ethereal.birchtree,
{{"ethereal:birch_leaves", "ethereal:birch_leaves" .. num}})
return
end
end
add_tree(pos, ethereal.birchtree)
end
function ethereal.grow_sakura_tree(pos)
if math.random(10) == 1 then
add_tree(pos, ethereal.sakura_tree,
{{"ethereal:sakura_leaves", "ethereal:sakura_leaves2"}})
else
add_tree(pos, ethereal.sakura_tree)
end
end
function ethereal.grow_lemon_tree(pos)
add_tree(pos, ethereal.lemontree)
end
function ethereal.grow_olive_tree(pos)
add_tree(pos, ethereal.olivetree_from_sapling)
end
-- return True if sapling has enough height room to grow
local function enough_height(pos, height)
return core.line_of_sight(
{x = pos.x, y = pos.y + 1, z = pos.z},
{x = pos.x, y = pos.y + height, z = pos.z})
end
-- global function run by Abm
function ethereal.grow_sapling(pos, node)
-- sapling definition
local def = core.registered_nodes[node and node.name] ; if not def then return end
-- enough light to grow
if (core.get_node_light(pos) or 0) < 13 then return end
-- enought height to grow
local height = def.grown_height or 33
if not enough_height(pos, height) then return end
-- get node below sapling
local under = get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name
-- default ok and magic dirt check (can grow any ethereal sapling)
local ok = false ; if under == "ethereal:magical_dirt" then ok = true end
-- check if Ethereal Sapling is growing on correct substrate
if node.name == "ethereal:basandra_bush_sapling"
and (under == "ethereal:fiery_dirt" or ok) then ethereal.grow_basandra_bush(pos)
elseif node.name == "ethereal:yellow_tree_sapling"
and core.get_item_group(under, "soil") > 0 then ethereal.grow_yellow_tree(pos)
elseif node.name == "ethereal:big_tree_sapling"
and (under == "default:dirt_with_grass" or ok) then ethereal.grow_big_tree(pos)
elseif node.name == "ethereal:banana_tree_sapling"
and (under == "ethereal:grove_dirt" or ok) then ethereal.grow_banana_tree(pos)
elseif node.name == "ethereal:frost_tree_sapling"
and (under == "ethereal:crystal_dirt" or ok) then ethereal.grow_frost_tree(pos)
elseif node.name == "ethereal:mushroom_sapling"
and (under == "ethereal:mushroom_dirt" or ok) then ethereal.grow_mushroom_tree(pos)
elseif node.name == "ethereal:mushroom_brown_sapling"
and (under == "ethereal:mushroom_dirt" or ok) then
ethereal.grow_mushroom_brown_tree(pos)
elseif node.name == "ethereal:palm_sapling"
and (under == "default:sand" or ok) then ethereal.grow_palm_tree(pos)
elseif node.name == "ethereal:willow_sapling"
and (under == "ethereal:gray_dirt" or ok) then ethereal.grow_willow_tree(pos)
elseif node.name == "ethereal:redwood_sapling"
and (under == "default:dirt_with_dry_grass" or ok) then
ethereal.grow_redwood_tree(pos)
elseif node.name == "ethereal:giant_redwood_sapling"
and (under == "default:dirt_with_dry_grass" or ok) then
ethereal.grow_giant_redwood_tree(pos)
elseif node.name == "ethereal:orange_tree_sapling"
and (under == "ethereal:prairie_dirt" or ok) then ethereal.grow_orange_tree(pos)
elseif node.name == "ethereal:bamboo_sprout"
and (under == "ethereal:bamboo_dirt" or ok) then ethereal.grow_bamboo_tree(pos)
elseif node.name == "ethereal:birch_sapling"
and (under == "default:dirt_with_grass" or ok) then ethereal.grow_birch_tree(pos)
elseif node.name == "ethereal:sakura_sapling"
and (under == "ethereal:bamboo_dirt" or ok) then ethereal.grow_sakura_tree(pos)
elseif node.name == "ethereal:olive_tree_sapling"
and (under == "ethereal:grove_dirt" or ok) then ethereal.grow_olive_tree(pos)
elseif node.name == "ethereal:mangrove_sapling"
and (under == "ethereal:mud" or ok) then ethereal.grow_mangrove_tree(pos)
elseif node.name == "ethereal:lemon_tree_sapling"
and (under == "ethereal:grove_dirt" or ok) then ethereal.grow_lemon_tree(pos) end
end
-- grow saplings Abm
core.register_abm({
label = "Ethereal grow sapling",
nodenames = {"group:ethereal_sapling"},
interval = 10,
chance = 50,
catch_up = false,
action = ethereal.grow_sapling
})
-- 2x redwood saplings make 1x giant redwood sapling
core.register_craft({
output = "ethereal:giant_redwood_sapling",
recipe = {{"ethereal:redwood_sapling", "ethereal:redwood_sapling"}}
})