From 061f4e76dd1e42517c618d2e6bd8d0c88b0ed5c7 Mon Sep 17 00:00:00 2001 From: ssdaniel24 <107036969+ssdaniel24@users.noreply.github.com> Date: Sun, 23 Jun 2024 19:03:36 +0300 Subject: [PATCH] Added can_grow function to plant definition (#3131) --- game_api.txt | 2 ++ mods/farming/api.lua | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/game_api.txt b/game_api.txt index fb769c8d..3dcb2578 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..08ab0a0a 100644 --- a/mods/farming/api.lua +++ b/mods/farming/api.lua @@ -189,6 +189,12 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname) return itemstack 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) local node = minetest.get_node(pos) local name = node.name @@ -224,9 +230,7 @@ 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 + if not (def.can_grow or farming.can_grow)(pos) then tick_again(pos) return end