From c0ef6e3d5ac3ee1f645b6b54bf17437d35d82e61 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 5 Dec 2020 14:42:03 +0100 Subject: [PATCH] Add instant_death for mobs --- mods/ENTITIES/mcl_mobs/api.lua | 35 +++++++++++++++++++++------------ mods/ENTITIES/mcl_mobs/api.txt | 1 + mods/ENTITIES/mobs_mc/ghast.lua | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 9b1971aef..f4c6e063b 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -577,7 +577,7 @@ local damage_effect = function(self, damage) end end -mobs.death_effect = function(pos, yaw, collisionbox) +mobs.death_effect = function(pos, yaw, collisionbox, rotate) local min, max if collisionbox then 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 } max = { x = 0.5, y = 0.5, z = 0.5 } end - min = vector.rotate(min, {x=0, y=yaw, z=pi/2}) - max = vector.rotate(max, {x=0, y=yaw, z=pi/2}) - min, max = vector.sort(min, max) - min = vector.multiply(min, 0.5) - max = vector.multiply(max, 0.5) + if rotate then + min = vector.rotate(min, {x=0, y=yaw, z=pi/2}) + max = vector.rotate(max, {x=0, y=yaw, z=pi/2}) + min, max = vector.sort(min, max) + min = vector.multiply(min, 0.5) + max = vector.multiply(max, 0.5) + end minetest.add_particlespawner({ amount = 50, @@ -802,12 +804,14 @@ local check_for_death = function(self, cause, cmi_cause) }) set_velocity(self, 0) 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) - local length = 0 + local length -- 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_end then @@ -825,7 +829,7 @@ local check_for_death = function(self, cause, cmi_cause) -- 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 return end @@ -838,9 +842,13 @@ local check_for_death = function(self, cause, cmi_cause) local cbox = self.collisionbox local yaw = self.object:get_rotation().y self.object:remove() - mobs.death_effect(dpos, yaw, cbox) - end, self) - + mobs.death_effect(dpos, yaw, cbox, not self.instant_death) + end + if length <= 0 then + kill(self) + else + minetest.after(length, kill, self) + end return true end @@ -3732,6 +3740,7 @@ minetest.register_entity(name, { explosion_strength = def.explosion_strength, suffocation_timer = 0, follow_velocity = def.follow_velocity or 2.4, + instant_death = def.instant_death or false, -- End of MCL2 extensions on_spawn = def.on_spawn, diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index 3ac66161e..6e790f2d5 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -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 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. + 'instant_death' If true, mob dies instantly (no death animation or delay) (default: false) Node Replacement diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index 27998d170..2259eb562 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -58,6 +58,7 @@ mobs:register_mob("mobs_mc:ghast", { jump_height = 4, floats=1, fly = true, + instant_death = true, })