1
0
Fork 0

Redo the death effect

objects
Wuzzy 2020-12-05 04:33:23 +01:00
parent 411e180477
commit ed3afc6e49
10 changed files with 71 additions and 59 deletions

View File

@ -9,6 +9,7 @@ local MAX_MOB_NAME_LENGTH = 30
local HORNY_TIME = 30
local HORNY_AGAIN_TIME = 300
local CHILD_GROW_TIME = 60*20
local DEATH_DELAY = 0.5
local MOB_CAP = {}
MOB_CAP.hostile = 70
@ -334,7 +335,7 @@ local remove_texture_mod = function(self, mod)
end
-- set defined animation
local set_animation = function(self, anim)
local set_animation = function(self, anim, fixed_frame)
if not self.animation
or not anim then return end
@ -349,9 +350,17 @@ local set_animation = function(self, anim)
self.animation.current = anim
local a_start = self.animation[anim .. "_start"]
local a_end
if fixed_frame then
a_end = a_start
else
a_end = self.animation[anim .. "_end"]
end
self.object:set_animation({
x = self.animation[anim .. "_start"],
y = self.animation[anim .. "_end"]},
x = a_start,
y = a_end},
self.animation[anim .. "_speed"] or self.animation.speed_normal or 15,
0, self.animation[anim .. "_loop"] ~= false)
end
@ -669,6 +678,10 @@ end
-- check if mob is dead or only hurt
local check_for_death = function(self, cause, cmi_cause)
if self.state == "die" then
return true
end
-- has health actually changed?
if self.health == self.old_health and self.health > 0 then
return false
@ -713,33 +726,39 @@ local check_for_death = function(self, cause, cmi_cause)
return false
end
-- dropped cooked item if mob died in fire or lava
if cause == "lava" or cause == "fire" then
item_drop(self, true)
else
item_drop(self, nil)
end
mob_sound(self, "death")
local pos = self.object:get_pos()
local function death_handle(self)
-- dropped cooked item if mob died in fire or lava
if cause == "lava" or cause == "fire" then
item_drop(self, true)
else
item_drop(self, nil)
end
if mod_experience and self.hp_min and self.hp_max then
mcl_experience.throw_experience(pos, math.ceil( math.random(self.hp_min,self.hp_max+5) / 5) )
local pos = self.object:get_pos()
if mod_experience and self.hp_min and self.hp_max then
mcl_experience.throw_experience(pos, math.ceil( math.random(self.hp_min,self.hp_max+5) / 5) )
end
end
-- execute custom death function
if self.on_die then
self.on_die(self, pos)
death_handle(self)
local pos = self.object:get_pos()
local on_die_exit = self.on_die(self, pos)
if use_cmi then
cmi.notify_die(self.object, cmi_cause)
end
self.object:remove()
return true
if on_die_exit == true then
self.object:remove()
return true
end
end
local collisionbox
@ -747,6 +766,7 @@ local check_for_death = function(self, cause, cmi_cause)
collisionbox = table.copy(self.collisionbox)
end
local length = 0
-- default death function and die animation (if defined)
if self.animation
and self.animation.die_start
@ -754,40 +774,41 @@ local check_for_death = function(self, cause, cmi_cause)
local frames = self.animation.die_end - self.animation.die_start
local speed = self.animation.die_speed or 15
local length = max(frames / speed, 0)
self.attack = nil
self.v_start = false
self.timer = 0
self.blinktimer = 0
self.passive = true
self.state = "die"
self.object:set_properties({
pointable = false,
})
set_velocity(self, 0)
length = max(frames / speed, 0) + DEATH_DELAY
set_animation(self, "die")
minetest.after(length, function(self)
if not self.object:get_luaentity() then
return
end
if use_cmi then
cmi.notify_die(self.object, cmi_cause)
end
self.object:remove()
mobs.death_effect(pos)
end, self)
else
local rot = self.object:get_rotation()
rot.z = math.pi/2
self.object:set_rotation(rot)
length = 1 + DEATH_DELAY
set_animation(self, "stand", true)
end
if use_cmi then
self.attack = nil
self.v_start = false
self.timer = 0
self.blinktimer = 0
self.passive = true
self.state = "die"
self.object:set_properties({
pointable = false,
})
set_velocity(self, 0)
minetest.after(length, function(self)
if not self.object:get_luaentity() then
return
end
if use_cmi then
cmi.notify_die(self.object, cmi_cause)
end
death_handle(self)
local dpos = self.object:get_pos()
self.object:remove()
mobs.death_effect(pos, collisionbox)
end
mobs.death_effect(dpos)
end, self)
return true
end
@ -2690,7 +2711,7 @@ end
-- returns true if mob died
local falling = function(self, pos)
if self.fly then
if self.fly and self.state ~= "die" then
return
end

