blockgame/mods/bg_api/increasing_abm.lua
trans_soup 453add021d implement increasing ABM:s.
create public api function that registers "increasing ABM:s"; these
abstract over using numerical values associated with individual nodes in
ABM:s, allowing for straightforward creation of processes that occur
over time.
2023-10-16 21:27:59 +02:00

31 lines
806 B
Lua

function blockgame.register_increasing_abm (def)
local id = def.id or "unknown"
local label = def.label or "unlabeled"
local nodenames = def.nodenames or {}
local neighbors = def.neighbors or {}
local interval = def.interval or 60
local chance = def.chance or 10
-- TODO: fully validate def, make sure it has the necessary functions specified.
blockgame.register_abm({
label = label,
nodenames = nodenames,
neighbors = neighbors,
interval = interval,
chance = chance,
action = function (pos, node)
local meta = minetest.get_meta(pos)
local value = meta:get_int(id) or 0
local data = {
value = value,
}
value = def.rate(pos, node, data)
meta:set_int(id, value)
if not def.check(pos, node, data) then return end
def.action(pos, node, data)
end,
})
end