diff --git a/api.txt b/api.txt index 2500df3..eb25cb9 100644 --- a/api.txt +++ b/api.txt @@ -50,7 +50,7 @@ Note: Any crops registered with the above function will use the new growing rout If a mod registers nodes to be used as crops using the {growing=1} group then an additional function can be used for custom growth checks instead of the standard 'are we above wet soil'. -growth_check = function(pos, [node_name]) +growth_check = function(pos, [node_name]) [DEPRECATED for above can_grow function] -- check surrounding for jungle tree if minetest.find_node_near(pos, 1, {"default:jungletree"}) then return true -- place next growth stage diff --git a/init.lua b/init.lua index 5c1fe31..491e429 100644 --- a/init.lua +++ b/init.lua @@ -7,7 +7,7 @@ farming = { mod = "redo", - version = "20240609", + version = "20240624", path = minetest.get_modpath("farming"), select = { type = "fixed", @@ -360,6 +360,12 @@ minetest.register_abm({ }) +-- check if on wet soil +farming.can_grow = function(pos) + local below = minetest.get_node({x = pos.x, y = pos.y -1, z = pos.z}) + return minetest.get_item_group(below.name, "soil") >= 3 +end + -- Plant timer function that grows plants under the right conditions. function farming.plant_growth_timer(pos, elapsed, node_name) @@ -375,22 +381,26 @@ function farming.plant_growth_timer(pos, elapsed, node_name) return false end - -- custom growth check - local chk = minetest.registered_nodes[node_name].growth_check + local chk1 = minetest.registered_nodes[node_name].growth_check -- old + local chk2 = minetest.registered_nodes[node_name].can_grow -- new - if chk then + -- custom farming redo growth_check function + if chk1 then - if not chk(pos, node_name) then + if not chk1(pos, node_name) then return true end - -- otherwise check for wet soil beneath crop - else - local under = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}) + -- custom mt 5.9x farming can_grow function + elseif chk2 then - if minetest.get_item_group(under.name, "soil") < 3 then + if not chk2(pos) then return true end + + -- default mt 5.9x farming.can_grow function + elseif not farming.can_grow(pos) then + return true end local growth