From 968ae04b3ae9144319964d4341432df21bd31cfc Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Tue, 17 Oct 2023 20:39:13 +0200 Subject: [PATCH] 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. --- mods/bg_api/wrappers.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mods/bg_api/wrappers.lua b/mods/bg_api/wrappers.lua index ffc2752..24ef6f1 100644 --- a/mods/bg_api/wrappers.lua +++ b/mods/bg_api/wrappers.lua @@ -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