Added can_grow function to plant definition (#3131)

This commit is contained in:
ssdaniel24 2024-06-23 19:03:36 +03:00 committed by GitHub
parent f03c992864
commit 061f4e76dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

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

@ -189,6 +189,12 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
return itemstack return itemstack
end end
-- check if on wet soil
farming.can_grow = function(pos)
local below = minetest.get_node(pos:offset(0, -1, 0))
return minetest.get_item_group(below.name, "soil") >= 3
end
farming.grow_plant = function(pos, elapsed) farming.grow_plant = function(pos, elapsed)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local name = node.name local name = node.name
@ -224,9 +230,7 @@ farming.grow_plant = function(pos, elapsed)
return return
end end
-- check if on wet soil if not (def.can_grow or farming.can_grow)(pos) then
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
tick_again(pos) tick_again(pos)
return return
end end