make leaves growth use an increasing ABM.
this also means that leaves now grow slower.
This commit is contained in:
parent
0dffde9363
commit
1282fda837
1 changed files with 14 additions and 4 deletions
|
@ -7,19 +7,28 @@ local leaves = modname .. ":leaves"
|
|||
local leaves_growing = modname .. ":leaves_growing"
|
||||
local leaves_alive = modname .. ":leaves_alive"
|
||||
|
||||
-- END OF NODE NAMES
|
||||
|
||||
|
||||
local max_grow_distance = 2
|
||||
local leaves_grow_cost = 250
|
||||
|
||||
-- TODO: turn this into an increasing ABM.
|
||||
blockgame.register_abm({
|
||||
blockgame.register_increasing_abm({
|
||||
id = modname .. ":grow_leaves",
|
||||
label = "grow leaves",
|
||||
nodenames = {leaves_growing},
|
||||
neighbors = {log_alive, leaves_growing, leaves_alive},
|
||||
interval = 15,
|
||||
chance = 8,
|
||||
action = function (pos, node)
|
||||
rate = function (pos, node, data)
|
||||
-- TODO: account for nearby nodes? e.g. grow slower if there are more leaves nearby.
|
||||
return data.value + math.random(1, 99)
|
||||
end,
|
||||
check = function (pos, node, data)
|
||||
return data.value >= leaves_grow_cost
|
||||
end,
|
||||
action = function (pos, node, data)
|
||||
-- TODO: give leaves energy over time, that they spend when creating new leaves.
|
||||
-- this requires the API to add support for increasing ABM `action`:s to modify `data`.
|
||||
local meta = minetest.get_meta(pos)
|
||||
local distance = meta:get_int("leaf_distance") or 1
|
||||
if distance >= max_grow_distance then return end
|
||||
|
@ -28,6 +37,7 @@ blockgame.register_abm({
|
|||
for _, target in pairs(sides) do
|
||||
if blockgame.chance(2) then
|
||||
blockgame.attempt_place(target, {name = leaves_growing})
|
||||
-- TODO: find lowest possible leaf distance by checking all 4 sides?
|
||||
minetest.get_meta(target):set_int("leaf_distance", distance + 1)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue