From 28aead0a60c1e7454a93a55d7ef168c25a840127 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 19 Aug 2020 18:31:45 +0200 Subject: [PATCH] Tweak mob death particles --- mods/ENTITIES/mcl_mobs/api.lua | 34 ++++++++++++++++++++++++++++-- mods/ENTITIES/mcl_mobs/api.txt | 8 ++++++- mods/ENTITIES/mobs_mc/creeper.lua | 1 + mods/ENTITIES/mobs_mc/enderman.lua | 5 +++-- mods/ENTITIES/mobs_mc/horse.lua | 2 ++ mods/ENTITIES/mobs_mc/llama.lua | 1 + mods/ENTITIES/mobs_mc/pig.lua | 2 +- mods/ENTITIES/mobs_mc/snowman.lua | 25 +++++++++++++++++++++- mods/ENTITIES/mobs_mc/villager.lua | 1 + 9 files changed, 72 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index ad112ef5..aa5809cd 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -495,6 +495,31 @@ local damage_effect = function(self, damage) 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) self.object:set_properties({ nametag = self.nametag, @@ -629,6 +654,11 @@ local check_for_death = function(self, cause, cmi_cause) return true end + local collisionbox + if self.collisionbox then + collisionbox = table.copy(self.collisionbox) + end + -- default death function and die animation (if defined) if self.animation and self.animation.die_start @@ -656,6 +686,7 @@ local check_for_death = function(self, cause, cmi_cause) end self.object:remove() + mobs.death_effect(pos) end, self) else @@ -664,10 +695,9 @@ local check_for_death = function(self, cause, cmi_cause) end self.object:remove() + mobs.death_effect(pos, collisionbox) end - effect(pos, 20, "tnt_smoke.png") - return true end diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index 8b7f7119..e585c995 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -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: '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_blast' is called when an explosion happens near mob when using TNT 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. 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 ------------- diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index c1d582bb..ddba6523 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -81,6 +81,7 @@ 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 = { diff --git a/mods/ENTITIES/mobs_mc/enderman.lua b/mods/ENTITIES/mobs_mc/enderman.lua index 3ecff4e3..3f62bdb2 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -267,8 +267,8 @@ mobs:register_mob("mobs_mc:enderman", { self.state = "" else if self.attack then - target = self.attack - pos = target:get_pos() + local target = self.attack + local pos = target:get_pos() if pos ~= nil then if vector.distance(self.object:get_pos(), target:get_pos()) > 10 then self:teleport(target) @@ -507,6 +507,7 @@ 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. diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index bb4a93e2..fd4926d2 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -175,6 +175,8 @@ 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) diff --git a/mods/ENTITIES/mobs_mc/llama.lua b/mods/ENTITIES/mobs_mc/llama.lua index 6391e867..8cb32a16 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -111,6 +111,7 @@ 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, diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index 259f45d9..3ed821b3 100644 --- a/mods/ENTITIES/mobs_mc/pig.lua +++ b/mods/ENTITIES/mobs_mc/pig.lua @@ -79,7 +79,7 @@ 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) diff --git a/mods/ENTITIES/mobs_mc/snowman.lua b/mods/ENTITIES/mobs_mc/snowman.lua index 02c1178e..983391e0 100644 --- a/mods/ENTITIES/mobs_mc/snowman.lua +++ b/mods/ENTITIES/mobs_mc/snowman.lua @@ -128,6 +128,26 @@ mobs:register_mob("mobs_mc:snowman", { 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 -- of the node. -- 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(b1) 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 end end diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 9788d58c..babb1d57 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1053,6 +1053,7 @@ mobs:register_mob("mobs_mc:villager", { return_fields(player) end end + mobs.death_effect(pos, self.collisionbox) end, })