Skip to content

Commit bb5f830

Browse files
SmallJokerest31
authored andcommittedJun 14, 2015
Ignore punches with no damage in the actionstream
1 parent ecdfbfc commit bb5f830

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed
 

‎src/content_sao.cpp

+18-23
Original file line numberDiff line numberDiff line change
@@ -419,19 +419,19 @@ int LuaEntitySAO::punch(v3f dir,
419419
ServerActiveObject *puncher,
420420
float time_from_last_punch)
421421
{
422-
if(!m_registered){
422+
if (!m_registered){
423423
// Delete unknown LuaEntities when punched
424424
m_removed = true;
425425
return 0;
426426
}
427427

428428
// It's best that attachments cannot be punched
429-
if(isAttached())
429+
if (isAttached())
430430
return 0;
431431

432432
ItemStack *punchitem = NULL;
433433
ItemStack punchitem_static;
434-
if(puncher){
434+
if (puncher) {
435435
punchitem_static = puncher->getWieldedItem();
436436
punchitem = &punchitem_static;
437437
}
@@ -442,31 +442,26 @@ int LuaEntitySAO::punch(v3f dir,
442442
punchitem,
443443
time_from_last_punch);
444444

445-
if(result.did_punch)
446-
{
445+
if (result.did_punch) {
447446
setHP(getHP() - result.damage);
448447

448+
if (result.damage > 0) {
449+
std::string punchername = puncher ? puncher->getDescription() : "nil";
449450

450-
std::string punchername = "nil";
451-
452-
if ( puncher != 0 )
453-
punchername = puncher->getDescription();
454-
455-
actionstream<<getDescription()<<" punched by "
456-
<<punchername<<", damage "<<result.damage
457-
<<" hp, health now "<<getHP()<<" hp"<<std::endl;
458-
459-
{
460-
std::string str = gob_cmd_punched(result.damage, getHP());
461-
// create message and add to list
462-
ActiveObjectMessage aom(getId(), true, str);
463-
m_messages_out.push(aom);
451+
actionstream << getDescription() << " punched by "
452+
<< punchername << ", damage " << result.damage
453+
<< " hp, health now " << getHP() << " hp" << std::endl;
464454
}
465455

466-
if(getHP() == 0)
467-
m_removed = true;
456+
std::string str = gob_cmd_punched(result.damage, getHP());
457+
// create message and add to list
458+
ActiveObjectMessage aom(getId(), true, str);
459+
m_messages_out.push(aom);
468460
}
469461

462+
if (getHP() == 0)
463+
m_removed = true;
464+
470465
m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
471466
time_from_last_punch, toolcap, dir);
472467

@@ -475,10 +470,10 @@ int LuaEntitySAO::punch(v3f dir,
475470

476471
void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
477472
{
478-
if(!m_registered)
473+
if (!m_registered)
479474
return;
480475
// It's best that attachments cannot be clicked
481-
if(isAttached())
476+
if (isAttached())
482477
return;
483478
m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker);
484479
}

0 commit comments

Comments
 (0)
Please sign in to comment.