Added can_grow function to plant definition

This commit is contained in:
ssdaniel24 2024-06-16 20:07:57 +03:00
parent 511619253f
commit d71123e337
2 changed files with 10 additions and 4 deletions

View file

@ -382,6 +382,8 @@ The farming API allows you to easily register plants and hoes.
-- ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber) -- ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
minlight = 13, -- Minimum light to grow minlight = 13, -- Minimum light to grow
maxlight = default.LIGHT_MAX -- Maximum light to grow maxlight = default.LIGHT_MAX -- Maximum light to grow
can_grow = function(pos) -- Сalled every growth tick to check if the plant can grow, returns bool
-- (optional, checks for wet soil by default)
} }

View file

@ -224,12 +224,16 @@ farming.grow_plant = function(pos, elapsed)
return return
end end
if def.can_grow and not def.can_grow(pos) then
return
else
-- check if on wet soil -- check if on wet soil
local below = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}) local below = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
if minetest.get_item_group(below.name, "soil") < 3 then if minetest.get_item_group(below.name, "soil") < 3 then
tick_again(pos) tick_again(pos)
return return
end end
end
-- check light -- check light
local light = minetest.get_node_light(pos) local light = minetest.get_node_light(pos)