1
0
Fork 0

Merge pull request 'Mobs fix crash and not drop XP when dying by fire from sunlight' (#3398) from mob_death_xp_drop into master

Reviewed-on: MineClone2/MineClone2#3398
This commit is contained in:
ancientmarinerdev 2023-02-08 19:44:12 +00:00
commit 30bb1ab075
4 changed files with 55 additions and 22 deletions

View File

@ -365,6 +365,8 @@ function mob_class:on_step(dtime)
if self:check_despawn(pos, dtime) then return true end if self:check_despawn(pos, dtime) then return true end
if self:outside_limits() then return 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 if self:check_death_and_slow_mob() then
--minetest.log("action", "Mob is dying: ".. tostring(self.name)) --minetest.log("action", "Mob is dying: ".. tostring(self.name))
-- Do we abandon out of here now? -- Do we abandon out of here now?
@ -375,47 +377,50 @@ function mob_class:on_step(dtime)
if not self.fire_resistant then if not self.fire_resistant then
mcl_burning.tick(self.object, dtime, self) mcl_burning.tick(self.object, dtime, self)
-- mcl_burning.tick may remove object immediately if not self.object:get_pos() then return end -- 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 end
if self:env_damage (dtime, pos) then return end
if self.state == "die" then return end if self.state == "die" then return end
-- End: Death/damage processing
self:check_water_flow() self:check_water_flow()
self:env_danger_movement_checks (dtime) self:env_danger_movement_checks (dtime)
if mobs_debug then self:update_tag() end
self:follow_flop() -- Mob following code. 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_smooth_rotation(dtime)
self:check_head_swivel(dtime) self:check_head_swivel(dtime)
if self.jump_sound_cooloff > 0 then if self.jump_sound_cooloff > 0 then self.jump_sound_cooloff = self.jump_sound_cooloff - dtime end
self.jump_sound_cooloff = self.jump_sound_cooloff - dtime
end
self:do_jump() self:do_jump()
self:set_armor_texture()
self:check_runaway_from() self:check_runaway_from()
self:monster_attack() self:monster_attack()
self:npc_attack() self:npc_attack()
self:check_breeding()
self:check_aggro(dtime) self:check_aggro(dtime)
-- run custom function (defined in mob lua file) self:check_breeding()
if self.do_custom then
if self.do_custom(self, dtime) == false then self:check_item_pickup()
return self:set_armor_texture()
end
end if self.do_custom and self.do_custom(self, dtime) == false then return end
if update_timers(self, dtime) then return end if update_timers(self, dtime) then return end
self:check_particlespawners(dtime) 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 if self.opinion_sound_cooloff > 0 then
self.opinion_sound_cooloff = self.opinion_sound_cooloff - dtime self.opinion_sound_cooloff = self.opinion_sound_cooloff - dtime
@ -425,9 +430,10 @@ function mob_class:on_step(dtime)
self:mob_sound("random", true) self:mob_sound("random", true)
end end
if self:env_damage (dtime, pos) then return end
if self:do_states(dtime) then return end if self:do_states(dtime) then return end
if mobs_debug then self:update_tag() end
if not self.object:get_luaentity() then if not self.object:get_luaentity() then
return false return false
end end

View File

@ -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 mob_class = mcl_mobs.mob_class
local active_particlespawners = {} local active_particlespawners = {}
local disable_blood = minetest.settings:get_bool("mobs_disable_blood") 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 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 -- custom particle effects
function mcl_mobs.effect(pos, amount, texture, min_size, max_size, radius, gravity, glow, go_down) 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) mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), final_rotation)
end end
function mob_class:set_animation_speed() function mob_class:set_animation_speed()
local v = self.object:get_velocity() local v = self.object:get_velocity()
if v then if v then
@ -400,7 +411,7 @@ function mob_class:set_animation_speed()
end end
end end
--set_speed --set_speed
if self.acc then if validate_vector(self.acc) then
self.object:add_velocity(self.acc) self.object:add_velocity(self.acc)
end end
end end

View File

@ -239,9 +239,15 @@ function mob_class:is_at_water_danger()
return false return false
end end
local yaw = self.object:get_yaw() 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_x = -math.sin(yaw) * (self.collisionbox[4] + 0.5)
local dir_z = math.cos(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 ypos = pos.y + self.collisionbox[2] -- just above floor
local free_fall, blocker = minetest.line_of_sight( local free_fall, blocker = minetest.line_of_sight(

View File

@ -311,6 +311,8 @@ end
function mob_class:set_yaw(yaw, delay, dtime) function mob_class:set_yaw(yaw, delay, dtime)
if self.noyaw then return end 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 if self.state ~= PATHFINDING then
self._turn_to = yaw self._turn_to = yaw
end end
@ -462,6 +464,14 @@ function mob_class:check_for_death(cause, cmi_cause)
self:mob_sound("death") self:mob_sound("death")
local function death_handle(self) 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 -- dropped cooked item if mob died in fire or lava
if cause == "lava" or cause == "fire" then if cause == "lava" or cause == "fire" then
self:item_drop(true, 0) self:item_drop(true, 0)
@ -800,7 +810,7 @@ function mob_class:do_env_damage()
self.suffocation_timer = 0 self.suffocation_timer = 0
end end
return self:check_for_death("", {type = "unknown"}) return self:check_for_death("unknown", {type = "unknown"})
end end
function mob_class:env_damage (dtime, pos) function mob_class:env_damage (dtime, pos)