aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorsapier <sapier at gmx dot net>2017-01-21 15:58:07 +0100
committersapier <sapier at gmx dot net>2017-01-28 15:57:54 +0100
commit814ee971f70a8ef1fa4a470bcf385300686e9e70 (patch)
tree441f17f8a118a8bad5cc6ad5ca3067f90bd28f6a /src/script
parent953cbb3b15997a0e7c7c32af2365cb5046a9e476 (diff)
downloadminetest-814ee971f70a8ef1fa4a470bcf385300686e9e70.tar.gz
minetest-814ee971f70a8ef1fa4a470bcf385300686e9e70.tar.bz2
minetest-814ee971f70a8ef1fa4a470bcf385300686e9e70.zip
Make entity on_punch have same signature and behaviour as player on_punch
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_entity.cpp15
-rw-r--r--src/script/cpp_api/s_entity.h4
2 files changed, 11 insertions, 8 deletions
diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp
index 378a6bf09..fcd8dd4a0 100644
--- a/src/script/cpp_api/s_entity.cpp
+++ b/src/script/cpp_api/s_entity.cpp
@@ -224,10 +224,10 @@ void ScriptApiEntity::luaentity_Step(u16 id, float dtime)
}
// Calls entity:on_punch(ObjectRef puncher, time_from_last_punch,
-// tool_capabilities, direction)
-void ScriptApiEntity::luaentity_Punch(u16 id,
+// tool_capabilities, direction, damage)
+bool ScriptApiEntity::luaentity_Punch(u16 id,
ServerActiveObject *puncher, float time_from_last_punch,
- const ToolCapabilities *toolcap, v3f dir)
+ const ToolCapabilities *toolcap, v3f dir, s16 damage)
{
SCRIPTAPI_PRECHECKHEADER
@@ -242,8 +242,8 @@ void ScriptApiEntity::luaentity_Punch(u16 id,
// Get function
lua_getfield(L, -1, "on_punch");
if (lua_isnil(L, -1)) {
- lua_pop(L, 2); // Pop on_punch and entitu
- return;
+ lua_pop(L, 2); // Pop on_punch and entity
+ return false;
}
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self
@@ -251,11 +251,14 @@ void ScriptApiEntity::luaentity_Punch(u16 id,
lua_pushnumber(L, time_from_last_punch);
push_tool_capabilities(L, *toolcap);
push_v3f(L, dir);
+ lua_pushnumber(L, damage);
setOriginFromTable(object);
- PCALL_RES(lua_pcall(L, 5, 0, error_handler));
+ PCALL_RES(lua_pcall(L, 6, 0, error_handler));
+ bool retval = lua_toboolean(L, -1);
lua_pop(L, 2); // Pop object and error handler
+ return retval;
}
// Calls entity:on_rightclick(ObjectRef clicker)
diff --git a/src/script/cpp_api/s_entity.h b/src/script/cpp_api/s_entity.h
index 8df9d7f00..4e2a056bb 100644
--- a/src/script/cpp_api/s_entity.h
+++ b/src/script/cpp_api/s_entity.h
@@ -38,9 +38,9 @@ public:
void luaentity_GetProperties(u16 id,
ObjectProperties *prop);
void luaentity_Step(u16 id, float dtime);
- void luaentity_Punch(u16 id,
+ bool luaentity_Punch(u16 id,
ServerActiveObject *puncher, float time_from_last_punch,
- const ToolCapabilities *toolcap, v3f dir);
+ const ToolCapabilities *toolcap, v3f dir, s16 damage);
void luaentity_Rightclick(u16 id,
ServerActiveObject *clicker);
};