From b7eda10054a78a66228e4275138914882296510b Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Sun, 16 Oct 2022 17:16:38 -0700 Subject: [PATCH] add better pvp knockback --- mods/ITEMS/mcl_enchanting/enchantments.lua | 14 ++++++++++++++ mods/PLAYER/mcl_player/init.lua | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index f137b4230..9fea7d3ee 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -130,6 +130,20 @@ mcl_enchanting.enchantments.fire_aspect = { minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage) if hitter and hitter:is_player() then local wielditem = hitter:get_wielded_item() + local p = player:get_pos() + if time_from_last_punch > 0.5 then + local yy=0 + if math.abs(player:get_velocity().y) < 0.1 then + yy=4 + end + player:get_meta():set_string("punched", tostring(minetest.get_gametime())) + minetest.after(0.4, function() + player:get_meta():set_string("punched", "0") + end) + + local d = hitter:get_look_dir() + player:add_velocity({x=d.x*4,y=yy,z=d.z*4}) + end if wielditem then local fire_aspect_level = mcl_enchanting.get_enchantment(wielditem, "fire_aspect") if fire_aspect_level > 0 then diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index e915efbe2..922ac2c69 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -91,7 +91,7 @@ local function update_player_textures(player) end player:set_properties({ textures = textures }) - + -- Delay calling the callbacks because mods (including mcl_player) -- need to fully initialize player data from minetest.register_on_joinplayer -- before callbacks run @@ -231,13 +231,21 @@ minetest.register_globalstep(function(dtime) local velocity = player:get_velocity() or player:get_player_velocity() + local mod_speed = 5 + if player:get_meta():get("punched") and tonumber(player:get_meta():get("punched")) > 0 then + mod_speed = 10 + end -- Apply animations based on what the player is doing if player:get_hp() == 0 then player_set_animation(player, "die") + elseif player:get_meta():get("punched") and tonumber(player:get_meta():get("punched")) > 0 then + player_set_animation(player, "run_walk", animation_speed_mod) + player:set_animation_frame_speed((math.abs(velocity.x)+math.abs(velocity.z))*mod_speed) elseif walking and velocity.x > 0.35 or walking and velocity.x < -0.35 or walking and velocity.z > 0.35 or walking and velocity.z < -0.35 then + player:set_animation_frame_speed((math.abs(velocity.x)+math.abs(velocity.z))*mod_speed) local wielded_itemname = player:get_wielded_item():get_name() local no_arm_moving = string.find(wielded_itemname, "mcl_bows:bow") or mcl_shields.wielding_shield(player, 1) or mcl_shields.wielding_shield(player, 2) if player_sneak[name] ~= controls.sneak then