From 751c4c2d995a011a3298d374c77b9c4567ed2fa1 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Tue, 20 Apr 2021 22:41:13 -0400 Subject: [PATCH] Integrate mob punching into collision detection --- .../api/mob_functions/attack_type_instructions.lua | 9 ++++++++- .../mcl_mobs/api/mob_functions/collision.lua | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua index 873cc5d629..679ef5025a 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua @@ -90,7 +90,14 @@ mobs.punch_attack_walk = function(self,dtime) if self.punch_timer > 0 then self.punch_timer = self.punch_timer - dtime end +end - print(self.punch_timer) +mobs.punch_attack = function(self) + self.attacking:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = self.damage} + }, nil) + + self.punch_timer = self.punch_timer_cooloff end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua index 47c5611bfd..19d709329f 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua @@ -29,6 +29,13 @@ mobs.collision = function(self) local collision_count = 0 + + local check_for_attack = false + + if self.hostile and self.attacking then + check_for_attack = true + end + for _,object in ipairs(minetest_get_objects_inside_radius(pos, radius*1.25)) do if object and object ~= self.object and (object:is_player() or object:get_luaentity()._cmi_is_mob == true) then--and --don't collide with rider, rider don't collide with thing @@ -85,6 +92,13 @@ mobs.collision = function(self) if object:is_player() then vel2 = vector_multiply(vel2, 2.5) + + --integrate mob punching into collision detection + if check_for_attack and self.punch_timer <= 0 then + if object == self.attacking then + mobs.punch_attack(self) + end + end end self.object:add_velocity(vel1)