From 5ecb56452e96f2e1257ca7daf6b7b5d6f8d6c5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 26 Jan 2021 14:13:21 +0100 Subject: [PATCH] Fix creeper explosions only doing 1/2 heart damage The solution was to move the creeper explosions to originate from the center of the creepers collisionbox and not its entity position. --- mods/CORE/mcl_util/init.lua | 11 ++++++++++- mods/ENTITIES/mcl_mobs/api.lua | 3 +-- mods/ENTITIES/mobs_mc/creeper.lua | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 7e851336..6c63c21a 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -395,4 +395,13 @@ function mcl_util.generate_on_place_plant_function(condition) end end - +-- adjust the y level of an object to the center of its collisionbox +-- used to get the origin position of entity explosions +function mcl_util.get_object_center(obj) + local collisionbox = obj:get_properties().collisionbox + local pos = obj:get_pos() + local ymin = collisionbox[2] + local ymax = collisionbox[5] + pos.y = pos.y + (ymax - ymin) / 2.0 + return pos +end diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 821dbc0e..33e049a8 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2258,7 +2258,6 @@ local dogswitch = function(self, dtime) return self.dogshoot_switch end - -- execute current state (stand, walk, run, attacks) -- returns true if mob has died local do_states = function(self, dtime) @@ -2550,7 +2549,7 @@ local do_states = function(self, dtime) if mod_explosions then if mobs_griefing and not minetest.is_protected(pos, "") then - mcl_explosions.explode(self.object:get_pos(), self.explosion_strength, { drop_chance = 1.0 }, self.object) + mcl_explosions.explode(mcl_util.get_object_center(self.object), self.explosion_strength, { drop_chance = 1.0 }, self.object) else minetest.sound_play(self.sounds.explode, { pos = pos, diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 2beffcf8..f1648525 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -71,7 +71,7 @@ mobs:register_mob("mobs_mc:creeper", { if self._forced_explosion_countdown_timer ~= nil then self._forced_explosion_countdown_timer = self._forced_explosion_countdown_timer - dtime if self._forced_explosion_countdown_timer <= 0 then - mobs:boom(self, self.object:get_pos(), self.explosion_strength) + mobs:boom(self, mcl_util.get_object_center(self.object), self.explosion_strength) self.object:remove() end end