diff --git a/mods/ENTITIES/extra_mobs/piglin.lua b/mods/ENTITIES/extra_mobs/piglin.lua index bb111c7d75..babd6c476b 100644 --- a/mods/ENTITIES/extra_mobs/piglin.lua +++ b/mods/ENTITIES/extra_mobs/piglin.lua @@ -145,7 +145,7 @@ local piglin = { if mod_bows then -- 2-4 damage per arrow local dmg = math.max(4, math.random(2, 8)) - mcl_bows.shoot_arrow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + mobs.shoot_projectile_handling("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end end, shoot_interval = 1.2, diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 96d479b3ff..c7d92c1e66 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -161,6 +161,7 @@ dofile(api_path .. "attack_type_instructions.lua") dofile(api_path .. "sound_handling.lua") dofile(api_path .. "death_logic.lua") dofile(api_path .. "mob_effects.lua") +dofile(api_path .. "projectile_handling.lua") mobs.spawning_mobs = {} diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index f9f886edcd..5429ff8c54 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -670,7 +670,6 @@ mobs.mob_step = function(self, dtime) --do custom mob instructions if self.do_custom then - print("doing custom instructions") -- when false skip going any further if self.do_custom(self, dtime) == false then --this overrides internal lua collision detection diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/projectile_handling.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/projectile_handling.lua new file mode 100644 index 0000000000..63668c8212 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/projectile_handling.lua @@ -0,0 +1,41 @@ +local GRAVITY = minetest.settings:get("movement_gravity")-- + 9.81 + +mobs.shoot_projectile_handling = function(arrow_item, pos, dir, yaw, shooter, power, damage, is_critical, bow_stack, collectable) + local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, arrow_item.."_entity") + if power == nil then + power = 19 + end + if damage == nil then + damage = 3 + end + local knockback + if bow_stack then + local enchantments = mcl_enchanting.get_enchantments(bow_stack) + if enchantments.power then + damage = damage + (enchantments.power + 1) / 4 + end + if enchantments.punch then + knockback = enchantments.punch * 3 + end + if enchantments.flame then + mcl_burning.set_on_fire(obj, math.huge) + end + end + obj:set_velocity({x=dir.x*power, y=dir.y*power, z=dir.z*power}) + obj:set_acceleration({x=0, y=-GRAVITY, z=0}) + obj:set_yaw(yaw-math.pi/2) + local le = obj:get_luaentity() + le._shooter = shooter + le._damage = damage + le._is_critical = is_critical + le._startpos = pos + le._knockback = knockback + le._collectable = collectable + + --play custom shoot sound + if shooter ~= nil and shooter.shoot_sound then + minetest.sound_play(shooter.shoot_sound, {pos=pos, max_hear_distance=16}, true) + end + + return obj +end \ No newline at end of file diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index d88a84515c..0293152b1a 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -82,7 +82,7 @@ mobs:register_mob("mobs_mc:blaze", { shoot_arrow = function(self, pos, dir) -- 2-4 damage per arrow local dmg = math.random(2,4) - mcl_bows.shoot_arrow("mobs_mc:blaze_fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + mobs.shoot_projectile_handling("mobs_mc:blaze_fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end, do_custom = function(self) diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index 37de9a4ac1..289102395b 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -15,7 +15,7 @@ mobs:register_mob("mobs_mc:enderdragon", { shoot_arrow = function(self, pos, dir) -- 2-4 damage per arrow local dmg = math.random(2,4) - mcl_bows.shoot_arrow("mobs_mc:dragon_fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + mobs.shoot_projectile_handling("mobs_mc:dragon_fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end, hp_max = 200, hp_min = 200, diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index d30504a649..c95d0282fc 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -64,7 +64,7 @@ mobs:register_mob("mobs_mc:ghast", { shoot_arrow = function(self, pos, dir) -- 2-4 damage per arrow local dmg = math.random(2,4) - mcl_bows.shoot_arrow("mobs_mc:fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + mobs.shoot_projectile_handling("mobs_mc:fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end, --[[ do_custom = function(self) diff --git a/mods/ENTITIES/mobs_mc/llama.lua b/mods/ENTITIES/mobs_mc/llama.lua index e0c353ad8b..75a08f0528 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -27,6 +27,15 @@ local carpets = { mobs:register_mob("mobs_mc:llama", { type = "animal", spawn_class = "passive", + rotate = 270, + neutral = true, + group_attack = true, + attack_type = "projectile", + shoot_arrow = function(self, pos, dir) + -- 2-4 damage per arrow + local dmg = 1 + mobs.shoot_projectile_handling("mobs_mc:spit", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + end, hp_min = 15, hp_max = 30, xp_min = 1, @@ -50,6 +59,7 @@ mobs:register_mob("mobs_mc:llama", { run_velocity = 4.4, follow_velocity = 4.4, floats = 1, + reach = 6, drops = { {name = mobs_mc.items.leather, chance = 1, @@ -235,3 +245,37 @@ mobs_mc.spawn_height.overworld_max) -- spawn eggs mobs:register_egg("mobs_mc:llama", S("Llama"), "mobs_mc_spawn_icon_llama.png", 0) + + +-- llama spit +mobs:register_arrow("mobs_mc:spit", { + visual = "sprite", + visual_size = {x = 0.3, y = 0.3}, + textures = {"mobs_mc_spit.png"}, + velocity = 1, + speed = 1, + tail = 1, + tail_texture = "mobs_mc_spit.png", + tail_size = 2, + + hit_player = function(self, player) + if rawget(_G, "armor") and armor.last_damage_types then + armor.last_damage_types[player:get_player_name()] = "spit" + end + player:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = self._damage}, + }, nil) + end, + + hit_mob = function(self, mob) + mob:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = _damage}, + }, nil) + end, + + hit_node = function(self, pos, node) + --does nothing + end +}) \ No newline at end of file diff --git a/mods/ENTITIES/mobs_mc/skeleton+stray.lua b/mods/ENTITIES/mobs_mc/skeleton+stray.lua index dfcab465ae..6f0d5c0b99 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -97,7 +97,7 @@ local skeleton = { if mod_bows then -- 2-4 damage per arrow local dmg = math.random(2,4) - mcl_bows.shoot_arrow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + mobs.shoot_projectile_handling("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end end, shoot_interval = 2, diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_spit.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_spit.png new file mode 100644 index 0000000000..6cdb3e0b3c Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_spit.png differ diff --git a/mods/ENTITIES/mobs_mc/villager_illusioner.lua b/mods/ENTITIES/mobs_mc/villager_illusioner.lua index e4642c847c..7716970fb7 100644 --- a/mods/ENTITIES/mobs_mc/villager_illusioner.lua +++ b/mods/ENTITIES/mobs_mc/villager_illusioner.lua @@ -17,7 +17,7 @@ mobs:register_mob("mobs_mc:illusioner", { if mod_bows then -- 1-4 damage per arrow local dmg = math.random(1, 4) - mcl_bows.shoot_arrow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + mobs.shoot_projectile_handling("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end end, hp_min = 32,