Skip to content

Commit 061f4e7

Browse files
authored
Added can_grow function to plant definition (#3131)
1 parent f03c992 commit 061f4e7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

game_api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ The farming API allows you to easily register plants and hoes.
382382
-- ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
383383
minlight = 13, -- Minimum light to grow
384384
maxlight = default.LIGHT_MAX -- Maximum light to grow
385+
can_grow = function(pos) -- Сalled every growth tick to check if the plant can grow, returns bool
386+
-- (optional, checks for wet soil by default)
385387
}
386388

387389

mods/farming/api.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
189189
return itemstack
190190
end
191191

192+
-- check if on wet soil
193+
farming.can_grow = function(pos)
194+
local below = minetest.get_node(pos:offset(0, -1, 0))
195+
return minetest.get_item_group(below.name, "soil") >= 3
196+
end
197+
192198
farming.grow_plant = function(pos, elapsed)
193199
local node = minetest.get_node(pos)
194200
local name = node.name
@@ -224,9 +230,7 @@ farming.grow_plant = function(pos, elapsed)
224230
return
225231
end
226232

227-
-- check if on wet soil
228-
local below = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
229-
if minetest.get_item_group(below.name, "soil") < 3 then
233+
if not (def.can_grow or farming.can_grow)(pos) then
230234
tick_again(pos)
231235
return
232236
end

0 commit comments

Comments
 (0)