From ffb1d39464b0fbc394607b1e0e204c71e14bf81d Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 14 Nov 2024 06:25:30 -0600 Subject: [PATCH] Correct damage for mob projectiles --- mods/ENTITIES/mcl_mobs/init.lua | 4 ++-- mods/ENTITIES/mobs_mc/blaze.lua | 11 +++-------- mods/ENTITIES/mobs_mc/ender_dragon.lua | 12 +++--------- mods/ENTITIES/mobs_mc/ghast.lua | 11 +++-------- mods/ENTITIES/mobs_mc/llama.lua | 7 +++---- mods/ENTITIES/mobs_mc/wither.lua | 11 +++-------- mods/ITEMS/vl_projectile/init.lua | 12 +++++++----- 7 files changed, 24 insertions(+), 44 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index 267d6603f..468d42af1 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -409,7 +409,7 @@ function mcl_mobs.register_arrow(name, def) switch = 0, _lifetime = def._lifetime or 7, owner_id = def.owner_id, - _vl_projectile = { + _vl_projectile = table.update(def._vl_projectile or {},{ behaviors = behaviors, ignore_gravity = true, damages_players = true, @@ -458,7 +458,7 @@ function mcl_mobs.register_arrow(name, def) return end end - }, + }), on_punch = def.on_punch or function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage) local vel = self.object:get_velocity():length() self.object:set_velocity(dir * vel) diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index a025479f8..f75236a5d 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -163,22 +163,17 @@ mcl_mobs.register_arrow("mobs_mc:blaze_fireball", { textures = {"mcl_fire_fire_charge.png"}, velocity = 15, _is_fireball = true, + _vl_projectile = { + damage_groups = {fleshy = 5} + }, -- Direct hit, no fire... just plenty of pain hit_player = function(self, player) mcl_burning.set_on_fire(player, 5) - player:punch(self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = 5}, - }, nil) end, hit_mob = function(self, mob) mcl_burning.set_on_fire(mob, 5) - mob:punch(self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = 5}, - }, nil) end, hit_object = function(self, object) diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index ea23f57a3..f74bc4bb5 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -155,21 +155,15 @@ mcl_mobs.register_arrow("mobs_mc:dragon_fireball", { visual_size = {x = 1.25, y = 1.25}, textures = {"mobs_mc_dragon_fireball.png"}, velocity = 6, + _vl_projectile = { + damage_groups = {fleshy = 12} + }, - -- direct hit, no fire... just plenty of pain hit_player = function(self, player) - player:punch(self.object, 1.0, { - full_punch_interval = 0.5, - damage_groups = {fleshy = 12}, - }, nil) end, hit_mob = function(self, mob) minetest.sound_play("tnt_explode", {pos = mob:get_pos(), gain = 1.5, max_hear_distance = 2*64}, true) - mob:punch(self.object, 1.0, { - full_punch_interval = 0.5, - damage_groups = {fleshy = 12}, - }, nil) end, -- node hit, explode diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index 9197c82f1..a4f1d160d 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -111,12 +111,11 @@ mcl_mobs.register_arrow("mobs_mc:fireball", { collisionbox = {-.5, -.5, -.5, .5, .5, .5}, _lifetime = 10, _is_fireball = true, + _vl_projectile = { + damage_groups = {fleshy = 6} + }, hit_player = function(self, player) - player:punch(self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = 6}, - }, nil) local p = self.object:get_pos() if p then mcl_mobs.mob_class.boom(self,p, 1, true) @@ -127,10 +126,6 @@ mcl_mobs.register_arrow("mobs_mc:fireball", { hit_mob = function(self, mob) local name = mob:get_luaentity().name - mob:punch(self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = 6}, - }, nil) mcl_mobs.mob_class.boom(self,self.object:get_pos(), 1, true) local ent = mob:get_luaentity() if (not ent or ent.health <= 0) and self._owner and minetest.get_player_by_name(self._owner) and name == "mobs_mc:ghast" then diff --git a/mods/ENTITIES/mobs_mc/llama.lua b/mods/ENTITIES/mobs_mc/llama.lua index 0379979ce..7756b3846 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -258,11 +258,10 @@ mcl_mobs.register_arrow("mobs_mc:llamaspit", { visual_size = {x = 0.10, y = 0.10}, textures = {"mobs_mc_llama_spit.png"}, velocity = 5, + _vl_projectile = { + damage_groups = {fleshy = 1} + }, hit_player = function(self, player) - player:punch(self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = 1}, - }, nil) end, hit_mob = function(self, mob) diff --git a/mods/ENTITIES/mobs_mc/wither.lua b/mods/ENTITIES/mobs_mc/wither.lua index b78b3766d..53373f96f 100644 --- a/mods/ENTITIES/mobs_mc/wither.lua +++ b/mods/ENTITIES/mobs_mc/wither.lua @@ -464,6 +464,9 @@ mcl_mobs.register_arrow("mobs_mc:wither_skull", { }, velocity = 7, _lifetime = 15, + _vl_projectile = { + damage_groups = {fleshy = 8}, + }, on_punch = function(self) end, allow_punching = function(self, _, _, object) local le = object and object:get_luaentity() @@ -474,10 +477,6 @@ mcl_mobs.register_arrow("mobs_mc:wither_skull", { hit_player = function(self, player) local pos = vector.new(self.object:get_pos()) mcl_potions.give_effect("withering", player, 2, 10) - player:punch(self.object, 1.0, { - full_punch_interval = 0.5, - damage_groups = {fleshy = 8}, - }, nil) mcl_mobs.mob_class.boom(self, pos, 1) if player:get_hp() <= 0 then local shooter = self._shooter:get_luaentity() @@ -489,10 +488,6 @@ mcl_mobs.register_arrow("mobs_mc:wither_skull", { hit_mob = function(self, mob) local pos = vector.new(self.object:get_pos()) mcl_potions.give_effect("withering", mob, 2, 10) - mob:punch(self.object, 1.0, { - full_punch_interval = 0.5, - damage_groups = {fleshy = 8}, - }, nil) mcl_mobs.mob_class.boom(self, pos, 1) local l = mob:get_luaentity() if l and l.health - 8 <= 0 then diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 0feff8ce1..3b0d81a1c 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -464,16 +464,12 @@ local function handle_entity_collision(self, entity_def, projectile_def, object) allow_punching = allow_punching, entity_def = entity_def, object = object, + object_id = mcl_util.get_entity_id(object), luaentity = object:get_luaentity(), })..")") end if not allow_punching then return end - -- Get damage - local dmg = projectile_def.damage_groups or 0 - if type(dmg) == "function" then - dmg = dmg(self, entity_def, projectile_def, object) - end local object_lua = object:get_luaentity() @@ -489,6 +485,12 @@ local function handle_entity_collision(self, entity_def, projectile_def, object) end if do_damage then + -- Get damage + local dmg = projectile_def.damage_groups or 0 + if type(dmg) == "function" then + dmg = dmg(self, entity_def, projectile_def, object) + end + object:punch(self.object, 1.0, projectile_def.tool or { full_punch_interval = 1.0, damage_groups = dmg }, dir ) -- Guard against crashes when projectiles get destroyed in response to what it punched