2015-07-03 04:58:01 +00:00
|
|
|
local init = os.clock()
|
2017-01-31 11:35:59 +00:00
|
|
|
mcl_farming = {}
|
2015-06-29 17:55:56 +00:00
|
|
|
|
2017-01-31 11:35:59 +00:00
|
|
|
function mcl_farming:add_plant(full_grown, names, interval, chance)
|
2015-06-29 17:55:56 +00:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = names,
|
|
|
|
interval = interval,
|
|
|
|
chance = chance,
|
|
|
|
action = function(pos, node)
|
|
|
|
pos.y = pos.y-1
|
2017-01-31 11:35:59 +00:00
|
|
|
if minetest.get_node(pos).name ~= "mcl_farming:soil_wet" and math.random(0, 9) > 0 then
|
2015-06-29 17:55:56 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
pos.y = pos.y+1
|
2017-01-11 17:21:46 +00:00
|
|
|
if not minetest.get_node_light(pos) then
|
2015-06-29 17:55:56 +00:00
|
|
|
return
|
|
|
|
end
|
2017-01-11 17:21:46 +00:00
|
|
|
if minetest.get_node_light(pos) < 10 then
|
2015-06-29 17:55:56 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local step = nil
|
|
|
|
for i,name in ipairs(names) do
|
|
|
|
if name == node.name then
|
|
|
|
step = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if step == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local new_node = {name=names[step+1]}
|
|
|
|
if new_node.name == nil then
|
|
|
|
new_node.name = full_grown
|
|
|
|
end
|
2017-01-11 17:21:46 +00:00
|
|
|
minetest.set_node(pos, new_node)
|
2015-06-29 17:55:56 +00:00
|
|
|
end
|
|
|
|
} )
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-01-31 11:35:59 +00:00
|
|
|
function mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname)
|
2015-06-29 17:55:56 +00:00
|
|
|
local pt = pointed_thing
|
|
|
|
if not pt then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if pt.type ~= "node" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local pos = {x=pt.above.x, y=pt.above.y-1, z=pt.above.z}
|
2017-01-11 17:21:46 +00:00
|
|
|
local farmland = minetest.get_node(pos)
|
2015-06-29 17:55:56 +00:00
|
|
|
pos= {x=pt.above.x, y=pt.above.y, z=pt.above.z}
|
2017-01-11 17:21:46 +00:00
|
|
|
local place_s = minetest.get_node(pos)
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
|
2017-01-31 11:35:59 +00:00
|
|
|
if string.find(farmland.name, "mcl_farming:soil") and string.find(place_s.name, "air") then
|
2017-01-11 17:21:46 +00:00
|
|
|
minetest.add_node(pos, {name=plantname})
|
2015-06-29 17:55:56 +00:00
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ========= SOIL =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/soil.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
-- ========= HOES =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/hoes.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
-- ========= WHEAT =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/wheat.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
-- ========= PUMPKIN =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/pumpkin.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
-- ========= MELON =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/melon.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
-- ========= CARROT =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/carrots.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
-- ========= POTATOES =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/potatoes.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
|
|
|
-- ========= MUSHROOMS =========
|
2017-01-31 11:35:59 +00:00
|
|
|
dofile(minetest.get_modpath("mcl_farming").."/mushrooms.lua")
|
2015-06-29 17:55:56 +00:00
|
|
|
|
2017-02-01 12:27:49 +00:00
|
|
|
-- ========= BEETROOT =========
|
|
|
|
-- TODO: Add beetroot textures
|
|
|
|
--dofile(minetest.get_modpath("mcl_farming").."/beetroot.lua")
|
|
|
|
|
2015-07-03 04:58:01 +00:00
|
|
|
local time_to_load= os.clock() - init
|
|
|
|
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))
|