/
i_bonemeal_override.lua
422 lines (329 loc) · 10.5 KB
/
i_bonemeal_override.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
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
--[[The MIT License (MIT)
Copyright (c) 2016 TenPlus1
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.]]
local min, max, random = math.min, math.max, math.random
-- default crops
local crops = {
{"farming:cotton_", 8, "farming:seed_cotton"},
{"farming:wheat_", 8, "farming:seed_wheat"}
}
-- special pine check for nearby snow
local function pine_grow(pos)
if minetest.find_node_near(pos, 1,
{"default:snow", "default:snowblock", "default:dirt_with_snow"}) then
default.grow_new_snowy_pine_tree(pos)
else
default.grow_new_pine_tree(pos)
end
end
-- special function for cactus growth
local function cactus_grow(pos)
default.grow_cactus(pos, minetest.get_node(pos))
end
-- special function for papyrus growth
local function papyrus_grow(pos)
default.grow_papyrus(pos, minetest.get_node(pos))
end
-- default saplings
local saplings = {
{"default:sapling", default.grow_new_apple_tree, "soil"},
{"default:junglesapling", default.grow_new_jungle_tree, "soil"},
{"default:emergent_jungle_sapling", default.grow_new_emergent_jungle_tree, "soil"},
{"default:acacia_sapling", default.grow_new_acacia_tree, "soil"},
{"default:aspen_sapling", default.grow_new_aspen_tree, "soil"},
{"default:pine_sapling", pine_grow, "soil"},
{"default:bush_sapling", default.grow_bush, "soil"},
{"default:acacia_bush_sapling", default.grow_acacia_bush, "soil"},
{"default:large_cactus_seedling", default.grow_large_cactus, "sand"},
{"default:blueberry_bush_sapling", default.grow_blueberry_bush, "soil"},
{"default:pine_bush_sapling", default.grow_pine_bush, "soil"},
{"default:cactus", cactus_grow, "sand"},
{"default:papyrus", papyrus_grow, "soil"}
}
-- helper tables ( "" denotes a blank item )
local green_grass = {
"default:grass_2", "default:grass_3", "default:grass_4",
"default:grass_5", "", ""
}
local dry_grass = {
"default:dry_grass_2", "default:dry_grass_3", "default:dry_grass_4",
"default:dry_grass_5", "", ""
}
-- loads mods then add all in-game flowers except waterlily
local flowers = {}
minetest.after(0.1, function()
for node, def in pairs(minetest.registered_nodes) do
if def.groups
and def.groups.flower
and not node:find("waterlily")
and not node:find("xdecor:potted_") then
flowers[#flowers + 1] = node
end
end
end)
-- default biomes deco
local deco = {
{"default:dry_dirt", dry_grass, {}},
{"default:dry_dirt_with_dry_grass", dry_grass, {}},
{"default:dirt_with_dry_grass", dry_grass, flowers},
{"default:sand", {}, {"default:dry_shrub", "", "", ""} },
{"default:desert_sand", {}, {"default:dry_shrub", "", "", ""} },
{"default:silver_sand", {}, {"default:dry_shrub", "", "", ""} },
{"default:dirt_with_rainforest_litter", {}, {"default:junglegrass", "", "", ""}}
}
--
-- local functions
--
-- particles
local function particle_effect(pos)
minetest.add_particlespawner({
amount = 4,
time = 0.15,
minpos = pos,
maxpos = pos,
minvel = {x = -1, y = 2, z = -1},
maxvel = {x = 1, y = 4, z = 1},
minacc = {x = -1, y = -1, z = -1},
maxacc = {x = 1, y = 1, z = 1},
minexptime = 1,
maxexptime = 1,
minsize = 1,
maxsize = 3,
texture = "bonemeal_particle.png"
})
end
-- tree type check
local function grow_tree(pos, object)
if type(object) == "table" and object.axiom then
-- grow L-system tree
minetest.remove_node(pos)
minetest.spawn_tree(pos, object)
elseif type(object) == "string" and minetest.registered_nodes[object] then
-- place node
minetest.set_node(pos, {name = object})
elseif type(object) == "function" then
-- function
object(pos)
end
end
-- sapling check
local function check_sapling(pos, nodename)
-- what is sapling placed on?
local under = minetest.get_node({
x = pos.x,
y = pos.y - 1,
z = pos.z
})
local can_grow, grow_on
-- check list for sapling and function
for n = 1, #saplings do
if saplings[n][1] == nodename then
grow_on = saplings[n][3]
-- sapling grows on top of specific node
if grow_on
and grow_on ~= "soil"
and grow_on ~= "sand"
and grow_on == under.name then
can_grow = true
end
-- sapling grows on top of soil (default)
if can_grow == nil
and (grow_on == nil or grow_on == "soil")
and minetest.get_item_group(under.name, "soil") > 0 then
can_grow = true
end
-- sapling grows on top of sand
if can_grow == nil
and grow_on == "sand"
and minetest.get_item_group(under.name, "sand") > 0 then
can_grow = true
end
-- check if we can grow sapling
if can_grow then
particle_effect(pos)
grow_tree(pos, saplings[n][2])
return true
end
end
end
end
-- crops check
local function check_crops(pos, nodename, strength)
local mod, crop, stage, nod, def
-- grow registered crops
for n = 1, #crops do
if nodename:find(crops[n][1])
or nodename == crops[n][3] then
-- separate mod and node name
mod = nodename:split(":")[1] .. ":"
crop = nodename:split(":")[2]
-- get stage number or set to 0 for seed
stage = tonumber( crop:split("_")[2] ) or 0
stage = min(stage + strength, crops[n][2])
-- check for place_param setting
nod = crops[n][1] .. stage
def = minetest.registered_nodes[nod]
def = def and def.place_param2 or 0
minetest.set_node(pos, {name = nod, param2 = def})
particle_effect(pos)
return true
end
end
end
-- check soil for specific decoration placement
local function check_soil(pos, nodename, strength)
-- set radius according to strength
local side = strength - 1
local tall = max(strength - 2, 0)
local floor
local groups = minetest.registered_items[nodename]
and minetest.registered_items[nodename].groups or {}
-- only place decoration on one type of surface
if groups.soil then
floor = {"group:soil"}
elseif groups.sand then
floor = {"group:sand"}
else
floor = {nodename}
end
-- get area of land with free space above
local dirt = minetest.find_nodes_in_area_under_air(
{x = pos.x - side, y = pos.y - tall, z = pos.z - side},
{x = pos.x + side, y = pos.y + tall, z = pos.z + side}, floor)
-- set default grass and decoration
local grass = green_grass
local decor = flowers
-- choose grass and decoration to use on dirt patch
for n = 1, #deco do
-- do we have a grass match?
if nodename == deco[n][1] then
grass = deco[n][2] or {}
decor = deco[n][3] or {}
end
end
local pos2, nod, def
-- loop through soil
for _, n in pairs(dirt) do
if random(5) == 5 and 1 == 2 then -- flowers_nt add 1==2 stop flowers from being placed
if decor and #decor > 0 then
-- place random decoration (rare)
local dnum = #decor or 1
nod = decor[random(dnum)] or ""
end
else
if grass and #grass > 0 then
-- place random grass (common)
local dgra = #grass or 1
nod = #grass > 0 and grass[random(dgra)] or ""
end
end
pos2 = n
pos2.y = pos2.y + 1
if nod and nod ~= "" then
-- get crop param2 value
def = minetest.registered_nodes[nod]
def = def and def.place_param2
-- if param2 not preset then get from existing node
if not def then
local node = minetest.get_node_or_nil(pos2)
def = node and node.param2 or 0
end
minetest.set_node(pos2, {name = nod, param2 = def})
end
particle_effect(pos2)
end
end
-- global on_use function for bonemeal
function bonemeal:on_use(pos, strength, node)
-- get node pointed at
local node = node or minetest.get_node(pos)
-- return if nothing there
if node.name == "ignore" then
return
end
-- make sure strength is between 1 and 4
strength = strength or 1
strength = max(strength, 1)
strength = min(strength, 4)
-- papyrus and cactus
if node.name == "default:papyrus" then
default.grow_papyrus(pos, node)
particle_effect(pos)
return true
elseif node.name == "default:cactus" then
default.grow_cactus(pos, node)
particle_effect(pos)
return true
end
-------------------------
-- flowers_nt addition --
-------------------------
local flowers_nt_node = false
local fnt_reg_name
for reg_name, def in pairs(flowers_nt.registered_flowers) do
local sub_name = string.sub(node.name, 0, -3)
if reg_name == sub_name then
flowers_nt_node = true
fnt_reg_name = sub_name
break
elseif reg_name == node.name then
flowers_nt_node = true
fnt_reg_name = def.parent
break
end
end
if flowers_nt_node == true then
local meta = minetest.get_meta(pos)
local flowers_met = meta:get_int("flowers_nt")
local is_grow = flowers_nt.allowed_to_grow(pos)
if is_grow and flowers_met == 0 then
local light_min = flowers_nt.registered_flowers[fnt_reg_name].light_min
-- light check depending on strength, sub in flower light_min
if (minetest.get_node_light(pos) or 0) < (light_min - (strength * 3)) then
return
end
flowers_nt.set_grow_stage(pos)
particle_effect(pos)
return true
end
end
-----------------------------
-- end flowers_nt addition --
-----------------------------
-- grow grass and flowers
if minetest.get_item_group(node.name, "soil") > 0
or minetest.get_item_group(node.name, "sand") > 0
or minetest.get_item_group(node.name, "can_bonemeal") > 0 then
check_soil(pos, node.name, strength)
return true
end
-- light check depending on strength (strength of 4 = no light needed)
if (minetest.get_node_light(pos) or 0) < (12 - (strength * 3)) then
return
end
-- check for tree growth if pointing at sapling
if (minetest.get_item_group(node.name, "sapling") > 0
or node.name == "default:large_cactus_seedling")
and random(5 - strength) == 1 then
check_sapling(pos, node.name)
return true
end
-- check for crop growth
if check_crops(pos, node.name, strength) then
return true
end
end