From d71123e337e4819a50af22fdcc2e61c3d1b9bd50 Mon Sep 17 00:00:00 2001 From: ssdaniel24 Date: Sun, 16 Jun 2024 20:07:57 +0300 Subject: [PATCH] Added can_grow function to plant definition --- game_api.txt | 2 ++ mods/farming/api.lua | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/game_api.txt b/game_api.txt index b3f6efc6..eb7e49ee 100644 --- a/game_api.txt +++ b/game_api.txt @@ -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) minlight = 13, -- Minimum 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) } diff --git a/mods/farming/api.lua b/mods/farming/api.lua index 96f9f636..db2809cf 100644 --- a/mods/farming/api.lua +++ b/mods/farming/api.lua @@ -224,11 +224,15 @@ farming.grow_plant = function(pos, elapsed) return end - -- check if on wet soil - 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) + if def.can_grow and not def.can_grow(pos) then return + else + -- check if on wet soil + 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) + return + end end -- check light