blockgame/mods/bg_api/increasing_abm.lua

32 lines
806 B
Lua
Raw Normal View History

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