From 426564232eef561925c28347a0380eaf67979b31 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Wed, 6 Sep 2023 08:11:07 +0100 Subject: [PATCH] Fix growth_check return value/check, add initial on_grow function --- crops/cocoa.lua | 4 ++-- init.lua | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crops/cocoa.lua b/crops/cocoa.lua index 303104e..cc3267f 100644 --- a/crops/cocoa.lua +++ b/crops/cocoa.lua @@ -163,10 +163,10 @@ local def = { if minetest.find_node_near(pos, 1, {"default:jungletree", "mcl_core:jungletree"}) then - return false -- can grow + return true -- place next growth stage end - return true -- cannot grow + return false -- condition not met, skip growth stage until next check end } diff --git a/init.lua b/init.lua index f41394a..c78f964 100644 --- a/init.lua +++ b/init.lua @@ -7,7 +7,7 @@ farming = { mod = "redo", - version = "20230905", + version = "20230906", path = minetest.get_modpath("farming"), select = { type = "fixed", @@ -332,6 +332,15 @@ minetest.register_abm({ }) +-- Standard growth logic, swap node until we reach last stage. +function farming.classic_growth(pos, next_stage) + + local p2 = minetest.registered_nodes[next_stage].place_param2 or 1 + + minetest.swap_node(pos, {name = next_stage, param2 = p2}) +end + + -- Plant timer function that grows plants under the right conditions. function farming.plant_growth_timer(pos, elapsed, node_name) @@ -352,7 +361,7 @@ function farming.plant_growth_timer(pos, elapsed, node_name) if chk then - if chk(pos, node_name) then + if not chk(pos, node_name) then return true end @@ -413,9 +422,14 @@ function farming.plant_growth_timer(pos, elapsed, node_name) if minetest.registered_nodes[stages.stages_left[growth]] then - local p2 = minetest.registered_nodes[stages.stages_left[growth] ].place_param2 or 1 + -- Custom grow function + local on_grow = minetest.registered_nodes[node_name].on_grow - minetest.swap_node(pos, {name = stages.stages_left[growth], param2 = p2}) + if on_grow then + on_grow(pos, stages.stages_left[growth]) + else + farming.classic_growth(pos, stages.stages_left[growth]) + end else return true end