From 4c34a98ad53ecff261e04cff0407b59d8880f8ea Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Sun, 18 Aug 2024 19:32:22 +0200 Subject: [PATCH] Fix: Knockback calculation Now only our yaw rotation is broken but not the knockback calculation --- pumpkin/src/client/player_packet.rs | 8 +++++--- pumpkin/src/entity/player.rs | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index b06432cf5..36eaac5ca 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -1,3 +1,5 @@ +use std::f32::consts::PI; + use num_traits::FromPrimitive; use pumpkin_entity::EntityId; use pumpkin_protocol::{ @@ -284,12 +286,12 @@ impl Client { return; } if config.knockback { - let pitch = attacker_player.entity.pitch; + let yaw = attacker_player.entity.yaw; let strength = 1.0; player.knockback( strength * 0.5, - (pitch * 0.017453292).sin() as f64, - -(pitch * 0.017453292).cos() as f64, + (yaw * (PI / 180.0)).sin() as f64, + -(yaw * (PI / 180.0)).cos() as f64, ); let packet = &CEntityVelocity::new( &entity_id, diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 80f1e3438..81e14730e 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -53,21 +53,21 @@ impl Player { self.entity.entity_id } - pub fn knockback(&mut self, y: f64, x: f64, z: f64) { + pub fn knockback(&mut self, strength: f64, x: f64, z: f64) { // This has some vanilla magic let mut x = x; let mut z = z; - while x * x + z * z < 9.999999747378752E-6 { + while x * x + z * z < 1.0E-5 { x = (rand::random::() - rand::random::()) * 0.01; z = (rand::random::() - rand::random::()) * 0.01; } - let var8 = Vector3::new(x, 0.0, z).normalize() * y; + let var8 = Vector3::new(x, 0.0, z).normalize() * strength; let var7 = self.velocity; self.velocity = Vector3::new( var7.x / 2.0 - var8.x, if self.on_ground { - (var7.y / 2.0 + x).min(0.4) + (var7.y / 2.0 + strength).min(0.4) } else { var7.y },