aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-11-25 19:49:20 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-11-29 19:13:52 +0200
commit9e7ad1e2aa832ff93a623e7a1531cee1f1e79ef7 (patch)
tree92ebc9ff4a3750206f52b52858de1a4289d6f16d
parentae9f183cda7046028e6d74972922dc41cf6039bf (diff)
downloadminetest-9e7ad1e2aa832ff93a623e7a1531cee1f1e79ef7.tar.gz
minetest-9e7ad1e2aa832ff93a623e7a1531cee1f1e79ef7.tar.bz2
minetest-9e7ad1e2aa832ff93a623e7a1531cee1f1e79ef7.zip
Add object reference to Lua on_place/dig/punchnode parameters
-rw-r--r--data/mods/default/init.lua5
-rw-r--r--src/scriptapi.cpp20
-rw-r--r--src/scriptapi.h9
-rw-r--r--src/server.cpp9
4 files changed, 28 insertions, 15 deletions
diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua
index e6342c357..11fac245d 100644
--- a/data/mods/default/init.lua
+++ b/data/mods/default/init.lua
@@ -82,8 +82,9 @@ end
-- minetest.register_node(name, {lots of stuff})
-- minetest.register_craft({output=item, recipe={...})
-- minetest.register_globalstep(func)
--- minetest.register_on_placenode(func)
--- minetest.register_on_dignode(func)
+-- minetest.register_on_placenode(func(pos, newnode, placer))
+-- minetest.register_on_dignode(func(pos, oldnode, digger))
+-- minetest.register_on_punchnode(func(pos, node, puncher))
--
-- Global objects:
-- minetest.env - environment reference
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 5ef4f9972..a5454bea5 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -1432,7 +1432,8 @@ void scriptapi_environment_step(lua_State *L, float dtime)
}
}
-void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode)
+void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode,
+ ServerActiveObject *placer)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
@@ -1459,13 +1460,15 @@ void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode)
// Call function
pushpos(L, p);
pushnode(L, newnode, ndef);
- if(lua_pcall(L, 2, 0, 0))
+ objectref_get_or_create(L, placer);
+ if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1));
// value removed, keep key for next iteration
}
}
-void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode)
+void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode,
+ ServerActiveObject *digger)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
@@ -1492,13 +1495,15 @@ void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode)
// Call function
pushpos(L, p);
pushnode(L, oldnode, ndef);
- if(lua_pcall(L, 2, 0, 0))
+ objectref_get_or_create(L, digger);
+ if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1));
// value removed, keep key for next iteration
}
}
-void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode oldnode)
+void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node,
+ ServerActiveObject *puncher)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
@@ -1524,8 +1529,9 @@ void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode oldnode)
luaL_checktype(L, -1, LUA_TFUNCTION);
// Call function
pushpos(L, p);
- pushnode(L, oldnode, ndef);
- if(lua_pcall(L, 2, 0, 0))
+ pushnode(L, node, ndef);
+ objectref_get_or_create(L, puncher);
+ if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1));
// value removed, keep key for next iteration
}
diff --git a/src/scriptapi.h b/src/scriptapi.h
index 46bc8233b..33f090f74 100644
--- a/src/scriptapi.h
+++ b/src/scriptapi.h
@@ -41,11 +41,14 @@ void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj);
// On environment step
void scriptapi_environment_step(lua_State *L, float dtime);
// After adding node
-void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode);
+void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode,
+ ServerActiveObject *placer);
// After removing node
-void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode);
+void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode,
+ ServerActiveObject *digger);
// When punching node
-void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node);
+void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node,
+ ServerActiveObject *puncher);
/* luaentity */
// Returns true if succesfully added into Lua; false otherwise.
diff --git a/src/server.cpp b/src/server.cpp
index 12026054e..fea103e1c 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -2529,7 +2529,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
/*
Run script hook
*/
- scriptapi_environment_on_punchnode(m_lua, p_under, n);
+ ServerRemotePlayer *srp = (ServerRemotePlayer*)player;
+ scriptapi_environment_on_punchnode(m_lua, p_under, n, srp);
} // action == 0
@@ -2769,7 +2770,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
/*
Run script hook
*/
- scriptapi_environment_on_dignode(m_lua, p_under, n);
+ ServerRemotePlayer *srp = (ServerRemotePlayer*)player;
+ scriptapi_environment_on_dignode(m_lua, p_under, n, srp);
}
/*
@@ -2916,7 +2918,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
/*
Run script hook
*/
- scriptapi_environment_on_placenode(m_lua, p_over, n);
+ ServerRemotePlayer *srp = (ServerRemotePlayer*)player;
+ scriptapi_environment_on_placenode(m_lua, p_over, n, srp);
/*
Calculate special events