Tweak mob death particles

This commit is contained in:
Wuzzy 2020-08-19 18:31:45 +02:00
parent 7c0c0d4d0c
commit 28aead0a60
9 changed files with 72 additions and 7 deletions

View File

@ -495,6 +495,31 @@ local damage_effect = function(self, damage)
end end
end end
mobs.death_effect = function(pos, collisionbox)
local min, max
if collisionbox then
min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]}
max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]}
else
min = { x = -0.5, y = 0, z = -0.5 }
max = { x = 0.5, y = 0.5, z = 0.5 }
end
minetest.add_particlespawner({
amount = 40,
time = 0.1,
minpos = vector.add(pos, min),
maxpos = vector.add(pos, max),
minvel = {x = -0.2, y = -0.1, z = -0.2},
maxvel = {x = 0.2, y = 0.1, z = 0.2},
minexptime = 0.5,
maxexptime = 1.5,
minsize = 0.5,
maxsize = 1.5,
texture = "tnt_smoke.png",
})
end
local update_tag = function(self) local update_tag = function(self)
self.object:set_properties({ self.object:set_properties({
nametag = self.nametag, nametag = self.nametag,
@ -629,6 +654,11 @@ local check_for_death = function(self, cause, cmi_cause)
return true return true
end end
local collisionbox
if self.collisionbox then
collisionbox = table.copy(self.collisionbox)
end
-- default death function and die animation (if defined) -- default death function and die animation (if defined)
if self.animation if self.animation
and self.animation.die_start and self.animation.die_start
@ -656,6 +686,7 @@ local check_for_death = function(self, cause, cmi_cause)
end end
self.object:remove() self.object:remove()
mobs.death_effect(pos)
end, self) end, self)
else else
@ -664,10 +695,9 @@ local check_for_death = function(self, cause, cmi_cause)
end end
self.object:remove() self.object:remove()
mobs.death_effect(pos, collisionbox)
end end
effect(pos, 20, "tnt_smoke.png")
return true return true
end end

View File

@ -283,7 +283,9 @@ Along with the above mob registry settings we can also use custom functions to
enhance mob functionality and have them do many interesting things: enhance mob functionality and have them do many interesting things:
'on_die' a function that is called when the mob is killed the 'on_die' a function that is called when the mob is killed the
parameters are (self, pos) 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_rightclick' its same as in minetest.register_entity() 'on_rightclick' its same as in minetest.register_entity()
'on_blast' is called when an explosion happens near mob when using TNT 'on_blast' is called when an explosion happens near mob when using TNT
functions, parameters are (object, damage) and returns functions, parameters are (object, damage) and returns
@ -410,6 +412,10 @@ This function spawns a mob as a child. The parameter mob_type is the
entitystring of the new mob. entitystring of the new mob.
This function returns the mob on success and nil otherwise. This function returns the mob on success and nil otherwise.
mobs:death_effect(pos, collisionbox)
Create death particles at pos with the given collisionbox.
Making Arrows Making Arrows
------------- -------------

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -128,6 +128,26 @@ mobs:register_mob("mobs_mc:snowman", {
end, end,
}) })
local summon_particles = function(obj)
local lua = obj:get_luaentity()
local min = {x=lua.collisionbox[1], y=lua.collisionbox[2], z=lua.collisionbox[3]}
local max = {x=lua.collisionbox[4], y=lua.collisionbox[5], z=lua.collisionbox[6]}
local pos = obj:get_pos()
minetest.add_particlespawner({
amount = 60,
time = 0.1,
minpos = vector.add(pos, min),
maxpos = vector.add(pos, max),
minvel = {x = -0.1, y = -0.1, z = -0.1},
maxvel = {x = 0.1, y = 0.1, z = 0.1},
minexptime = 1.0,
maxexptime = 2.0,
minsize = 2.0,
maxsize = 3.0,
texture = "tnt_smoke.png",
})
end
-- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function -- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function
-- of the node. -- of the node.
-- This summons a snow golen when pos is next to a row of two snow blocks. -- This summons a snow golen when pos is next to a row of two snow blocks.
@ -157,7 +177,10 @@ mobs_mc.tools.check_snow_golem_summon = function(pos)
core.check_for_falling(pos) core.check_for_falling(pos)
core.check_for_falling(b1) core.check_for_falling(b1)
core.check_for_falling(b2) core.check_for_falling(b2)
minetest.add_entity(place, "mobs_mc:snowman") local obj = minetest.add_entity(place, "mobs_mc:snowman")
if obj then
summon_particles(obj)
end
break break
end end
end end

View File

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