Skip to content

Commit

Permalink
Added can_grow function to plant definition (#3131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssdaniel24 authored Jun 23, 2024
1 parent f03c992 commit 061f4e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions game_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down
10 changes: 7 additions & 3 deletions mods/farming/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 061f4e7

Please sign in to comment.