From 45ec87616705a596ea67c7f9af8d7a4b47cbb9be Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Tue, 7 Jun 2022 02:55:19 -0500 Subject: [PATCH] Knockback fixes: This PR enables knockback for snowballs, and eggs. And disables knockback for the following mobs: Shulkers, Iron Golems, and Ender Dragons. --- mods/ENTITIES/mcl_mobs/api.lua | 51 +++++++++++++------------- mods/ENTITIES/mobs_mc/ender_dragon.lua | 1 + mods/ENTITIES/mobs_mc/iron_golem.lua | 1 + mods/ENTITIES/mobs_mc/shulker.lua | 1 + mods/ITEMS/mcl_throwing/register.lua | 4 +- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 933634ccee..577c4c2aaa 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3210,35 +3210,36 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) local die = false - -- only play hit sound and show blood effects if damage is 1 or over; lower to 0.1 to ensure armor works appropriately. - if damage >= 0.1 then - -- weapon sounds - if weapon:get_definition().sounds ~= nil then + if damage >= 0 then + -- only play hit sound and show blood effects if damage is 1 or over; lower to 0.1 to ensure armor works appropriately. + if damage >= 0.1 then + -- weapon sounds + if weapon:get_definition().sounds ~= nil then - local s = random(0, #weapon:get_definition().sounds) + local s = random(0, #weapon:get_definition().sounds) - minetest.sound_play(weapon:get_definition().sounds[s], { - object = self.object, --hitter, - max_hear_distance = 8 - }, true) - else - minetest.sound_play("default_punch", { - object = self.object, - max_hear_distance = 5 - }, true) + minetest.sound_play(weapon:get_definition().sounds[s], { + object = self.object, --hitter, + max_hear_distance = 8 + }, true) + else + minetest.sound_play("default_punch", { + object = self.object, + max_hear_distance = 5 + }, true) + end + + damage_effect(self, damage) + + -- do damage + self.health = self.health - damage + + -- skip future functions if dead, except alerting others + if check_for_death(self, "hit", {type = "punch", puncher = hitter}) then + die = true + end end - - damage_effect(self, damage) - - -- do damage - self.health = self.health - damage - - -- skip future functions if dead, except alerting others - if check_for_death(self, "hit", {type = "punch", puncher = hitter}) then - die = true - end - -- knock back effect (only on full punch) if not die and self.knock_back diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index d2f971f79c..e7a233fc53 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -35,6 +35,7 @@ mcl_mobs:register_mob("mobs_mc:enderdragon", { }, physical = true, damage = 10, + knock_back = false, jump = true, jump_height = 14, fly = true, diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 7f1e667146..81c7ed4bbb 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -37,6 +37,7 @@ mcl_mobs:register_mob("mobs_mc:iron_golem", { run_velocity = 1.2, -- Approximation damage = 14, + knock_back = false, reach = 3, group_attack = true, attacks_monsters = true, diff --git a/mods/ENTITIES/mobs_mc/shulker.lua b/mods/ENTITIES/mobs_mc/shulker.lua index 5b3c4d2820..77273db2f7 100644 --- a/mods/ENTITIES/mobs_mc/shulker.lua +++ b/mods/ENTITIES/mobs_mc/shulker.lua @@ -33,6 +33,7 @@ mcl_mobs:register_mob("mobs_mc:shulker", { -- TODO: Make shulker dye-able visual_size = {x=3, y=3}, walk_chance = 0, + knock_back = false, jump = false, drops = { {name = "mcl_mobitems:shulker_shell", diff --git a/mods/ITEMS/mcl_throwing/register.lua b/mods/ITEMS/mcl_throwing/register.lua index 413bc9d5fc..53af28652b 100644 --- a/mods/ITEMS/mcl_throwing/register.lua +++ b/mods/ITEMS/mcl_throwing/register.lua @@ -61,11 +61,9 @@ local function check_object_hit(self, pos, dmg) and entity.name ~= self.object:get_luaentity().name then if object:is_player() and self._thrower ~= object:get_player_name() then - -- TODO: Deal knockback self.object:remove() return true elseif (entity.is_mob == true or entity._hittable_by_projectile) and (self._thrower ~= object) then - -- FIXME: Knockback is broken object:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = dmg, @@ -185,7 +183,7 @@ local function egg_on_step(self, dtime) end -- Destroy when hitting a mob or player (no chick spawning) - if check_object_hit(self, pos) then + if check_object_hit(self, pos, 0) then minetest.sound_play("mcl_throwing_egg_impact", { pos = self.object:get_pos(), max_hear_distance=10, gain=0.5 }, true) self.object:remove() return