Fix: Knockback calculation
Now only our yaw rotation is broken but not the knockback calculation
This commit is contained in:
parent
c7b3ce6391
commit
4c34a98ad5
@ -1,3 +1,5 @@
|
|||||||
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use pumpkin_entity::EntityId;
|
use pumpkin_entity::EntityId;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
@ -284,12 +286,12 @@ impl Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if config.knockback {
|
if config.knockback {
|
||||||
let pitch = attacker_player.entity.pitch;
|
let yaw = attacker_player.entity.yaw;
|
||||||
let strength = 1.0;
|
let strength = 1.0;
|
||||||
player.knockback(
|
player.knockback(
|
||||||
strength * 0.5,
|
strength * 0.5,
|
||||||
(pitch * 0.017453292).sin() as f64,
|
(yaw * (PI / 180.0)).sin() as f64,
|
||||||
-(pitch * 0.017453292).cos() as f64,
|
-(yaw * (PI / 180.0)).cos() as f64,
|
||||||
);
|
);
|
||||||
let packet = &CEntityVelocity::new(
|
let packet = &CEntityVelocity::new(
|
||||||
&entity_id,
|
&entity_id,
|
||||||
|
|||||||
@ -53,21 +53,21 @@ impl Player {
|
|||||||
self.entity.entity_id
|
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
|
// This has some vanilla magic
|
||||||
let mut x = x;
|
let mut x = x;
|
||||||
let mut z = z;
|
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;
|
x = (rand::random::<f64>() - rand::random::<f64>()) * 0.01;
|
||||||
z = (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;
|
let var7 = self.velocity;
|
||||||
self.velocity = Vector3::new(
|
self.velocity = Vector3::new(
|
||||||
var7.x / 2.0 - var8.x,
|
var7.x / 2.0 - var8.x,
|
||||||
if self.on_ground {
|
if self.on_ground {
|
||||||
(var7.y / 2.0 + x).min(0.4)
|
(var7.y / 2.0 + strength).min(0.4)
|
||||||
} else {
|
} else {
|
||||||
var7.y
|
var7.y
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user