local S = minetest.get_translator(minetest.get_current_modname()) local name = minetest.get_current_modname() local path = minetest.get_modpath(name) local function set_crops_in_meta_name(meta,name) if meta:get_string("crop1")=='none' then meta:set_string("crop1",name) do return end elseif meta:get_string("crop2")=='none' then meta:set_string("crop1",name) do return end end end --Crops minetest.register_node("owl_tech:crops",{ description = "Crops", _tt_help = S("Crops for grow crops"), _doc_items_longdesc = S("Fence gates can be opened or closed and can't be jumped over. Fences will connect nicely to fence gates."), _doc_items_usagehelp = S("Right-click the fcrops to put a seed and begin grow"), tiles = {"mcl_core_log_big_oak.png"}, paramtype = "light", is_ground_content = false, stack_max = 64, sunlight_propagates = true, walkable = true, groups = {owl_tech_fluid_pipe=1}, drawtype = "nodebox", node_box = { type = "fixed", fixed ={{-0.45,-0.5,-0.45,-0.4,0.5,-0.4}, {-0.45,-0.5,-0.45,-0.4,0.5,-0.4}, {-0.45,-0.5,0.45,-0.4,0.5,0.4}, {0.45,-0.5,0.45,0.4,0.5,0.4} }, }, sounds = mcl_sounds.node_sound_wool_defaults(), _mcl_hardness = 0.1, _mcl_blast_resistance = 0.1, on_construct = function(pos) local meta = minetest.get_meta(pos) meta:set_string("infotext", "crops") meta:set_int("state",0) meta:set_string("pos-x", 'none') meta:set_string("pos+x", 'none') meta:set_string("pos-z", 'none') meta:set_string("pos+z", 'none') meta:set_string("crop1", 'none') meta:set_string("crop2", 'none') local timer =minetest.get_node_timer(pos) timer:start(0.2) end, on_timer = function (pos, elapsed) local meta = minetest.get_meta(pos) local timer =minetest.get_node_timer(pos) local get_two_seed_around = 0 if meta:get_int("look_around")==0 then for i = 1, #LIST_ALL_CROPS ,1 do if minetest.get_node({x=pos.x-1 ,y=pos.y,z=pos.z}).name == LIST_ALL_CROPS[i] then meta:set_string("pos-x",minetest.get_node({x=pos.x-1 ,y=pos.y,z=pos.z}).name) get_two_seed_around = get_two_seed_around + 1 end if minetest.get_node({x=pos.x+1 ,y=pos.y,z=pos.z}).name == LIST_ALL_CROPS[i] then meta:set_string("pos+x",minetest.get_node({x=pos.x+1 ,y=pos.y,z=pos.z}).name) get_two_seed_around = get_two_seed_around + 1 end if minetest.get_node({x=pos.x ,y=pos.y,z=pos.z-1}).name == LIST_ALL_CROPS[i] then meta:set_string("pos-z",minetest.get_node({x=pos.x ,y=pos.y,z=pos.z-1}).name) get_two_seed_around = get_two_seed_around + 1 end if minetest.get_node({x=pos.x ,y=pos.y,z=pos.z+1}).name == LIST_ALL_CROPS[i] then meta:set_string("pos+z",minetest.get_node({x=pos.x ,y=pos.y,z=pos.z+1}).name) get_two_seed_around = get_two_seed_around + 1 end end if get_two_seed_around==2 then meta:set_int("look_around",1) end end if meta:get_int("look_around")==1 then --look for name of crops found if meta:get_string("pos-x")~='none' then set_crops_in_meta_name(meta,meta:get_string("pos-x")) elseif meta:get_string("pos+x")~='none' then set_crops_in_meta_name(meta,meta:get_string("pos+x")) elseif meta:get_string("pos-y")~='none' then set_crops_in_meta_name(meta,meta:get_string("pos-z")) elseif meta:get_string("pos-y")~='none' then set_crops_in_meta_name(meta,meta:get_string("pos+z")) end if meta:get_string("crop1")=='none'and meta:get_string("crop2")=='none' then meta:set_int("look_around",2) end end if meta:get_int("look_around")==2 then --spawn new crop end timer:start(0.2) end })