aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/script/cpp_api/s_item.cpp11
-rw-r--r--src/script/cpp_api/s_item.h2
-rw-r--r--src/script/cpp_api/s_node.cpp16
-rw-r--r--src/script/cpp_api/s_nodemeta.cpp12
4 files changed, 22 insertions, 19 deletions
diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp
index e13da1c86..0654ca3dc 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 7350a71c5..b4b02b0c5 100644
--- a/src/script/cpp_api/s_item.h
+++ b/src/script/cpp_api/s_item.h
@@ -53,7 +53,7 @@ protected:
friend class LuaItemStack;
friend class ModApiItemMod;
- 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 1ae8f58a5..91e153c18 100644
--- a/src/script/cpp_api/s_node.cpp
+++ b/src/script/cpp_api/s_node.cpp
@@ -107,7 +107,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
@@ -130,7 +130,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
@@ -151,7 +151,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
@@ -169,7 +169,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
@@ -187,7 +187,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
@@ -208,7 +208,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
@@ -227,7 +227,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
@@ -255,7 +255,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 d050c0bc9..2f726dfa2 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)