// 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();
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
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);
};
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
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
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
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
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
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
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
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
// 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)
// 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)
// 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)
// 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)
// 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)
// 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)