From 555935ff3d35d4ac28dad42f5facac0bbfe9b1c9 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sun, 25 Apr 2021 16:43:23 -0400 Subject: [PATCH] Implement basic fall damage --- .../mcl_mobs/api/mob_functions/ai.lua | 5 ++++ .../api/mob_functions/backup_code_api.lua | 27 ------------------- .../api/mob_functions/environment.lua | 14 ++++++++++ 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index 3fcc15fe53..bb54f5b955 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -187,6 +187,11 @@ local land_state_execution = function(self,dtime) end end + --calculate fall damage + if self.fall_damage then + mobs.calculate_fall_damage(self) + end + if self.state == "stand" then --do animation diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua index 43cbc5419a..202da48ced 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua @@ -279,33 +279,6 @@ local falling = function(self, pos) end 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 diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua index 5656a16680..7c709c09e6 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua @@ -15,6 +15,8 @@ local vector_distance = vector.distance local table_copy = table.copy +local math_abs = math.abs + -- default function when mobs are blown up with TNT local do_tnt = function(obj, damage) @@ -243,4 +245,16 @@ mobs.get_2d_distance = function(pos1,pos2) pos1.y = 0 pos2.y = 0 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 \ No newline at end of file