aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2020-11-12 19:15:41 +0100
committerGitHub <noreply@github.com>2020-11-12 19:15:41 +0100
commitadffef2b94f2d9cb3104cbc75e315cda3c0728aa (patch)
tree5dc237f6b7a217305aa5080ad83afcaf611dd19e /src
parentbe8d1d2d99ad835b5de7277b7b518c334113e795 (diff)
downloadminetest-adffef2b94f2d9cb3104cbc75e315cda3c0728aa.tar.gz
minetest-adffef2b94f2d9cb3104cbc75e315cda3c0728aa.tar.bz2
minetest-adffef2b94f2d9cb3104cbc75e315cda3c0728aa.zip
PlayerSAO: Run on_player_hpchange raw change values (#10478)
The callback is only run when a change in HP is to be expected. Following cases will not trigger the callback: * Dead player damaged further * Healing full-health player * Change of 0 HP
Diffstat (limited to 'src')
-rw-r--r--src/server/player_sao.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp
index 9fb53380c..62515d1c9 100644
--- a/src/server/player_sao.cpp
+++ b/src/server/player_sao.cpp
@@ -458,20 +458,25 @@ u16 PlayerSAO::punch(v3f dir,
void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
{
- s32 oldhp = m_hp;
+ if (hp == (s32)m_hp)
+ return; // Nothing to do
- hp = rangelim(hp, 0, m_prop.hp_max);
+ if (m_hp <= 0 && hp < (s32)m_hp)
+ return; // Cannot take more damage
- if (oldhp != hp) {
- s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason);
+ {
+ s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - m_hp, reason);
if (hp_change == 0)
return;
- hp = rangelim(oldhp + hp_change, 0, m_prop.hp_max);
+ hp = m_hp + hp_change;
}
+ s32 oldhp = m_hp;
+ hp = rangelim(hp, 0, m_prop.hp_max);
+
if (hp < oldhp && isImmortal())
- return;
+ return; // Do not allow immortal players to be damaged
m_hp = hp;