From 494ffb41d3751e3f39c5fc6e5991522eee6bd227 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 6 Nov 2020 15:05:31 +0100 Subject: [PATCH] Punch --- mods/CORE/mcl_enchanting/enchantments.lua | 10 ++++++++-- mods/ITEMS/mcl_bows/arrow.lua | 11 ++--------- mods/ITEMS/mcl_bows/bow.lua | 11 ++++++++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/mods/CORE/mcl_enchanting/enchantments.lua b/mods/CORE/mcl_enchanting/enchantments.lua index c143044a09..1da48f795c 100644 --- a/mods/CORE/mcl_enchanting/enchantments.lua +++ b/mods/CORE/mcl_enchanting/enchantments.lua @@ -174,7 +174,7 @@ mcl_enchanting.enchantments.fire_protection = { requires_tool = false, }]]-- --- unimplemented +-- implemented in mcl_item_entity mcl_enchanting.enchantments.fortune = { name = "Fortune", max_level = 4, @@ -254,9 +254,15 @@ mcl_enchanting.enchantments.knockback = { local old_calculate_knockback = minetest.calculate_knockback function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool_capabilities, dir, distance, damage) local knockback = old_calculate_knockback(player, hitter, time_from_last_punch, tool_capabilities, dir, distance, damage) + local luaentity + if hitter then + luaentity = hitter:get_luaentity() + end if hitter and hitter:is_player() then local wielditem = hitter:get_wielded_item() knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback") + elseif luaentity and luaentity._knockback then + knockback = knockback + luaentity._knockback end return knockback end @@ -366,7 +372,7 @@ mcl_enchanting.enchantments.protection = { requires_tool = false, } --- unimplemented +-- implemented via minetest.calculate_knockback (together with the Knockback enchantment) and mcl_bows mcl_enchanting.enchantments.punch = { name = "Punch", max_level = 2, diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 89f3405f36..0f603015e1 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -239,16 +239,9 @@ ARROW_ENTITY.on_step = function(self, dtime) end -- Punch target object but avoid hurting enderman. - if lua then - if lua.name ~= "mobs_mc:enderman" then - damage_particles(self.object:get_pos(), self._is_critical) - obj:punch(self.object, 1.0, { - full_punch_interval=1.0, - damage_groups={fleshy=self._damage}, - }, nil) - end - else + if not lua or lua.name ~= "mobs_mc:enderman" then damage_particles(self.object:get_pos(), self._is_critical) + self.object:set_pos(vector.subtract(obj:get_pos(), vector.multiply(vector.normalize(self.object:get_velocity()), 2))) obj:punch(self.object, 1.0, { full_punch_interval=1.0, damage_groups={fleshy=self._damage}, diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 4942d81a8f..fa2c2c5304 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -41,10 +41,14 @@ mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damag if damage == nil then damage = 3 end + local knockback if bow_stack then - local power_level = mcl_enchanting.get_enchantment(bow_stack, "power") - if power_level > 0 then - damage = damage + (power_level + 1) / 4 + 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 end obj:set_velocity({x=dir.x*power, y=dir.y*power, z=dir.z*power}) @@ -55,6 +59,7 @@ mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damag le._damage = damage le._is_critical = is_critical le._startpos = pos + le._knockback = knockback minetest.sound_play("mcl_bows_bow_shoot", {pos=pos}, true) if shooter ~= nil and shooter:is_player() then if obj:get_luaentity().player == "" then