Skip to content

Commit 6e0e032

Browse files
authored
Fix minetest.dig_node returning true when node isn't diggable (#10890)
1 parent d1ec511 commit 6e0e032

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

builtin/game/item.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ function core.node_dig(pos, node, digger)
557557
log("info", diggername .. " tried to dig "
558558
.. node.name .. " which is not diggable "
559559
.. core.pos_to_string(pos))
560-
return
560+
return false
561561
end
562562

563563
if core.is_protected(pos, diggername) then
@@ -566,7 +566,7 @@ function core.node_dig(pos, node, digger)
566566
.. " at protected position "
567567
.. core.pos_to_string(pos))
568568
core.record_protection_violation(pos, diggername)
569-
return
569+
return false
570570
end
571571

572572
log('action', diggername .. " digs "
@@ -649,6 +649,8 @@ function core.node_dig(pos, node, digger)
649649
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
650650
callback(pos_copy, node_copy, digger)
651651
end
652+
653+
return true
652654
end
653655

654656
function core.itemstring_with_palette(item, palette_index)

doc/lua_api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7628,6 +7628,8 @@ Used by `minetest.register_node`.
76287628
on_dig = function(pos, node, digger),
76297629
-- default: minetest.node_dig
76307630
-- By default checks privileges, wears out tool and removes node.
7631+
-- return true if the node was dug successfully, false otherwise.
7632+
-- Deprecated: returning nil is the same as returning true.
76317633

76327634
on_timer = function(pos, elapsed),
76337635
-- default: nil

src/script/cpp_api/s_node.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,14 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node,
141141
push_v3s16(L, p);
142142
pushnode(L, node, ndef);
143143
objectrefGetOrCreate(L, digger);
144-
PCALL_RES(lua_pcall(L, 3, 0, error_handler));
145-
lua_pop(L, 1); // Pop error handler
146-
return true;
144+
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
145+
146+
// nil is treated as true for backwards compat
147+
bool result = lua_isnil(L, -1) || lua_toboolean(L, -1);
148+
149+
lua_pop(L, 2); // Pop error handler and result
150+
151+
return result;
147152
}
148153

149154
void ScriptApiNode::node_on_construct(v3s16 p, MapNode node)

0 commit comments

Comments
 (0)