Add instant_death for mobs

This commit is contained in:
Wuzzy 2020-12-05 14:42:03 +01:00
parent e23bdca570
commit c0ef6e3d5a
3 changed files with 24 additions and 13 deletions

View File

@ -577,7 +577,7 @@ local damage_effect = function(self, damage)
end end
end end
mobs.death_effect = function(pos, yaw, collisionbox) mobs.death_effect = function(pos, yaw, collisionbox, rotate)
local min, max local min, max
if collisionbox then if collisionbox then
min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]}
@ -586,11 +586,13 @@ mobs.death_effect = function(pos, yaw, collisionbox)
min = { x = -0.5, y = 0, z = -0.5 } min = { x = -0.5, y = 0, z = -0.5 }
max = { x = 0.5, y = 0.5, z = 0.5 } max = { x = 0.5, y = 0.5, z = 0.5 }
end end
min = vector.rotate(min, {x=0, y=yaw, z=pi/2}) if rotate then
max = vector.rotate(max, {x=0, y=yaw, z=pi/2}) min = vector.rotate(min, {x=0, y=yaw, z=pi/2})
min, max = vector.sort(min, max) max = vector.rotate(max, {x=0, y=yaw, z=pi/2})
min = vector.multiply(min, 0.5) min, max = vector.sort(min, max)
max = vector.multiply(max, 0.5) min = vector.multiply(min, 0.5)
max = vector.multiply(max, 0.5)
end
minetest.add_particlespawner({ minetest.add_particlespawner({
amount = 50, amount = 50,
@ -802,12 +804,14 @@ local check_for_death = function(self, cause, cmi_cause)
}) })
set_velocity(self, 0) set_velocity(self, 0)
local acc = self.object:get_acceleration() local acc = self.object:get_acceleration()
acc.x, acc.z = 0, 0 acc.x, acc.y, acc.z = 0, DEFAULT_FALL_SPEED, 0
self.object:set_acceleration(acc) self.object:set_acceleration(acc)
local length = 0 local length
-- default death function and die animation (if defined) -- default death function and die animation (if defined)
if self.animation if self.instant_death then
length = 0
elseif self.animation
and self.animation.die_start and self.animation.die_start
and self.animation.die_end then and self.animation.die_end then
@ -825,7 +829,7 @@ local check_for_death = function(self, cause, cmi_cause)
-- Remove body after a few seconds and drop stuff -- Remove body after a few seconds and drop stuff
minetest.after(length, function(self) local kill = function(self)
if not self.object:get_luaentity() then if not self.object:get_luaentity() then
return return
end end
@ -838,9 +842,13 @@ local check_for_death = function(self, cause, cmi_cause)
local cbox = self.collisionbox local cbox = self.collisionbox
local yaw = self.object:get_rotation().y local yaw = self.object:get_rotation().y
self.object:remove() self.object:remove()
mobs.death_effect(dpos, yaw, cbox) mobs.death_effect(dpos, yaw, cbox, not self.instant_death)
end, self) end
if length <= 0 then
kill(self)
else
minetest.after(length, kill, self)
end
return true return true
end end
@ -3732,6 +3740,7 @@ minetest.register_entity(name, {
explosion_strength = def.explosion_strength, explosion_strength = def.explosion_strength,
suffocation_timer = 0, suffocation_timer = 0,
follow_velocity = def.follow_velocity or 2.4, follow_velocity = def.follow_velocity or 2.4,
instant_death = def.instant_death or false,
-- End of MCL2 extensions -- End of MCL2 extensions
on_spawn = def.on_spawn, on_spawn = def.on_spawn,

View File

@ -244,6 +244,7 @@ functions needed for the mob to work properly which contains the following:
'sounds_child' same as sounds, but for childs. If not defined, childs will use same 'sounds_child' same as sounds, but for childs. If not defined, childs will use same
sound as adults but with higher pitch sound as adults but with higher pitch
'follow_velocity' The speed at which a mob moves toward the player when they're holding the appropriate follow item. 'follow_velocity' The speed at which a mob moves toward the player when they're holding the appropriate follow item.
'instant_death' If true, mob dies instantly (no death animation or delay) (default: false)
Node Replacement Node Replacement

View File

@ -58,6 +58,7 @@ mobs:register_mob("mobs_mc:ghast", {
jump_height = 4, jump_height = 4,
floats=1, floats=1,
fly = true, fly = true,
instant_death = true,
}) })