mirror of
https://codeberg.org/tenplus1/farming.git
synced 2024-12-27 03:00:20 +01:00
add mt5.9x new farming.can_grow default function and check, deprecate but still run growth_check function
This commit is contained in:
parent
8bd129309c
commit
ac4c4f48d3
2
api.txt
2
api.txt
@ -50,7 +50,7 @@ Note: Any crops registered with the above function will use the new growing rout
|
|||||||
|
|
||||||
If a mod registers nodes to be used as crops using the {growing=1} group then an additional function can be used for custom growth checks instead of the standard 'are we above wet soil'.
|
If a mod registers nodes to be used as crops using the {growing=1} group then an additional function can be used for custom growth checks instead of the standard 'are we above wet soil'.
|
||||||
|
|
||||||
growth_check = function(pos, [node_name])
|
growth_check = function(pos, [node_name]) [DEPRECATED for above can_grow function]
|
||||||
-- check surrounding for jungle tree
|
-- check surrounding for jungle tree
|
||||||
if minetest.find_node_near(pos, 1, {"default:jungletree"}) then
|
if minetest.find_node_near(pos, 1, {"default:jungletree"}) then
|
||||||
return true -- place next growth stage
|
return true -- place next growth stage
|
||||||
|
28
init.lua
28
init.lua
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
farming = {
|
farming = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20240609",
|
version = "20240624",
|
||||||
path = minetest.get_modpath("farming"),
|
path = minetest.get_modpath("farming"),
|
||||||
select = {
|
select = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -360,6 +360,12 @@ minetest.register_abm({
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
-- check if on wet soil
|
||||||
|
farming.can_grow = function(pos)
|
||||||
|
local below = minetest.get_node({x = pos.x, y = pos.y -1, z = pos.z})
|
||||||
|
return minetest.get_item_group(below.name, "soil") >= 3
|
||||||
|
end
|
||||||
|
|
||||||
-- Plant timer function that grows plants under the right conditions.
|
-- Plant timer function that grows plants under the right conditions.
|
||||||
function farming.plant_growth_timer(pos, elapsed, node_name)
|
function farming.plant_growth_timer(pos, elapsed, node_name)
|
||||||
|
|
||||||
@ -375,22 +381,26 @@ function farming.plant_growth_timer(pos, elapsed, node_name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- custom growth check
|
local chk1 = minetest.registered_nodes[node_name].growth_check -- old
|
||||||
local chk = minetest.registered_nodes[node_name].growth_check
|
local chk2 = minetest.registered_nodes[node_name].can_grow -- new
|
||||||
|
|
||||||
if chk then
|
-- custom farming redo growth_check function
|
||||||
|
if chk1 then
|
||||||
|
|
||||||
if not chk(pos, node_name) then
|
if not chk1(pos, node_name) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- otherwise check for wet soil beneath crop
|
-- custom mt 5.9x farming can_grow function
|
||||||
else
|
elseif chk2 then
|
||||||
local under = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
|
|
||||||
|
|
||||||
if minetest.get_item_group(under.name, "soil") < 3 then
|
if not chk2(pos) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- default mt 5.9x farming.can_grow function
|
||||||
|
elseif not farming.can_grow(pos) then
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local growth
|
local growth
|
||||||
|
Loading…
Reference in New Issue
Block a user