View File

@ -284,10 +284,9 @@ Custom Definition Functions
Along with the above mob registry settings we can also use custom functions to
enhance mob functionality and have them do many interesting things:
'on_die' a function that is called when the mob is killed the
parameters are (self, pos). When this function is used,
the death particles will be skipped on death. You can get
them back by calling mobs:death_effect manually
'on_die' a function that is called when the mob is killed; the
parameters are (self, pos). Return true to skip the builtin
death animation and death effects
'on_rightclick' its same as in minetest.register_entity()
'on_blast' is called when an explosion happens near mob when using TNT
functions, parameters are (object, damage) and returns

View File

@ -33,12 +33,10 @@ mobs:register_mob("mobs_mc:bat", {
run_speed = 80,
run_start = 0,
run_end = 40,
-- TODO: Less ugly death animation
--[[ die_speed = 60,
die_speed = 60,
die_start = 40,
die_end = 80,
die_loop = false,
]]
},
walk_chance = 100,
fall_damage = 0,

View File

@ -81,7 +81,6 @@ mobs:register_mob("mobs_mc:creeper", {
local r = math.random(1, #mobs_mc.items.music_discs)
minetest.add_item({x=pos.x, y=pos.y+1, z=pos.z}, mobs_mc.items.music_discs[r])
end
mobs.death_effect(pos, self.collisionbox)
end,
maxdrops = 2,
drops = {

View File

@ -507,7 +507,6 @@ mobs:register_mob("mobs_mc:enderman", {
if self._taken_node ~= nil and self._taken_node ~= "" then
minetest.add_item(pos, self._taken_node)
end
mobs.death_effect(pos, self.collisionbox)
end,
do_punch = function(self, hitter, tflp, tool_caps, dir)
-- damage from rain caused by itself so we don't want it to attack itself.

View File

@ -175,8 +175,6 @@ local horse = {
mobs.detach(self.driver, {x = 1, y = 0, z = 1})
end
mobs.death_effect(pos, self.collisionbox)
end,
on_rightclick = function(self, clicker)

View File

@ -111,7 +111,6 @@ mobs:register_mob("mobs_mc:llama", {
if self.driver then
mobs.detach(self.driver, {x = 1, y = 0, z = 1})
end
mobs.death_effect(pos, self.collisionbox)
end,

View File

@ -79,7 +79,6 @@ mobs:register_mob("mobs_mc:pig", {
if self.driver then
mobs.detach(self.driver, {x = 1, y = 0, z = 1})
end
mobs.death_effect(pos, self.collisionbox)
end,
on_rightclick = function(self, clicker)

View File

@ -51,6 +51,7 @@ local spawn_children_on_die = function(child_mob, children_count, spawn_distance
end
end, children, self.attack)
end
return true
end
end

View File

@ -1053,7 +1053,6 @@ mobs:register_mob("mobs_mc:villager", {
return_fields(player)
end
end
mobs.death_effect(pos, self.collisionbox)
end,
})