2023-01-04 10:27:40 +01:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
local name = minetest.get_current_modname()
|
|
|
|
local path = minetest.get_modpath(name)
|
|
|
|
|
2023-01-12 18:58:55 +01:00
|
|
|
local function set_crops_in_meta_name(meta,name)
|
|
|
|
if meta:get_string("crop1")=='none' then
|
|
|
|
meta:set_string("crop1",name)
|
2023-01-19 07:49:36 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if meta:get_string("crop2")=='none' then
|
|
|
|
meta:set_string("crop2",name)
|
|
|
|
return
|
2023-01-12 18:58:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-04 10:27:40 +01:00
|
|
|
--Crops
|
2023-01-12 18:58:55 +01:00
|
|
|
minetest.register_node("owl_tech:crops",{
|
2023-01-04 10:27:40 +01:00
|
|
|
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},
|
2023-01-19 07:49:36 +01:00
|
|
|
{0.45,-0.5,-0.45,0.4,0.5,-0.4},
|
2023-01-04 10:27:40 +01:00
|
|
|
{-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)
|
2023-01-19 07:49:36 +01:00
|
|
|
|
|
|
|
meta:set_string("infotext", "empty")
|
2023-01-12 18:58:55 +01:00
|
|
|
meta:set_int("state",0)
|
2023-01-19 07:49:36 +01:00
|
|
|
meta:set_int("max_redines",0)
|
|
|
|
meta:set_int("redines",0)
|
2023-01-12 18:58:55 +01:00
|
|
|
|
2023-01-04 10:27:40 +01:00
|
|
|
meta:set_string("pos-x", 'none')
|
|
|
|
meta:set_string("pos+x", 'none')
|
|
|
|
meta:set_string("pos-z", 'none')
|
|
|
|
meta:set_string("pos+z", 'none')
|
2023-01-12 18:58:55 +01:00
|
|
|
|
|
|
|
meta:set_string("crop1", 'none')
|
|
|
|
meta:set_string("crop2", 'none')
|
|
|
|
|
2023-01-19 07:49:36 +01:00
|
|
|
meta:set_string("grow_in",'')
|
|
|
|
|
2023-01-04 10:27:40 +01:00
|
|
|
local timer =minetest.get_node_timer(pos)
|
2023-02-23 12:39:51 +01:00
|
|
|
timer:start(0.2)
|
2023-01-04 10:27:40 +01:00
|
|
|
end,
|
|
|
|
on_timer = function (pos, elapsed)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local timer =minetest.get_node_timer(pos)
|
2023-02-23 12:39:51 +01:00
|
|
|
if meta:get_int("state")==0 and minetest.get_node({x=pos.x ,y=pos.y-1,z=pos.z}).name== 'mcl_farming:soil_wet' then
|
2023-01-19 07:49:36 +01:00
|
|
|
local get_two_seed_around = 0
|
2023-02-23 12:39:51 +01:00
|
|
|
for j, value1 in pairs(LIST_CROSS_CROPS) do
|
|
|
|
if minetest.get_node({x=pos.x-1 ,y=pos.y,z=pos.z}).name == LIST_CROSS_CROPS[j] and meta:get_string("pos-x")=="none" then
|
2023-01-04 10:27:40 +01:00
|
|
|
meta:set_string("pos-x",minetest.get_node({x=pos.x-1 ,y=pos.y,z=pos.z}).name)
|
2023-01-12 18:58:55 +01:00
|
|
|
get_two_seed_around = get_two_seed_around + 1
|
2023-01-04 10:27:40 +01:00
|
|
|
end
|
2023-02-23 12:39:51 +01:00
|
|
|
if minetest.get_node({x=pos.x+1 ,y=pos.y,z=pos.z}).name == LIST_CROSS_CROPS[j] and meta:get_string("pos+x")=="none"then
|
2023-01-04 10:27:40 +01:00
|
|
|
meta:set_string("pos+x",minetest.get_node({x=pos.x+1 ,y=pos.y,z=pos.z}).name)
|
2023-01-12 18:58:55 +01:00
|
|
|
get_two_seed_around = get_two_seed_around + 1
|
2023-01-04 10:27:40 +01:00
|
|
|
end
|
2023-02-23 12:39:51 +01:00
|
|
|
if minetest.get_node({x=pos.x ,y=pos.y,z=pos.z-1}).name == LIST_CROSS_CROPS[j] and meta:get_string("pos-z")=="none"then
|
2023-01-04 10:27:40 +01:00
|
|
|
meta:set_string("pos-z",minetest.get_node({x=pos.x ,y=pos.y,z=pos.z-1}).name)
|
2023-01-12 18:58:55 +01:00
|
|
|
get_two_seed_around = get_two_seed_around + 1
|
2023-01-04 10:27:40 +01:00
|
|
|
end
|
2023-02-23 12:39:51 +01:00
|
|
|
if minetest.get_node({x=pos.x ,y=pos.y,z=pos.z+1}).name == LIST_CROSS_CROPS[j] and meta:get_string("pos+z")=="none"then
|
2023-01-04 10:27:40 +01:00
|
|
|
meta:set_string("pos+z",minetest.get_node({x=pos.x ,y=pos.y,z=pos.z+1}).name)
|
2023-01-12 18:58:55 +01:00
|
|
|
get_two_seed_around = get_two_seed_around + 1
|
2023-01-04 10:27:40 +01:00
|
|
|
end
|
|
|
|
end
|
2023-02-23 12:39:51 +01:00
|
|
|
minetest.chat_send_all(get_two_seed_around)
|
2023-01-12 18:58:55 +01:00
|
|
|
if get_two_seed_around==2 then
|
2023-01-19 07:49:36 +01:00
|
|
|
meta:set_int("state",1)
|
2023-01-12 18:58:55 +01:00
|
|
|
end
|
|
|
|
end
|
2023-01-19 07:49:36 +01:00
|
|
|
if meta:get_int("state")==1 then --look for name of crops found
|
2023-01-12 18:58:55 +01:00
|
|
|
if meta:get_string("pos-x")~='none' then
|
|
|
|
set_crops_in_meta_name(meta,meta:get_string("pos-x"))
|
2023-01-19 07:49:36 +01:00
|
|
|
end
|
|
|
|
if meta:get_string("pos+x")~='none' then
|
2023-01-12 18:58:55 +01:00
|
|
|
set_crops_in_meta_name(meta,meta:get_string("pos+x"))
|
2023-01-19 07:49:36 +01:00
|
|
|
end
|
|
|
|
if meta:get_string("pos-z")~='none' then
|
2023-01-12 18:58:55 +01:00
|
|
|
set_crops_in_meta_name(meta,meta:get_string("pos-z"))
|
2023-01-19 07:49:36 +01:00
|
|
|
end
|
|
|
|
if meta:get_string("pos+z")~='none' then
|
2023-01-12 18:58:55 +01:00
|
|
|
set_crops_in_meta_name(meta,meta:get_string("pos+z"))
|
|
|
|
end
|
2023-01-19 07:49:36 +01:00
|
|
|
if meta:get_string("crop1")~='none'and meta:get_string("crop2")~='none' then
|
|
|
|
meta:set_int("state",2)
|
2023-01-12 18:58:55 +01:00
|
|
|
end
|
|
|
|
end
|
2023-01-19 07:49:36 +01:00
|
|
|
if meta:get_int("state")==2 then --spawn new crop
|
|
|
|
meta:set_string('crop1',string.gsub(meta:get_string("crop1"),"mcl_farming:",''))
|
|
|
|
meta:set_string('crop2',string.gsub(meta:get_string("crop2"),"mcl_farming:",''))
|
|
|
|
meta:set_string('crop1',string.gsub(meta:get_string("crop1"),"owl_tech:",''))
|
|
|
|
meta:set_string('crop2',string.gsub(meta:get_string("crop2"),"owl_tech:",''))
|
|
|
|
|
|
|
|
if CROPS_BREED[meta:get_string("crop1")..meta:get_string("crop2")] then
|
|
|
|
meta:set_int("state",3)
|
|
|
|
meta:set_string("grow_in",CROPS_BREED[meta:get_string("crop1")..meta:get_string("crop2")][2])
|
|
|
|
meta:set_int("max_redines", CROPS_BREED[meta:get_string("crop1")..meta:get_string("crop2")][1])
|
|
|
|
elseif CROPS_BREED[meta:get_string("crop2")..meta:get_string("crop1")] then
|
|
|
|
meta:set_int("state",3)
|
|
|
|
meta:set_string("grow_in",CROPS_BREED[meta:get_string("crop2")..meta:get_string("crop1")][2])
|
|
|
|
meta:set_int("max_redines", CROPS_BREED[meta:get_string("crop2")..meta:get_string("crop1")][1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if meta:get_int("state")==3 then
|
|
|
|
meta:set_string("infotext", "somthing_grow")
|
|
|
|
if meta:get_int("redines")>=meta:get_int("max_redines") then
|
|
|
|
meta:set_int("redines",meta:get_int("redines")+1)
|
|
|
|
else
|
|
|
|
minetest.set_node(pos, {name=meta:get_string("grow_in")})
|
|
|
|
end
|
2023-01-04 10:27:40 +01:00
|
|
|
end
|
2023-02-23 12:39:51 +01:00
|
|
|
timer:start(0.2)
|
2023-01-04 10:27:40 +01:00
|
|
|
end
|
2023-01-12 18:58:55 +01:00
|
|
|
})
|