mirror of
https://github.com/moparisthebest/minetest
synced 2024-11-17 23:05:07 -05:00
Allow digging of unknown nodes
This allows the removal of nodes with unknown types. get_item_callback() (C++) would fail if a node has an unknown type. Now it will try using the callback from minetest.nodedef_default in this case. Also, minetest.node_dig() (Lua) was altered to always allow digging when the node definition is empty (i.e. unknown node).
This commit is contained in:
parent
e3b831e975
commit
1ed559bd24
@ -262,7 +262,8 @@ function minetest.node_dig(pos, node, digger)
|
|||||||
minetest.debug("node_dig")
|
minetest.debug("node_dig")
|
||||||
|
|
||||||
local def = ItemStack({name=node.name}):get_definition()
|
local def = ItemStack({name=node.name}):get_definition()
|
||||||
if not def.diggable or (def.can_dig and not def.can_dig(pos,digger)) then
|
-- Check if def ~= 0 because we always want to be able to remove unknown nodes
|
||||||
|
if #def ~= 0 and not def.diggable or (def.can_dig and not def.can_dig(pos,digger)) then
|
||||||
minetest.debug("not diggable")
|
minetest.debug("not diggable")
|
||||||
minetest.log("info", digger:get_player_name() .. " tried to dig "
|
minetest.log("info", digger:get_player_name() .. " tried to dig "
|
||||||
.. node.name .. " which is not diggable "
|
.. node.name .. " which is not diggable "
|
||||||
|
@ -5510,6 +5510,8 @@ void scriptapi_on_player_receive_fields(lua_State *L,
|
|||||||
// If that is nil or on error, return false and stack is unchanged
|
// If that is nil or on error, return false and stack is unchanged
|
||||||
// If that is a function, returns true and pushes the
|
// If that is a function, returns true and pushes the
|
||||||
// function onto the stack
|
// function onto the stack
|
||||||
|
// If minetest.registered_items[name] doesn't exist, minetest.nodedef_default
|
||||||
|
// is tried instead so unknown items can still be manipulated to some degree
|
||||||
static bool get_item_callback(lua_State *L,
|
static bool get_item_callback(lua_State *L,
|
||||||
const char *name, const char *callbackname)
|
const char *name, const char *callbackname)
|
||||||
{
|
{
|
||||||
@ -5522,9 +5524,15 @@ static bool get_item_callback(lua_State *L,
|
|||||||
// Should be a table
|
// Should be a table
|
||||||
if(lua_type(L, -1) != LUA_TTABLE)
|
if(lua_type(L, -1) != LUA_TTABLE)
|
||||||
{
|
{
|
||||||
|
// Report error and clean up
|
||||||
errorstream<<"Item \""<<name<<"\" not defined"<<std::endl;
|
errorstream<<"Item \""<<name<<"\" not defined"<<std::endl;
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
return false;
|
|
||||||
|
// Try minetest.nodedef_default instead
|
||||||
|
lua_getglobal(L, "minetest");
|
||||||
|
lua_getfield(L, -1, "nodedef_default");
|
||||||
|
lua_remove(L, -2);
|
||||||
|
luaL_checktype(L, -1, LUA_TTABLE);
|
||||||
}
|
}
|
||||||
lua_getfield(L, -1, callbackname);
|
lua_getfield(L, -1, callbackname);
|
||||||
lua_remove(L, -2);
|
lua_remove(L, -2);
|
||||||
|
Loading…
Reference in New Issue
Block a user