-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua~
More file actions
426 lines (386 loc) · 10.9 KB
/
init.lua~
File metadata and controls
426 lines (386 loc) · 10.9 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
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
423
424
425
426
--[[
Weed mod (based on wheat and baking mods)
VERSION: 0.0.2
LICENSE: GPLv3
TODO:
]]
PLANTS_GROW_INTERVAL = 80 -- interval in ABMs for plants
PLANTS_GROW_CHANCE = 60 -- chance in ABMs for plants
PLANTS_VISUAL_SCALE = 1.19 -- visualscale for plants
local weed_STATES = {
'1',
'2',
'3',
'4',
'5',
'6',
'7',
--'final',
}
NODES_TO_DELETE_IF_THEY_ABOVE_AIR = {
"weed:weed_1",
"weed:weed_2",
"weed:weed_3",
"weed:weed_4",
"weed:weed_5",
"weed:weed_6",
"weed:weed_7",
"weed:weed_final",
"weed:big_grass",
}
local DIRT_BED_TO_GRASS = {
"weed:weed_1",
"weed:weed_2",
"weed:weed_3",
"weed:weed_4",
"weed:weed_5",
"weed:weed_6",
"weed:weed_7",
"weed:weed_final",
}
local LIGHT = 5 -- amount of light neded to weed grow
local check_water = function(pos)
--[[for x = pos.x - 2, pos.x + 2 do
for x = pos.z - 2, pos.z + 2 do
n = minetest.env:get_node_or_nil({x = x, pos.z, z = z})
if (n == nil) or (n.name == "default:water_source") or (n.name == "default:water_flowing") then
return true
end
end
end]]
return true
end
-- ABMs
minetest.register_abm({
nodenames = {"weed:weed_1","weed:weed_2","weed:weed_3","weed:weed_4",
"weed:weed_5","weed:weed_6","weed:weed_7"},
interval = PLANTS_GROW_INTERVAL/3*2,
chance = PLANTS_GROW_CHANCE/2,
action = function(pos, node, _, __)
local l = minetest.env:get_node_light(pos, nil)
local p = pos
local rnd = math.random(1, 3)
p.y = p.y - 1 -- it will change pos too, that cause using p.y = p.y + 1
local under_node = minetest.env:get_node(p)
if (l >= LIGHT) and (under_node.name == "weed:dirt_bed") and (rnd == 1) then
local nname --= 'weed:weed_final'
if node.name == "weed:weed_1" then
nname = 'weed:weed_2'
elseif node.name == "weed:weed_2" then
nname = 'weed:weed_3'
elseif node.name == 'weed:weed_3' then
nname = 'weed:weed_4'
elseif node.name == 'weed:weed_4' then
nname = 'weed:weed_5'
elseif node.name == 'weed:weed_5' then
nname = 'weed:weed_6'
elseif node.name == 'weed:weed_6' then
nname = 'weed:weed_7'
else nname = 'weed:weed_final' end
p.y = p.y + 1
minetest.env:remove_node(pos)
minetest.env:add_node(pos, { name = nname })
end
end
})
minetest.register_abm({
nodenames = NODES_TO_DELETE_IF_THEY_ABOVE_AIR,
interval = 3,
chance = 1,
action = function(pos, node, _, __)
local p = {x = pos.x,y = pos.y -1,z = pos.z}
--p.y = p.y - 1 -- it will change pos too, that cause using p.y = p.y + 1
local under_node = minetest.env:get_node(p)
if (under_node.name == "air") then
--p.y = p.y + 1
minetest.env:remove_node(pos)
minetest.env:add_node(p, {name = node.name})
end
end
})
minetest.register_abm({
nodenames = "weed:dirt_bed",
interval = 40,
chance = 3,
action = function(pos, node, _, __)
local p = {x = pos.x,y = pos.y +1,z = pos.z}
local above_node = minetest.env:get_node(p)
for i, plant in ipairs(DIRT_BED_TO_GRASS) do
if (above_node.name == plant) then return; end
end
minetest.env:remove_node(pos)
minetest.env:add_node(pos, {name = "weed:dirt_bed"})
end
})-- ABMs end
-- Nodes
for i, state in ipairs(weed_STATES) do
minetest.register_node("weed:weed_" .. state, {
drawtype = "plantlike",
tile_images = {"weed_weed_" .. state .. ".png"},
inventory_image = "weed_weed_" .. state .. ".png",
paramtype = "light",
is_ground_content = true,
walkable = false,
groups = {dig_immediate=3,choppy=3},
drop = {
items = {
{
items = {'weed:weed_nug'},
rarity = 10,
},
},
},
wall_mounted = false,
visual_scale = PLANTS_VISUAL_SCALE,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -0.4, 1/2},
},
})
-- Fuel
minetest.register_craft({
type = "fuel",
recipe = "weed:weed_" .. state,
burntime = 2,
})
end
minetest.register_node("weed:weed_final", {
drawtype = "plantlike",
tile_images = {"weed_weed_final.png"},
inventory_image = "weed_weed_final.png",
paramtype = "light",
is_ground_content = true,
walkable = false,
groups = {dig_immediate=3,choppy=3},
drop = {
max_items = 1,
items = {
{
items = {'weed:weed_nug 10'},
rarity = 1.5,
},
{
items = {'weed:weed_nug'},
}
}
},
wall_mounted = false,
visual_scale = PLANTS_VISUAL_SCALE,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -0.4, 1/2},
},
})
minetest.register_node("weed:dirt_bed", {
description = "Weed dirt bed",
tile_images = {"weed_bed.png", "default_dirt.png"},
inventory_image = minetest.inventorycube("default_dirt.png"),
is_ground_content = true,
groups = {crumbly=3},
drop = {
max_items = 1,
items = {
{
items = {'default:dirt'},
}
}
},
})
minetest.register_node("weed:big_grass", {
drawtype = "plantlike",
paramtype = "facedir_simple",
tile_images = {"weed_weed_final.png"},
inventory_image = "weed_weed_final.png",
paramtype = "light",
is_ground_content = true,
walkable = false,
groups = {dig_immediate=3,choppy=3},
drop = {
max_items = 1,
items = {
{
items = {'weed:weed_nug'},
rarity = 10,
},
},
},
visual_scale = PLANTS_VISUAL_SCALE,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -0.3, 1/2},
},
})-- Nodes end
minetest.register_node("weed:wild_grass", {
drawtype = "plantlike",
paramtype = "facedir_simple",
tile_images = {"weed_weed_4.png"},
inventory_image = "weed_weed_4.png",
paramtype = "light",
is_ground_content = true,
walkable = false,
groups = {dig_immediate=3,choppy=3},
drop = {
max_items = 1,
items = {
{
items = {'weed:weed_nug'},
rarity = 10,
},
},
},
visual_scale = PLANTS_VISUAL_SCALE,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -0.3, 1/2},
},
})-- Nodes end
-- Craftitems
minetest.register_craftitem("weed:weed_nug", {
description = "weed nug (and seeds)",
image = "weed_weed_nug.png",
stack_max = 99,
usable = true,
dropcount = 10,
liquids_pointable = false,
on_place = minetest.item_place,
on_use = function(item, player, pointed_thing)
if pointed_thing.type == "node" then
n = minetest.env:get_node(pointed_thing.under)
if n.name == "weed:dirt_bed" then
minetest.env:add_node(pointed_thing.above, {name="weed:weed_1"})
item:take_item()
end
end
return item
end,
}) -- Craftitems end
-- Fuel
minetest.register_craft({
type = "fuel",
recipe = "weed:weed_nug",
burntime = 1,
})
minetest.register_craft({
type = "fuel",
recipe = "weed:big_grass",
burntime = 2,
})
minetest.register_craft({
type = "fuel",
recipe = "weed:weed_final",
burntime = 2,
})
minetest.register_craft({ --TODO: find a better recipe
output = 'node "weed:dirt_bed" 2',
recipe = {
{'node "default:dirt" 1', 'node "default:sand" 1', 'node "default:dirt" 1'},
},
})
------
minetest.register_craftitem("weed:flour", {
image = "weed_flour.png",
on_place = minetest.item_place
})
minetest.register_craftitem("weed:brownie", {
image = "weed_brownie.png",
on_place = minetest.item_place,
on_use = minetest.item_eat(9)
})
minetest.register_craftitem("weed:weed_cigarette", {
image = "cigarette.png",
on_place = minetest.item_place,
on_use = minetest.item_eat(1)
})
minetest.register_craftitem("weed:brownie_dough", {
image = "weed_brownie_dough.png",
on_place = minetest.item_place,
})
minetest.register_craft({
output = 'weed:flour 1',
recipe = {
{'weed:weed_nug', 'weed:weed_nug'},
{'weed:weed_nug', 'weed:weed_nug'},
}
})
minetest.register_craft({
output = 'weed:brownie_dough 1',
recipe = {
{'weed:flour', 'weed:flour', 'weed:flour'},
{'weed:flour', 'weed:weed_form_water', 'weed:flour'},
{'weed:flour', 'weed:flour', 'weed:flour'},
}
})
minetest.register_craft({
output = 'weed:weed_form_empty 1',
recipe = {
{'default:wood', '', 'default:wood'},
{'', 'default:wood', ''},
}
})
minetest.register_craft({
output = 'weed:weed_cigarette',
recipe = {
{'default:paper'},
{'weed:weed_nug'},
}
})
minetest.register_craftitem("weed:weed_form_empty", {
description = "Empty weed form",
image = "weed_weed_form.png",
stack_max = 1,
liquids_pointable = true,
on_place = minetest.item_place,
on_use = function(item, player, pointed_thing)
if pointed_thing.type == "node" then
n = minetest.env:get_node(pointed_thing.under)
if n.name == "default:water_source" then
minetest.env:add_node(pointed_thing.under, {name="air"})
local leftover = player:get_inventory():add_item("main", ItemStack('weed:weed_form_water 1'))
if leftover:is_empty() then
item:take_item()
else
minetest.chat_send_player(player:get_player_name(), 'Not enough space in inventory!')
end
end
end
return item
end,
})
minetest.register_craftitem("weed:weed_form_water", {
description = "weed form with water",
image = "weed_weed_form_water.png",
stack_max = 1,
liquids_pointable = true,
on_place = minetest.item_place,
on_use = function(item, player, pointed_thing)
if pointed_thing.type == "node" then
n = minetest.env:get_node(pointed_thing.under)
if n.name == "default:water_source" then
-- unchanged
elseif n.name == "default:lava_source" or n.name == "default:lava_flowing" then
minetest.env:add_node(pointed_thing.under, {name="default:cobble"})
else
minetest.env:add_node(pointed_thing.above, {name="default:water_flowing"})
end
local leftover = player:get_inventory():add_item("main", ItemStack('weed:weed_form_empty 1'))
if leftover:is_empty() then
item:take_item()
else
minetest.chat_send_player(player:get_player_name(), 'Not enough space in inventory!')
end
end
return item
end,
})
minetest.register_craft({
type = "cooking",
output = "weed:brownie",
recipe = "weed:brownie_dough",
cooktime = 10,
replacements = {
{"weed:brownie_dough", "weed:weed_form_empty"}, --- this is not work!!!
},
})
spawn_on_surfaces(GROWING_DELAY/2, "weed:wild_grass", 40, 20, "default:dirt_with_grass")
spawn_on_surfaces(GROWING_DELAY/2, "weed:wild_grass", 10, 2, "default:dirt_with_grass")
print("[weed mod] Loaded!")