seeds grow on timer so players can wander

This commit is contained in:
tenplus1 2023-09-11 14:49:37 +01:00
parent b6ba098396
commit fd205e10fc
8 changed files with 54 additions and 3 deletions

View File

@ -18,6 +18,9 @@ minetest.register_node("farming:seed_barley", {
selection_box = farming.select,
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing, "farming:seed_barley")
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "farming:barley_1", param2 = 3})
end
})

View File

@ -47,6 +47,9 @@ minetest.register_node("farming:seed_cotton", {
next_plant = "farming:cotton_1",
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing, "farming:seed_cotton")
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "farming:cotton_1", param2 = 1})
end
})

View File

@ -18,6 +18,9 @@ minetest.register_node("farming:seed_hemp", {
next_plant = "farming:hemp_1",
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing, "farming:seed_hemp")
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "farming:hemp_1", param2 = 1})
end
})

View File

@ -21,6 +21,9 @@ minetest.register_node("farming:seed_mint", {
next_plant = "farming:mint_1",
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing, "farming:seed_mint")
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "farming:mint_1", param2 = 1})
end
})

View File

@ -21,6 +21,9 @@ minetest.register_node("farming:seed_rice", {
next_plant = "farming:rice_1",
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing, "farming:seed_rice")
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "farming:rice_1", param2 = 3})
end
})

View File

@ -28,6 +28,9 @@ minetest.register_node("farming:seed_sunflower", {
next_plant = "farming:sunflower_1",
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing, "farming:seed_sunflower")
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "farming:sunflower_1", param2 = 1})
end
})

View File

@ -18,6 +18,9 @@ minetest.register_node("farming:seed_wheat", {
next_plant = "farming:wheat_1",
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing, "farming:seed_wheat")
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name = "farming:wheat_1", param2 = 3})
end
})

View File

@ -7,7 +7,7 @@
farming = {
mod = "redo",
version = "20230906",
version = "20230911",
path = minetest.get_modpath("farming"),
select = {
type = "fixed",
@ -107,6 +107,16 @@ local STAGE_LENGTH_AVG = tonumber(
local STAGE_LENGTH_DEV = STAGE_LENGTH_AVG / 6
-- quick start seed timer
farming.start_seed_timer = function(pos)
local timer = minetest.get_node_timer(pos)
local grow_time = math.floor(math.random(STAGE_LENGTH_DEV, STAGE_LENGTH_AVG))
timer:start(grow_time)
end
-- return plant name and stage from node provided
local function plant_name_stage(node)
@ -318,8 +328,15 @@ minetest.register_abm({
def = minetest.registered_nodes[next_stage]
-- change seed to stage_1 or crop
if def then
local timer = minetest.get_node_timer(pos):is_started()
-- if seed has timer function that isn't started then start timer
if def and def.on_timer and not timer then
farming.start_seed_timer(pos)
-- otherwise switch seed to stage_1 of crop
elseif def then
local p2 = def.place_param2 or 1
@ -503,6 +520,7 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname)
minetest.set_node(pt.above, {name = plantname, param2 = p2})
farming.start_seed_timer(pt.above)
--minetest.get_node_timer(pt.above):start(1)
--farming.handle_growth(pt.above)--, node)
@ -568,6 +586,18 @@ farming.register_plant = function(name, def)
place_param2 = 1, -- place seed flat
next_plant = mname .. ":" .. pname .. "_1",
on_timer = function(pos, elapsed)
local def = minetest.registered_nodes[mname .. ":" .. pname .. "_1"]
if def then
minetest.swap_node(pos, {
name = def.next_plant,
param2 = def.place_param2
})
end
end,
on_place = function(itemstack, placer, pointed_thing)
return farming.place_seed(itemstack, placer, pointed_thing,
mname .. ":seed_" .. pname)