From 1282fda837f8ce6b370c06411923f9064437f48c Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Thu, 19 Oct 2023 15:23:07 +0200 Subject: [PATCH] make leaves growth use an increasing ABM. this also means that leaves now grow slower. --- mods/bg_tree/grow_leaves.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mods/bg_tree/grow_leaves.lua b/mods/bg_tree/grow_leaves.lua index 44313c9..67dec98 100644 --- a/mods/bg_tree/grow_leaves.lua +++ b/mods/bg_tree/grow_leaves.lua @@ -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