owl_tech/api/farming.lua

68 lines
2.4 KiB
Lua

--Is wood in pos
function owl_tech.is_wood_in_pos(pos)
if minetest.get_item_group((minetest.get_node(pos)).name,"tree")>0 then
return true
end
return false
end
---------------------------------------------
--Is leaves in pos
function owl_tech.is_leaf_in_pos(pos)
if minetest.get_item_group((minetest.get_node(pos)).name,"leaves")>0 then
return true
end
return false
end
-------------------------------------------------
--is sapling in pos
function owl_tech.is_sapling(pos)
if minetest.get_item_group((minetest.get_node(pos)).name,"sapling")>0 then
return true
end
return false
end
----------------------------------------------
--can plant plant in pos
function owl_tech.can_plant_plant(pos)
if (minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})).name== "mcl_farming:soil_wet"then
return true
end
return false
end
----------------------------------------------
--can plant plant in pos
function owl_tech.can_plant_sapling(pos)
if minetest.get_item_group(minetest.get_node(pos).name,"soil_sapling")>1
and minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name =="air" then
return true
end
return false
end
-----------------------------------------------
--prepear for plant sampling
function owl_tech.prepear_for_sapling_plant(pos,distance)
local meta= minetest.get_meta(pos)
meta:set_int("distance",distance)
end
----------------------------------------------
--looking for new sapling
function owl_tech.look_for_place_new_sapling(pos)
local meta= minetest.get_meta(pos)
local inv = meta:get_inventory()
local fluid_its = inv:get_stack('sapling', 1)
for i = (meta:get_int("distance")*-1), meta:get_int("distance"), 1 do--x
for j = (meta:get_int("distance")*-1), meta:get_int("distance"), 1 do--z
if owl_tech.can_plant_sapling({x=pos.x+i,y=pos.y,z=pos.z+j}) and fluid_its:get_count()>0
and not fluid_its:is_empty() then
minetest.place_node({x=pos.x+i,y=pos.y+1,z=pos.z+j}, {name=fluid_its:get_name()})
local inv=meta:get_inventory()
local fluid_its = inv:get_stack('sapling', 1)
fluid_its:set_count(fluid_its:get_count()-1)
inv:set_stack('sapling', 1, fluid_its)
return -- plant 1 plant for each( if plant vore - hase bug)
end
end
end
end
------------------------------------------------