From 01c8009c6acf23d47e230ae1a1c98caa4d42bc94 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 6 Jan 2023 23:39:56 +0000 Subject: [PATCH] Tidy on_step function --- mods/ENTITIES/mcl_mobs/api.lua | 27 ++++++++++++--------------- mods/ENTITIES/mcl_mobs/spawning.lua | 4 +++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index e9265d36b..05c6ed9c6 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -306,7 +306,7 @@ function mob_class:do_states(dtime) end local function update_timers (self, dtime) - -- knockback timer + -- knockback timer. set in on_punch if self.pause_timer > 0 then self.pause_timer = self.pause_timer - dtime return true @@ -330,17 +330,15 @@ end -- main mob function function mob_class:on_step(dtime) - self.lifetimer = self.lifetimer - dtime - local pos = self.object:get_pos() if not pos then return end - if self:check_despawn(pos) then return true end + if self:check_despawn(pos, dtime) then return true end self:slow_mob() if self:falling(pos) then return end - self:check_suspend() + self:check_water_flow() self:env_danger_movement_checks (dtime) @@ -355,21 +353,17 @@ function mob_class:on_step(dtime) if self.state == "die" then return end - if self.jump_sound_cooloff > 0 then - self.jump_sound_cooloff = self.jump_sound_cooloff - dtime - end - if self.opinion_sound_cooloff > 0 then - self.opinion_sound_cooloff = self.opinion_sound_cooloff - dtime - end + self:follow_flop() -- Mob following code. - --Mob following code. - self:follow_flop() - --set animation speed relitive to velocity - self:set_animation_speed() + self:set_animation_speed() -- set animation speed relitive to velocity self:check_smooth_rotation(dtime) self:check_head_swivel(dtime) + if self.jump_sound_cooloff > 0 then + self.jump_sound_cooloff = self.jump_sound_cooloff - dtime + end self:do_jump() + self:set_armor_texture() self:check_runaway_from() @@ -390,6 +384,9 @@ function mob_class:on_step(dtime) self:check_particlespawners(dtime) self:check_item_pickup() + if self.opinion_sound_cooloff > 0 then + self.opinion_sound_cooloff = self.opinion_sound_cooloff - dtime + end -- mob plays random sound at times. Should be 120. Zombie and mob farms are ridiculous if math.random(1, 70) == 1 then self:mob_sound("random", true) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 01ef2a823..ee1986073 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -722,7 +722,9 @@ if mobs_spawn then end) end -function mob_class:check_despawn(pos) +function mob_class:check_despawn(pos, dtime) + self.lifetimer = self.lifetimer - dtime + -- Despawning: when lifetimer expires, remove mob if remove_far and self.can_despawn == true