summaryrefslogtreecommitdiff
path: root/src/content_sao.cpp
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/content_sao.cpp
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/content_sao.cpp')
-rw-r--r--src/content_sao.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 35133490e..7a1171eb7 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -578,28 +578,32 @@ int LuaEntitySAO::punch(v3f dir,
punchitem,
time_from_last_punch);
- if (result.did_punch) {
- setHP(getHP() - result.damage);
+ bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
+ time_from_last_punch, toolcap, dir, result.did_punch ? result.damage : 0);
- if (result.damage > 0) {
- std::string punchername = puncher ? puncher->getDescription() : "nil";
+ if (!damage_handled) {
+ if (result.did_punch) {
+ setHP(getHP() - result.damage);
- actionstream << getDescription() << " punched by "
- << punchername << ", damage " << result.damage
- << " hp, health now " << getHP() << " hp" << std::endl;
- }
+ if (result.damage > 0) {
+ std::string punchername = puncher ? puncher->getDescription() : "nil";
- std::string str = gob_cmd_punched(result.damage, getHP());
- // create message and add to list
- ActiveObjectMessage aom(getId(), true, str);
- m_messages_out.push(aom);
+ actionstream << getDescription() << " punched by "
+ << punchername << ", damage " << result.damage
+ << " hp, health now " << getHP() << " hp" << std::endl;
+ }
+
+ std::string str = gob_cmd_punched(result.damage, getHP());
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push(aom);
+ }
}
if (getHP() == 0)
m_removed = true;
- m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
- time_from_last_punch, toolcap, dir);
+
return result.wear;
}