From f547452685b299712ff5aa15bf06b4cd6069deec Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 7 Oct 2017 15:11:07 +0200 Subject: Unkown nodes: Provide position on interact (#6505) * Unkown nodes: Provide position on interact --- src/script/cpp_api/s_item.cpp | 11 +++++++---- src/script/cpp_api/s_item.h | 2 +- src/script/cpp_api/s_node.cpp | 16 ++++++++-------- src/script/cpp_api/s_nodemeta.cpp | 12 ++++++------ 4 files changed, 22 insertions(+), 19 deletions(-) (limited to 'src/script') diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index 3876272d7..5d9d26083 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -211,7 +211,8 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user, // function onto the stack // If core.registered_items[name] doesn't exist, core.nodedef_default // is tried instead so unknown items can still be manipulated to some degree -bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname) +bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname, + const v3s16 *p) { lua_State* L = getStack(); @@ -222,10 +223,12 @@ bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname) lua_getfield(L, -1, name); lua_remove(L, -2); // Remove registered_items // 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"; + if (p) + errorstream << " at position " << PP(*p); + errorstream << std::endl; lua_pop(L, 1); // Try core.nodedef_default instead diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h index 561f3a553..d91b5c1d6 100644 --- a/src/script/cpp_api/s_item.h +++ b/src/script/cpp_api/s_item.h @@ -53,7 +53,7 @@ protected: friend class ModApiItemMod; friend class LuaRaycast; - bool getItemCallback(const char *name, const char *callbackname); + bool getItemCallback(const char *name, const char *callbackname, const v3s16 *p = nullptr); void pushPointedThing(const PointedThing& pointed); }; diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index c8f85317e..f7ba95075 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -103,7 +103,7 @@ bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node, INodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_punch")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_punch", &p)) return false; // Call function @@ -126,7 +126,7 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node, INodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_dig")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_dig", &p)) return false; // Call function @@ -147,7 +147,7 @@ void ScriptApiNode::node_on_construct(v3s16 p, MapNode node) INodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_construct")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_construct", &p)) return; // Call function @@ -165,7 +165,7 @@ void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node) INodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_destruct")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_destruct", &p)) return; // Call function @@ -183,7 +183,7 @@ bool ScriptApiNode::node_on_flood(v3s16 p, MapNode node, MapNode newnode) INodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_flood")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_flood", &p)) return false; // Call function @@ -204,7 +204,7 @@ void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node) INodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "after_destruct")) + if (!getItemCallback(ndef->get(node).name.c_str(), "after_destruct", &p)) return; // Call function @@ -223,7 +223,7 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime) INodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_timer")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_timer", &p)) return false; // Call function @@ -251,7 +251,7 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p, return; // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_receive_fields")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_receive_fields", &p)) return; // Call function diff --git a/src/script/cpp_api/s_nodemeta.cpp b/src/script/cpp_api/s_nodemeta.cpp index 2e6d3a373..9c3bfcc8e 100644 --- a/src/script/cpp_api/s_nodemeta.cpp +++ b/src/script/cpp_api/s_nodemeta.cpp @@ -45,7 +45,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p, // Push callback function on stack std::string nodename = ndef->get(node).name; - if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_move")) + if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_move", &p)) return count; // function(pos, from_list, from_index, to_list, to_index, count, player) @@ -83,7 +83,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p, // Push callback function on stack std::string nodename = ndef->get(node).name; - if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_put")) + if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_put", &p)) return stack.count; // Call function(pos, listname, index, stack, player) @@ -119,7 +119,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p, // Push callback function on stack std::string nodename = ndef->get(node).name; - if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_take")) + if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_take", &p)) return stack.count; // Call function(pos, listname, index, count, player) @@ -156,7 +156,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove(v3s16 p, // Push callback function on stack std::string nodename = ndef->get(node).name; - if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_move")) + if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_move", &p)) return; // function(pos, from_list, from_index, to_list, to_index, count, player) @@ -189,7 +189,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut(v3s16 p, // Push callback function on stack std::string nodename = ndef->get(node).name; - if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_put")) + if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_put", &p)) return; // Call function(pos, listname, index, stack, player) @@ -220,7 +220,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake(v3s16 p, // Push callback function on stack std::string nodename = ndef->get(node).name; - if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_take")) + if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_take", &p)) return; // Call function(pos, listname, index, stack, player) -- cgit v1.2.3