Merge pull request #3 from Athemis/master
[MineClone.git] / mods / farming / init.lua
blob63974dae474ee5ecb8b864daaa0d66cad505d73d
1 local init = os.clock()
2 farming = {}
4 function farming:add_plant(full_grown, names, interval, chance)
5 minetest.register_abm({
6 nodenames = names,
7 interval = interval,
8 chance = chance,
9 action = function(pos, node)
10 pos.y = pos.y-1
11 if minetest.env:get_node(pos).name ~= "farming:soil_wet" and math.random(0, 9) > 0 then
12 return
13 end
14 pos.y = pos.y+1
15 if not minetest.env:get_node_light(pos) then
16 return
17 end
18 if minetest.env:get_node_light(pos) < 10 then
19 return
20 end
21 local step = nil
22 for i,name in ipairs(names) do
23 if name == node.name then
24 step = i
25 break
26 end
27 end
28 if step == nil then
29 return
30 end
31 local new_node = {name=names[step+1]}
32 if new_node.name == nil then
33 new_node.name = full_grown
34 end
35 minetest.env:set_node(pos, new_node)
36 end
37 } )
38 end
41 function farming:place_seed(itemstack, placer, pointed_thing, plantname)
42 local pt = pointed_thing
43 if not pt then
44 return
45 end
46 if pt.type ~= "node" then
47 return
48 end
50 local pos = {x=pt.above.x, y=pt.above.y-1, z=pt.above.z}
51 local farmland = minetest.env:get_node(pos)
52 pos= {x=pt.above.x, y=pt.above.y, z=pt.above.z}
53 local place_s = minetest.env:get_node(pos)
56 if string.find(farmland.name, "farming:soil") and string.find(place_s.name, "air") then
57 minetest.env:add_node(pos, {name=plantname})
58 else
59 return
60 end
62 if not minetest.setting_getbool("creative_mode") then
63 itemstack:take_item()
64 end
65 return itemstack
66 end
70 -- ========= SOIL =========
71 dofile(minetest.get_modpath("farming").."/soil.lua")
73 -- ========= HOES =========
74 dofile(minetest.get_modpath("farming").."/hoes.lua")
76 -- ========= WHEAT =========
77 dofile(minetest.get_modpath("farming").."/wheat.lua")
79 -- ========= PUMPKIN =========
80 dofile(minetest.get_modpath("farming").."/pumpkin.lua")
82 -- ========= MELON =========
83 dofile(minetest.get_modpath("farming").."/melon.lua")
85 -- ========= CARROT =========
86 dofile(minetest.get_modpath("farming").."/carrots.lua")
88 -- ========= POTATOES =========
89 dofile(minetest.get_modpath("farming").."/potatoes.lua")
91 -- ========= MUSHROOMS =========
92 dofile(minetest.get_modpath("farming").."/mushrooms.lua")
94 local time_to_load= os.clock() - init
95 print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))