aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-05-21 10:18:38 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-05-21 11:18:38 +0200
commitae483f1bd00625216bb0a35370f0cc4568ad7893 (patch)
tree91549df6327bc8e2a6b2357626d7be77f3ec8522
parent4dc97eb99fdbeec186cce5b03c64fb1df319d19d (diff)
downloadminetest-ae483f1bd00625216bb0a35370f0cc4568ad7893.tar.gz
minetest-ae483f1bd00625216bb0a35370f0cc4568ad7893.tar.bz2
minetest-ae483f1bd00625216bb0a35370f0cc4568ad7893.zip
Prevent fall damage from overflowing when falling from a large height. (#5791)
-rw-r--r--src/clientenvironment.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/clientenvironment.cpp b/src/clientenvironment.cpp
index 47df49b84..cc7cb54dd 100644
--- a/src/clientenvironment.cpp
+++ b/src/clientenvironment.cpp
@@ -237,11 +237,10 @@ void ClientEnvironment::step(float dtime)
pre_factor = 1.0 + (float)addp/100.0;
}
float speed = pre_factor * speed_diff.getLength();
- if(speed > tolerance)
- {
- f32 damage_f = (speed - tolerance)/BS * post_factor;
- u16 damage = (u16)(damage_f+0.5);
- if(damage != 0){
+ if (speed > tolerance) {
+ f32 damage_f = (speed - tolerance) / BS * post_factor;
+ u8 damage = (u8)MYMIN(damage_f + 0.5, 255);
+ if (damage != 0) {
damageLocalPlayer(damage, true);
MtEvent *e = new SimpleTriggerEvent("PlayerFallingDamage");
m_client->event()->put(e);