From 4909ef6ff7bdf4905c465b2a60f9a7c8b89d3e0d Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 11 Nov 2022 23:57:17 +0100 Subject: [PATCH] Restructure on_step a bit --- mods/ENTITIES/mcl_mobs/api.lua | 68 +++++++++++++++--------------- mods/ENTITIES/mcl_mobs/physics.lua | 31 +++++++------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 083b648e4..935110447 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -297,6 +297,8 @@ function mob_class:mob_activate(staticdata, def, dtime) end end + + -- main mob function function mob_class:on_step(dtime) self.lifetimer = self.lifetimer - dtime @@ -315,7 +317,30 @@ function mob_class:on_step(dtime) if self:falling(pos) then return end self:check_suspend() - self:check_aggro(dtime) + self:check_water_flow() + + local yaw = 0 + if self:is_at_water_danger() and self.state ~= "attack" then + if math.random(1, 10) <= 6 then + self:set_velocity(0) + self.state = "stand" + self:set_animation( "stand") + yaw = yaw + math.random(-0.5, 0.5) + yaw = self:set_yaw( yaw, 8) + end + else + if self.move_in_group ~= false then + self:check_herd(dtime) + end + end + + if self:is_at_cliff_or_danger() then + self:set_velocity(0) + self.state = "stand" + self:set_animation( "stand") + local yaw = self.object:get_yaw() or 0 + yaw = self:set_yaw( yaw + 0.78, 8) + end if not self.fire_resistant then mcl_burning.tick(self.object, dtime, self) @@ -341,6 +366,15 @@ function mob_class:on_step(dtime) self:check_smooth_rotation() self:check_head_swivel() + self:do_jump() + self:set_armor_texture() + self:check_runaway_from() + + self:monster_attack() + self:npc_attack() + self:check_breeding() + self:check_aggro(dtime) + -- run custom function (defined in mob lua file) if self.do_custom then @@ -397,10 +431,6 @@ function mob_class:on_step(dtime) self:replace(pos) end - self:monster_attack() - self:npc_attack() - self:check_breeding() - if self:do_states(dtime) then return end @@ -408,34 +438,6 @@ function mob_class:on_step(dtime) if not self.object:get_luaentity() then return false end - - self:do_jump() - self:set_armor_texture() - self:check_runaway_from() - - local yaw = 0 - if self:is_at_water_danger() and self.state ~= "attack" then - if math.random(1, 10) <= 6 then - self:set_velocity(0) - self.state = "stand" - self:set_animation( "stand") - yaw = yaw + math.random(-0.5, 0.5) - yaw = self:set_yaw( yaw, 8) - end - else - if self.move_in_group ~= false then - self:check_herd(dtime) - end - end - self:check_water_flow() - - if self:is_at_cliff_or_danger() then - self:set_velocity(0) - self.state = "stand" - self:set_animation( "stand") - local yaw = self.object:get_yaw() or 0 - yaw = self:set_yaw( yaw + 0.78, 8) - end end local timer = 0 diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index c3bc7fbc6..1a393f505 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -552,9 +552,21 @@ function mob_class:check_for_death(cause, cmi_cause) return true end +-- Deal light damage to mob, returns true if mob died +function mob_class:deal_light_damage(pos, damage) + if not ((mcl_weather.rain.raining or mcl_weather.state == "snow") and mcl_weather.is_outdoor(pos)) then + self.health = self.health - damage + + mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png") + + if self:check_for_death("light", {type = "light"}) then + return true + end + end +end + -- environmental damage (water, lava, fire, light etc.) function mob_class:do_env_damage() - -- feed/tame text timer (so mob 'full' messages dont spam chat) if self.htimer > 0 then self.htimer = self.htimer - 1 @@ -580,19 +592,6 @@ function mob_class:do_env_damage() return true end - -- Deal light damage to mob, returns true if mob died - local function deal_light_damage(self, pos, damage) - if not ((mcl_weather.rain.raining or mcl_weather.state == "snow") and mcl_weather.is_outdoor(pos)) then - self.health = self.health - damage - - mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png") - - if self:check_for_death("light", {type = "light"}) then - return true - end - end - end - local sunlight = 10 if within_limits(pos,0) then sunlight = minetest.get_natural_light(pos, self.time_of_day) @@ -600,7 +599,7 @@ function mob_class:do_env_damage() -- bright light harms mob if self.light_damage ~= 0 and (sunlight or 0) > 12 then - if deal_light_damage(self, pos, self.light_damage) then + if self:deal_light_damage(pos, self.light_damage) then return true end end @@ -610,7 +609,7 @@ function mob_class:do_env_damage() if self.ignited_by_sunlight then mcl_burning.set_on_fire(self.object, 10) else - deal_light_damage(self, pos, self.sunlight_damage) + self:deal_light_damage(pos, self.sunlight_damage) return true end end