blockgame/mods/bg_api/loose_node.lua
trans_soup 07781855ad make loose node settling use an increasing ABM.
loose nodes will now take some time to settle, instead of doing so
completely randomly.
2023-10-17 21:03:34 +02:00

48 lines
1.2 KiB
Lua

local modname = minetest.get_current_modname()
-- settle nodes that have been still for a while.
blockgame.register_increasing_abm({
id = modname .. ":settle_loose_nodes",
label = "settle loose nodes",
nodenames = {"group:loose"},
interval = 20,
chance = 5,
rate = function (pos, node, data)
return data.value + math.random(1, 9)
end,
check = function (pos, node, data)
local below = pos + blockgame.vector.dirs.down
if minetest.get_node(below).name == "air" then
minetest.check_for_falling(pos)
return false
end
return data.value >= 30
end,
action = function (pos, node, data)
local def = minetest.registered_nodes[node.name]
minetest.set_node(pos, {name = def.settle_into})
end,
})
local events = blockgame.events.namespace("api")
events.listen("before_register_node", function (data)
local name = data.name
local def = data.def
local mod = data.mod
if not def.loose_variant then return end
blockgame.register_node(def.loose_variant, {
description = "Loose " .. def.description,
tiles = def.tiles, -- temporary
groups = blockgame.underride({
loose = 1,
falling_node = 1
}, def.groups),
settle_into = mod .. ":" .. name,
}, mod)
end)