mirror of
https://github.com/minetest/minetest_game.git
synced 2024-11-08 08:43:51 +01:00
Added can_grow function to plant definition (#3131)
This commit is contained in:
parent
f03c992864
commit
061f4e76dd
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user