From 4b9482cb0924574b318fe3b878d99adbd07fed0d Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Sun, 5 Feb 2023 05:34:32 +0000 Subject: [PATCH 1/3] Mobs should not drop XP when dying by fire from sunlight --- mods/ENTITIES/mcl_mobs/api.lua | 11 ++++++++++- mods/ENTITIES/mcl_mobs/physics.lua | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 1e7c9168b..6cc8d3d28 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -365,6 +365,9 @@ function mob_class:on_step(dtime) if self:check_despawn(pos, dtime) then return true end if self:outside_limits() then return end + -- Start: Death/damage processing + -- All damage needs to be undertaken at the start. + -- We need to exit processing if the mob dies. if self:check_death_and_slow_mob() then --minetest.log("action", "Mob is dying: ".. tostring(self.name)) -- Do we abandon out of here now? @@ -377,9 +380,16 @@ function mob_class:on_step(dtime) mcl_burning.tick(self.object, dtime, self) -- mcl_burning.tick may remove object immediately if not self.object:get_pos() then return end + + if self:check_for_death("fire", {type = "fire"}) then + return true + end end + if self:env_damage (dtime, pos) then return end + if self.state == "die" then return end + -- End: Death/damage processing self:check_water_flow() self:env_danger_movement_checks (dtime) @@ -425,7 +435,6 @@ function mob_class:on_step(dtime) self:mob_sound("random", true) end - if self:env_damage (dtime, pos) then return end if self:do_states(dtime) then return end if not self.object:get_luaentity() then diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 0c908b639..d4d3c836d 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -462,6 +462,14 @@ function mob_class:check_for_death(cause, cmi_cause) self:mob_sound("death") local function death_handle(self) + if cmi_cause and cmi_cause["type"] then + --minetest.log("cmi_cause: " .. tostring(cmi_cause["type"])) + end + --minetest.log("cause: " .. tostring(cause)) + + -- TODO other env damage shouldn't drop xp + -- "rain", "water", "drowning", "suffocation" + -- dropped cooked item if mob died in fire or lava if cause == "lava" or cause == "fire" then self:item_drop(true, 0) @@ -800,7 +808,7 @@ function mob_class:do_env_damage() self.suffocation_timer = 0 end - return self:check_for_death("", {type = "unknown"}) + return self:check_for_death("unknown", {type = "unknown"}) end function mob_class:env_damage (dtime, pos) From 39d4434df160bdc630c2329f2d35c7db7d33b3d0 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Sun, 5 Feb 2023 23:42:36 +0000 Subject: [PATCH 2/3] Reorder on_step calls --- mods/ENTITIES/mcl_mobs/api.lua | 35 +++++++++++++---------------- mods/ENTITIES/mcl_mobs/movement.lua | 8 ++++++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 6cc8d3d28..fa7cd3d4c 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -366,8 +366,7 @@ function mob_class:on_step(dtime) if self:outside_limits() then return end -- Start: Death/damage processing - -- All damage needs to be undertaken at the start. - -- We need to exit processing if the mob dies. + -- All damage needs to be undertaken at the start. We need to exit processing if the mob dies. if self:check_death_and_slow_mob() then --minetest.log("action", "Mob is dying: ".. tostring(self.name)) -- Do we abandon out of here now? @@ -378,8 +377,7 @@ function mob_class:on_step(dtime) if not self.fire_resistant then mcl_burning.tick(self.object, dtime, self) - -- mcl_burning.tick may remove object immediately - if not self.object:get_pos() then return end + if not self.object:get_pos() then return end -- mcl_burning.tick may remove object immediately if self:check_for_death("fire", {type = "fire"}) then return true @@ -394,38 +392,35 @@ function mob_class:on_step(dtime) self:check_water_flow() self:env_danger_movement_checks (dtime) - if mobs_debug then self:update_tag() end self:follow_flop() -- Mob following code. - self:set_animation_speed() -- set animation speed relitive to velocity + self:set_animation_speed() -- set animation speed relative 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 + 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() - 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 - if self.do_custom(self, dtime) == false then - return - end - end + self:check_breeding() + + self:check_item_pickup() + self:set_armor_texture() + + if self.do_custom and self.do_custom(self, dtime) == false then return end if update_timers(self, dtime) then return end self:check_particlespawners(dtime) - self:check_item_pickup() + + if self:env_damage (dtime, pos) then return end + if self:do_states(dtime) then return end if self.opinion_sound_cooloff > 0 then self.opinion_sound_cooloff = self.opinion_sound_cooloff - dtime @@ -437,6 +432,8 @@ function mob_class:on_step(dtime) if self:do_states(dtime) then return end + if mobs_debug then self:update_tag() end + if not self.object:get_luaentity() then return false end diff --git a/mods/ENTITIES/mcl_mobs/movement.lua b/mods/ENTITIES/mcl_mobs/movement.lua index 758e74467..4f174b300 100644 --- a/mods/ENTITIES/mcl_mobs/movement.lua +++ b/mods/ENTITIES/mcl_mobs/movement.lua @@ -239,9 +239,15 @@ function mob_class:is_at_water_danger() return false end local yaw = self.object:get_yaw() + local pos = self.object:get_pos() + + if not yaw or not pos then + return + end + local dir_x = -math.sin(yaw) * (self.collisionbox[4] + 0.5) local dir_z = math.cos(yaw) * (self.collisionbox[4] + 0.5) - local pos = self.object:get_pos() + local ypos = pos.y + self.collisionbox[2] -- just above floor local free_fall, blocker = minetest.line_of_sight( From b834e790a76fa8610df3548e67941e8552cb4663 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 6 Feb 2023 04:35:35 +0000 Subject: [PATCH 3/3] Fix game crashes --- mods/ENTITIES/mcl_mobs/effects.lua | 15 +++++++++++++-- mods/ENTITIES/mcl_mobs/physics.lua | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/effects.lua b/mods/ENTITIES/mcl_mobs/effects.lua index d4b071f93..a8b761d47 100644 --- a/mods/ENTITIES/mcl_mobs/effects.lua +++ b/mods/ENTITIES/mcl_mobs/effects.lua @@ -1,4 +1,4 @@ -local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs +local math, tonumber, vector, minetest, mcl_mobs = math, tonumber, vector, minetest, mcl_mobs local mob_class = mcl_mobs.mob_class local active_particlespawners = {} local disable_blood = minetest.settings:get_bool("mobs_disable_blood") @@ -8,6 +8,15 @@ local player_transfer_distance = tonumber(minetest.settings:get("player_transfer if player_transfer_distance == 0 then player_transfer_distance = math.huge end +local function validate_vector (vect) + if vect then + if tonumber(vect.x) and tonumber(vect.y) and tonumber(vect.z) then + return true + end + end + return false +end + -- custom particle effects function mcl_mobs.effect(pos, amount, texture, min_size, max_size, radius, gravity, glow, go_down) @@ -385,6 +394,8 @@ function mob_class:check_head_swivel(dtime) mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), final_rotation) end + + function mob_class:set_animation_speed() local v = self.object:get_velocity() if v then @@ -400,7 +411,7 @@ function mob_class:set_animation_speed() end end --set_speed - if self.acc then + if validate_vector(self.acc) then self.object:add_velocity(self.acc) end end diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index d4d3c836d..797bb4b7e 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -311,6 +311,8 @@ end function mob_class:set_yaw(yaw, delay, dtime) if self.noyaw then return end + if not self.object:get_yaw() or not self.object:get_pos() then return end + if self.state ~= PATHFINDING then self._turn_to = yaw end