Unkown nodes: Provide position on interact (#6505)

* Unkown nodes: Provide position on interact
master
SmallJoker 2017-10-07 15:11:07 +02:00 committed by Loïc Blot
parent 00ceec9ff9
commit f547452685
4 changed files with 22 additions and 19 deletions

View File

@ -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

View File

@ -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);
};

View File

@ -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

View File

@ -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)