From b401b50c045830386c1c06c22be2232bda3e5b61 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sat, 24 Apr 2021 21:15:42 -0400 Subject: [PATCH] Give mobs 6 seconds of memory to prevent strange behavior when player hides behind something --- mods/ENTITIES/mcl_mobs/api/api.lua | 2 ++ .../mcl_mobs/api/mob_functions/ai.lua | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 81c88a064..3a1fa8bff 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -328,6 +328,8 @@ function mobs:register_mob(name, def) minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath + memory = 0, -- memory timer if chasing/following + --for spiders always_climb = def.always_climb, diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index ee7ca0ecc..d8993ee50 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -899,23 +899,41 @@ mobs.mob_step = function(self, dtime) --go get the closest player if attacking then + self.memory = 6 --6 seconds of memory + --set initial punch timer if self.attacking == nil then if self.attack_type == "punch" then self.punch_timer = -1 end end - self.attacking = attacking - --no player in area - else - --reset states when coming out of hostile state - if self.attacking ~= nil then - self.state_timer = -1 + --no player in area + elseif self.memory > 0 then + --try to remember + self.memory = self.memory - dtime + --get if memory player is within viewing range + if self.attacking and self.attacking:is_player() then + local distance = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + if distance > self.view_range then + self.memory = 0 + end + --out of viewing range, forget em + else + self.memory = 0 end - self.attacking = nil + if self.memory <= 0 then + + --reset states when coming out of hostile state + if self.attacking ~= nil then + self.state_timer = -1 + end + + self.attacking = nil + self.memory = 0 + end end end