From 87462ee8536e5f48695e63b2eb300e24af750e21 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 19 Mar 2021 09:11:12 +0100 Subject: [PATCH] Add apply_knockback (WIP) --- mods/CORE/mcl_object/init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mods/CORE/mcl_object/init.lua b/mods/CORE/mcl_object/init.lua index 2953662c4..82389b151 100644 --- a/mods/CORE/mcl_object/init.lua +++ b/mods/CORE/mcl_object/init.lua @@ -19,6 +19,22 @@ function MCLObject:on_punch(hitter, time_from_last_punch, tool_capabilities, dir return true end +function MCLObject:apply_knockback(strength, dir) + local oldvel = self.object:get_velocity() + local vel = vector.multiply(vector.normalize(vector.new(dir.x, 0, dir.z)), strength) + + if self:is_on_ground() then + local old_y = oldvel.y / 2 + + y = math.min(0.4, old_y / 2 + strenth) + vel.y + end + + vel = vector.subtract(vel, vector.divide(vector.new(oldvel.x, 0, oldvel.z), 2)) + + self.object:add_velocity(vel) +end + -- use this function to deal regular damage to an object (do NOT use :punch() unless toolcaps need to be handled) function MCLObject:damage(damage, source, knockback) damage = self:damage_modifier(damage, source) or damage