1
0
mirror of https://codeberg.org/tenplus1/farming.git synced 2024-12-26 18:50:20 +01:00

add mt5.9x new farming.can_grow default function and check, deprecate but still run growth_check function

This commit is contained in:
tenplus1 2024-06-24 07:41:40 +01:00
parent 8bd129309c
commit ac4c4f48d3
2 changed files with 20 additions and 10 deletions

View File

@ -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

View File

@ -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