2023-02-01 20:39:37 +01:00
|
|
|
--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
|
|
|
|
----------------------------------------------
|
2023-02-03 14:33:47 +01:00
|
|
|
--can plant plant in pos
|
|
|
|
function owl_tech.can_plant_plant(pos)
|
2023-02-01 20:39:37 +01:00
|
|
|
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
|
2023-02-03 14:33:47 +01:00
|
|
|
----------------------------------------------
|
|
|
|
--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
|
2023-02-01 20:39:37 +01:00
|
|
|
-----------------------------------------------
|
2023-02-03 14:33:47 +01:00
|
|
|
--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
|
2023-02-04 18:50:53 +01:00
|
|
|
-----------------------------------------------
|
2023-02-03 14:33:47 +01:00
|
|
|
--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
|
2023-02-04 18:50:53 +01:00
|
|
|
minetest.set_node({x=pos.x+i,y=pos.y+1,z=pos.z+j}, {name=fluid_its:get_name()})
|
2023-02-03 14:33:47 +01:00
|
|
|
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)
|
2023-02-04 18:50:53 +01:00
|
|
|
return -- plant 1 plant for each( if plant vore - hase bug1)
|
2023-02-03 14:33:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
------------------------------------------------
|
2023-02-04 18:50:53 +01:00
|
|
|
--get wood or leavs in slot
|
|
|
|
function owl_tech.get_wood_or_leaves(pos,inv,wood_its,leaves_its)
|
|
|
|
if owl_tech.is_wood_in_pos(pos)
|
|
|
|
and (minetest.get_node(pos).name== wood_its:get_name() or wood_its:is_empty())
|
|
|
|
and wood_its:get_count()<64 then
|
|
|
|
local cut_wood = minetest.get_node(pos).name
|
|
|
|
if not wood_its:is_empty() then-- Add main output
|
|
|
|
wood_its:set_count(wood_its:get_count()+1)
|
|
|
|
inv:set_stack('wood', 1, wood_its)
|
|
|
|
else
|
|
|
|
local item ={name=cut_wood, count=1, wear=0, metadata=""}
|
|
|
|
wood_its:add_item(item)
|
|
|
|
inv:set_stack('wood', 1, wood_its)
|
|
|
|
end
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end
|
|
|
|
if owl_tech.is_leaf_in_pos(pos)
|
|
|
|
and( minetest.get_node(pos).name== leaves_its:get_name() or leaves_its:is_empty())
|
|
|
|
and leaves_its:get_count()<64 then
|
|
|
|
local cut_leaf = minetest.get_node(pos).name
|
|
|
|
if not leaves_its:is_empty() then-- Add main output
|
|
|
|
leaves_its:set_count(leaves_its:get_count()+1)
|
|
|
|
inv:set_stack('leaves', 1, leaves_its)
|
|
|
|
else
|
|
|
|
local item ={name=cut_leaf, count=1, wear=0, metadata=""}
|
|
|
|
leaves_its:add_item(item)
|
|
|
|
inv:set_stack('leaves', 1, leaves_its)
|
|
|
|
end
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
------------------------------------------------
|
|
|
|
--looking frp trees
|
|
|
|
function owl_tech:look_for_trees(pos)
|
|
|
|
local meta =minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local wood_its = inv:get_stack('wood', 1)
|
|
|
|
local leaves_its = inv:get_stack('leaves', 1)
|
|
|
|
local rotation = minetest.get_node(pos).param2 % 32 --get rotattion ( return int )
|
|
|
|
if wood_its:is_empty()or (wood_its:get_count()<64) and leaves_its:is_empty()or (leaves_its:get_count()<64) then
|
|
|
|
if rotation==0 then --z-1
|
|
|
|
for i = (meta:get_int("distance")*-1), meta:get_int("distance"), 1 do--x
|
|
|
|
for j = 1,(meta:get_int("distance")*2)+1, 1 do--z
|
|
|
|
for k = 32,0, -1 do--y
|
|
|
|
owl_tech.get_wood_or_leaves({x=pos.x+i,y=pos.y+k,z=pos.z-j},inv,wood_its,leaves_its)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if rotation==2 then --z+1
|
|
|
|
for i = (meta:get_int("distance")*-1), meta:get_int("distance"), 1 do--x
|
|
|
|
for j = 1,(meta:get_int("distance")*2)+1, 1 do--z
|
|
|
|
for k =32,0, -1 do--y
|
|
|
|
owl_tech.get_wood_or_leaves({x=pos.x+i,y=pos.y+k,z=pos.z+j},inv,wood_its,leaves_its)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if rotation==0 then --x-1
|
|
|
|
for i = 1,(meta:get_int("distance")*2)+1, 1 do--x
|
|
|
|
for j = (meta:get_int("distance")*-1), meta:get_int("distance"), 1 do--z
|
|
|
|
for k = 32 ,0, -1 do--y
|
|
|
|
owl_tech.get_wood_or_leaves({x=pos.x-i,y=pos.y+k,z=pos.z+j},inv,wood_its,leaves_its)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if rotation==1 then --x+1
|
|
|
|
for i = 1,(meta:get_int("distance")*2)+1, 1 do--x
|
|
|
|
for j = (meta:get_int("distance")*-1), meta:get_int("distance"), 1 do--z
|
|
|
|
for k = 32,0,-1 do--y
|
|
|
|
owl_tech.get_wood_or_leaves({x=pos.x+i,y=pos.y+k,z=pos.z+j},inv,wood_its,leaves_its)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|