From 72c3f87925bc08f6d07869cca1ac4ae171eb44ab Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 12 May 2023 15:33:49 +0100 Subject: [PATCH] Reduce excessive mob overhead --- mods/ENTITIES/mcl_mobs/api.lua | 7 +++++-- mods/ENTITIES/mcl_mobs/effects.lua | 6 +++--- mods/ENTITIES/mcl_mobs/movement.lua | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 9c0beaeec..092c8939c 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -407,8 +407,11 @@ local function on_step_work (self, dtime) self:check_water_flow() self:env_danger_movement_checks (dtime) - -- Follow code is heavy and probably shouldn't run when not in range, but we need to extract the cancel follow stuff - self:check_follow() + if player_in_active_range then + if mcl_util.check_dtime_timer(self, dtime, "onstep_follow", 0.2) then + self:check_follow() + end + end self:flop() self:check_smooth_rotation(dtime) diff --git a/mods/ENTITIES/mcl_mobs/effects.lua b/mods/ENTITIES/mcl_mobs/effects.lua index 696994d0d..1a1578834 100644 --- a/mods/ENTITIES/mcl_mobs/effects.lua +++ b/mods/ENTITIES/mcl_mobs/effects.lua @@ -269,7 +269,7 @@ function mob_class:set_animation(anim, fixed_frame) - if self:flight_check() and self.fly and anim == "walk" then anim = "fly" end + if self.fly and self:flight_check() and anim == "walk" then anim = "fly" end self._current_animation = self._current_animation or "" @@ -324,12 +324,12 @@ local function who_are_you_looking_at (self) self._locked_object = nil end elseif not self._locked_object then - if math.random(1, 30) then + if mcl_util.check_dtime_timer(self, dtime, "step_look_for_someone", 0.2) then --minetest.log("Change look check: ".. self.name) -- For the wither this was 20/60=0.33, so probably need to rebalance and divide rates. -- but frequency of check isn't good as it is costly. Making others too infrequent requires testing - local chance = 20/self.curiosity + local chance = 150/self.curiosity if chance < 1 then chance = 1 end local look_at_player_chance = math.random(chance) diff --git a/mods/ENTITIES/mcl_mobs/movement.lua b/mods/ENTITIES/mcl_mobs/movement.lua index 469ac9e85..21595ef54 100644 --- a/mods/ENTITIES/mcl_mobs/movement.lua +++ b/mods/ENTITIES/mcl_mobs/movement.lua @@ -623,7 +623,7 @@ function mob_class:check_runaway_from() end --- follow player if owner or holding item, if fish outta water then flop +-- follow player if owner or holding item function mob_class:check_follow() -- find player to follow if (self.follow ~= "" or self.order == "follow") and not self.following