From c234b273ada8e9213bbff33909cef931f72d441c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 30 Jan 2020 16:12:25 +0100 Subject: [PATCH] Introduce snowball_vulnerable armor group --- mods/ENTITIES/mcl_mobs/api.lua | 9 ++++++++- mods/ENTITIES/mcl_mobs/api.txt | 8 ++++++-- mods/ENTITIES/mobs_mc/blaze.lua | 1 + mods/ITEMS/mcl_throwing/init.lua | 17 ++--------------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 36e6a945..fb838366 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2876,7 +2876,14 @@ local mob_activate = function(self, staticdata, def, dtime) self.path.stuck_timer = 0 -- if stuck for too long search for path -- mob defaults - self.object:set_armor_groups({immortal = 1, fleshy = self.armor}) + local armor + if type(self.armor) == "table" then + armor = table.copy(self.armor) + armor.immortal = 1 + else + armor = {immortal=1, fleshy = self.armor} + end + self.object:set_armor_groups(armor) self.old_y = self.object:get_pos().y self.old_health = self.health self.sounds.distance = self.sounds.distance or 10 diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index 7cc5725b..162772f0 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -35,8 +35,12 @@ functions needed for the mob to work properly which contains the following: 'breathes_in_water' If true, mob loses breath when not in water. Otherwise, mob loses breath when inside a node with `drowning` attribute set (default: false). - 'armor' holds strength of mob, 100 is normal, lower is more powerful - and needs more hits and better weapons to kill. + 'armor' entity armor groups (see lua_api.txt). If table, a list of + armor groups like for entities. If number, set value of + 'fleshy' armor group only. + Note: The 'immortal=1' armor group will automatically be added + since this mod handles health and damage manually. + Default: 100 (mob will take full dmg from 'fleshy' hits) 'passive' when true allows animals to defend themselves when hit, otherwise they amble onwards. 'walk_velocity' is the speed that your mob can walk around. diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index fad7765c..4562fea2 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -21,6 +21,7 @@ mobs:register_mob("mobs_mc:blaze", { textures = { {"mobs_mc_blaze.png"}, }, + armor = { fleshy = 100, snowball_vulnerable = 100 }, visual_size = {x=3, y=3}, sounds = { random = "mobs_mc_blaze_breath", diff --git a/mods/ITEMS/mcl_throwing/init.lua b/mods/ITEMS/mcl_throwing/init.lua index 5897a692..c997a394 100644 --- a/mods/ITEMS/mcl_throwing/init.lua +++ b/mods/ITEMS/mcl_throwing/init.lua @@ -145,7 +145,7 @@ local flying_bobber_ENTITY={ objtype="fishing", } -local check_object_hit = function(self, pos, mob_damage) +local check_object_hit = function(self, pos, dmg) for _,object in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do local entity = object:get_luaentity() @@ -158,11 +158,6 @@ local check_object_hit = function(self, pos, mob_damage) self.object:remove() return true elseif entity._cmi_is_mob == true and (self._thrower ~= object) then - local dmg = {} - if mob_damage then - dmg = mob_damage(entity.name) - end - -- FIXME: Knockback is broken object:punch(self.object, 1.0, { full_punch_interval = 1.0, @@ -193,15 +188,7 @@ local snowball_on_step = function(self, dtime) end end - local mob_damage = function(mobname) - if mobname == "mobs_mc:blaze" then - return {fleshy = 3} - else - return {} - end - end - - if check_object_hit(self, pos, mob_damage) then + if check_object_hit(self, pos, {snowball_vulnerable = 3}) then minetest.sound_play("mcl_throwing_snowball_impact_soft", { pos = self.object:get_pos(), max_hear_distance=16, gain=0.7 }) return end