make blockgame.register_node wrapper emit events.

the api function `blockgame.register_node` will now emit events before
and after registering a node, allowing for other code to react to and
affect node registration.
This commit is contained in:
trans_soup 2023-10-17 20:39:13 +02:00
parent 09bcf2260b
commit 968ae04b3a

View file

@ -32,6 +32,8 @@ local function capitalize (str)
return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2)
end
local events = blockgame.events.namespace("api")
function blockgame.register_node (name, def)
local modname = minetest.get_current_modname()
local full_name = modname .. ":" .. name
@ -41,5 +43,17 @@ function blockgame.register_node (name, def)
modname .. "_" .. name .. ".png",
}
events.broadcast("before_register_node", {
name = name,
def = def,
mod = modname,
})
minetest.register_node(full_name, def)
events.broadcast("after_register_node", {
name = name,
def = def,
mod = modname,
})
end