forked from mtcontrib/farming
Fix growth_check return value/check, add initial on_grow function
This commit is contained in:
parent
27aae682bd
commit
426564232e
@ -163,10 +163,10 @@ local def = {
|
|||||||
|
|
||||||
if minetest.find_node_near(pos, 1,
|
if minetest.find_node_near(pos, 1,
|
||||||
{"default:jungletree", "mcl_core:jungletree"}) then
|
{"default:jungletree", "mcl_core:jungletree"}) then
|
||||||
return false -- can grow
|
return true -- place next growth stage
|
||||||
end
|
end
|
||||||
|
|
||||||
return true -- cannot grow
|
return false -- condition not met, skip growth stage until next check
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
init.lua
22
init.lua
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
farming = {
|
farming = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20230905",
|
version = "20230906",
|
||||||
path = minetest.get_modpath("farming"),
|
path = minetest.get_modpath("farming"),
|
||||||
select = {
|
select = {
|
||||||
type = "fixed",
|
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.
|
-- Plant timer function that grows plants under the right conditions.
|
||||||
function farming.plant_growth_timer(pos, elapsed, node_name)
|
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 then
|
||||||
|
|
||||||
if chk(pos, node_name) then
|
if not chk(pos, node_name) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -413,9 +422,14 @@ function farming.plant_growth_timer(pos, elapsed, node_name)
|
|||||||
|
|
||||||
if minetest.registered_nodes[stages.stages_left[growth]] then
|
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
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user