summaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
authorLars Müller <34514239+appgurueu@users.noreply.github.com>2022-05-09 20:42:43 +0200
committersfan5 <sfan5@live.de>2022-05-14 18:33:42 +0200
commitf065d3a06bcbf0cfe5ab4819a1d4d7cd05f96e79 (patch)
tree48e83a15c3a1005a50d58c56119da6d0f3f0ff4a /builtin/game
parent21f7e3a987650cd8fa2f3fe3aa7aa1fde65ef699 (diff)
downloadminetest-f065d3a06bcbf0cfe5ab4819a1d4d7cd05f96e79.tar.gz
minetest-f065d3a06bcbf0cfe5ab4819a1d4d7cd05f96e79.tar.bz2
minetest-f065d3a06bcbf0cfe5ab4819a1d4d7cd05f96e79.zip
Fix Minetest blaming the wrong mod for errors (#12241)
Covers the case where mods insert their callbacks manually into "minetest.registered_<callbacks>" (often to achieve a particular order of execution).
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/item.lua4
-rw-r--r--builtin/game/register.lua14
2 files changed, 10 insertions, 8 deletions
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index 5a83eafd2..2a4b4e38f 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -676,9 +676,7 @@ function core.node_dig(pos, node, digger)
-- Run script hook
for _, callback in ipairs(core.registered_on_dignodes) do
local origin = core.callback_origins[callback]
- if origin then
- core.set_last_run_mod(origin.mod)
- end
+ core.set_last_run_mod(origin.mod)
-- Copy pos and node because callback can modify them
local pos_copy = vector.new(pos)
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index 56e40c75c..0be107c36 100644
--- a/builtin/game/register.lua
+++ b/builtin/game/register.lua
@@ -403,8 +403,14 @@ function core.override_item(name, redefinition)
register_item_raw(item)
end
-
-core.callback_origins = {}
+do
+ local default = {mod = "??", name = "??"}
+ core.callback_origins = setmetatable({}, {
+ __index = function()
+ return default
+ end
+ })
+end
function core.run_callbacks(callbacks, mode, ...)
assert(type(callbacks) == "table")
@@ -419,9 +425,7 @@ function core.run_callbacks(callbacks, mode, ...)
local ret = nil
for i = 1, cb_len do
local origin = core.callback_origins[callbacks[i]]
- if origin then
- core.set_last_run_mod(origin.mod)
- end
+ core.set_last_run_mod(origin.mod)
local cb_ret = callbacks[i](...)
if mode == 0 and i == 1 then