Skip to content
Snippets Groups Projects
Commit bb5f830d authored by SmallJoker's avatar SmallJoker Committed by est31
Browse files

Ignore punches with no damage in the actionstream

parent ecdfbfc8
No related branches found
No related tags found
No related merge requests found
...@@ -419,19 +419,19 @@ int LuaEntitySAO::punch(v3f dir, ...@@ -419,19 +419,19 @@ int LuaEntitySAO::punch(v3f dir,
ServerActiveObject *puncher, ServerActiveObject *puncher,
float time_from_last_punch) float time_from_last_punch)
{ {
if(!m_registered){ if (!m_registered){
// Delete unknown LuaEntities when punched // Delete unknown LuaEntities when punched
m_removed = true; m_removed = true;
return 0; return 0;
} }
// It's best that attachments cannot be punched // It's best that attachments cannot be punched
if(isAttached()) if (isAttached())
return 0; return 0;
ItemStack *punchitem = NULL; ItemStack *punchitem = NULL;
ItemStack punchitem_static; ItemStack punchitem_static;
if(puncher){ if (puncher) {
punchitem_static = puncher->getWieldedItem(); punchitem_static = puncher->getWieldedItem();
punchitem = &punchitem_static; punchitem = &punchitem_static;
} }
...@@ -442,31 +442,26 @@ int LuaEntitySAO::punch(v3f dir, ...@@ -442,31 +442,26 @@ int LuaEntitySAO::punch(v3f dir,
punchitem, punchitem,
time_from_last_punch); time_from_last_punch);
if(result.did_punch) if (result.did_punch) {
{
setHP(getHP() - result.damage); setHP(getHP() - result.damage);
if (result.damage > 0) {
std::string punchername = puncher ? puncher->getDescription() : "nil";
std::string punchername = "nil"; actionstream << getDescription() << " punched by "
<< punchername << ", damage " << result.damage
if ( puncher != 0 ) << " hp, health now " << getHP() << " hp" << std::endl;
punchername = puncher->getDescription();
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) std::string str = gob_cmd_punched(result.damage, getHP());
m_removed = true; // 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, m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
time_from_last_punch, toolcap, dir); time_from_last_punch, toolcap, dir);
...@@ -475,10 +470,10 @@ int LuaEntitySAO::punch(v3f dir, ...@@ -475,10 +470,10 @@ int LuaEntitySAO::punch(v3f dir,
void LuaEntitySAO::rightClick(ServerActiveObject *clicker) void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
{ {
if(!m_registered) if (!m_registered)
return; return;
// It's best that attachments cannot be clicked // It's best that attachments cannot be clicked
if(isAttached()) if (isAttached())
return; return;
m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker); m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment