1
0
Fork 0

Merge pull request 'Implement basic fall damage' (#1658) from jordan4ibanez/MineClone2:mineclone5 into mineclone5

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/1658
mineclone5
jordan4ibanez 2021-04-25 20:49:22 +00:00
commit d5da94d0de
3 changed files with 19 additions and 27 deletions

View File

@ -187,6 +187,11 @@ local land_state_execution = function(self,dtime)
end end
end end
--calculate fall damage
if self.fall_damage then
mobs.calculate_fall_damage(self)
end
if self.state == "stand" then if self.state == "stand" then
--do animation --do animation

View File

@ -279,33 +279,6 @@ local falling = function(self, pos)
end end
else else
-- fall damage onto solid ground
if self.fall_damage == 1
and self.object:get_velocity().y == 0 then
local d = (self.old_y or 0) - self.object:get_pos().y
if d > 5 then
local add = minetest_get_item_group(self.standing_on, "fall_damage_add_percent")
local damage = d - 5
if add ~= 0 then
damage = damage + damage * (add/100)
end
damage = math_floor(damage)
if damage > 0 then
self.health = self.health - damage
effect(pos, 5, "mcl_particles_smoke.png", 1, 2, 2, nil)
if check_for_death(self, "fall", {type = "fall"}) then
return true
end
end
end
self.old_y = self.object:get_pos().y
end
end end
end end

View File

@ -15,6 +15,8 @@ local vector_distance = vector.distance
local table_copy = table.copy local table_copy = table.copy
local math_abs = math.abs
-- default function when mobs are blown up with TNT -- default function when mobs are blown up with TNT
local do_tnt = function(obj, damage) local do_tnt = function(obj, damage)
@ -243,4 +245,16 @@ mobs.get_2d_distance = function(pos1,pos2)
pos1.y = 0 pos1.y = 0
pos2.y = 0 pos2.y = 0
return(vector_distance(pos1, pos2)) return(vector_distance(pos1, pos2))
end
-- fall damage onto solid ground
mobs.calculate_fall_damage = function(self)
if self.old_velocity and self.old_velocity.y < -7 and self.object:get_velocity().y == 0 then
local vel = self.object:get_velocity()
if vel then
local damage = math_abs(self.old_velocity.y + 7) * 2
self.pause_timer = 0.4
self.health = self.health - damage
end
end
end end