@@ -419,19 +419,19 @@ int LuaEntitySAO::punch(v3f dir,
419
419
ServerActiveObject *puncher,
420
420
float time_from_last_punch)
421
421
{
422
- if (!m_registered){
422
+ if (!m_registered){
423
423
// Delete unknown LuaEntities when punched
424
424
m_removed = true ;
425
425
return 0 ;
426
426
}
427
427
428
428
// It's best that attachments cannot be punched
429
- if (isAttached ())
429
+ if (isAttached ())
430
430
return 0 ;
431
431
432
432
ItemStack *punchitem = NULL ;
433
433
ItemStack punchitem_static;
434
- if (puncher){
434
+ if (puncher) {
435
435
punchitem_static = puncher->getWieldedItem ();
436
436
punchitem = &punchitem_static;
437
437
}
@@ -442,31 +442,26 @@ int LuaEntitySAO::punch(v3f dir,
442
442
punchitem,
443
443
time_from_last_punch);
444
444
445
- if (result.did_punch )
446
- {
445
+ if (result.did_punch ) {
447
446
setHP (getHP () - result.damage );
448
447
448
+ if (result.damage > 0 ) {
449
+ std::string punchername = puncher ? puncher->getDescription () : " nil" ;
449
450
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;
464
454
}
465
455
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);
468
460
}
469
461
462
+ if (getHP () == 0 )
463
+ m_removed = true ;
464
+
470
465
m_env->getScriptIface ()->luaentity_Punch (m_id, puncher,
471
466
time_from_last_punch, toolcap, dir);
472
467
@@ -475,10 +470,10 @@ int LuaEntitySAO::punch(v3f dir,
475
470
476
471
void LuaEntitySAO::rightClick (ServerActiveObject *clicker)
477
472
{
478
- if (!m_registered)
473
+ if (!m_registered)
479
474
return ;
480
475
// It's best that attachments cannot be clicked
481
- if (isAttached ())
476
+ if (isAttached ())
482
477
return ;
483
478
m_env->getScriptIface ()->luaentity_Rightclick (m_id, clicker);
484
479
}
0 commit comments