Fix: Knockback calculation

Now only our yaw rotation is broken but not the knockback calculation
This commit is contained in:
Snowiiii
2024-08-18 19:32:22 +02:00
parent c7b3ce6391
commit 4c34a98ad5
2 changed files with 9 additions and 7 deletions

View File

@@ -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,

View File

@@ -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::<f64>() - rand::random::<f64>()) * 0.01;
z = (rand::random::<f64>() - rand::random::<f64>()) * 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
},