blockgame/mods/bg_tree/grow_leaves.lua
trans_soup d884e75a24 fix: account for moved api function.
change something that should've been changed before, when the api
function in question was moved.
2023-10-17 11:24:18 +02:00

36 lines
1.1 KiB
Lua

local modname = minetest.get_current_modname()
-- NODE NAMES
local log_alive = modname .. ":log_alive"
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
-- TODO: turn this into an increasing ABM.
blockgame.register_abm({
label = "grow leaves",
nodenames = {leaves_growing},
neighbors = {log_alive, leaves_growing, leaves_alive},
interval = 15,
chance = 8,
action = function (pos, node)
-- TODO: give leaves energy over time, that they spend when creating new leaves.
local meta = minetest.get_meta(pos)
local distance = meta:get_int("leaf_distance") or 1
if distance >= max_grow_distance then return end
local neighbors = blockgame.vector.get_neighbors(pos)
for _, target in pairs(neighbors) do
if blockgame.chance(2) then
blockgame.attempt_place(target, {name = leaves_growing})
minetest.get_meta(target):set_int("leaf_distance", distance + 1)
end
end
minetest.set_node(pos, {name = leaves_alive})
end,
})