@@ -12,7 +12,7 @@ use hyperion::{
12
12
packets:: { BossBarAction , BossBarS2c } ,
13
13
} ,
14
14
simulation:: {
15
- PacketState , Player , Position , Velocity , event,
15
+ PacketState , Player , Position , Velocity , Yaw , event,
16
16
metadata:: { entity:: Pose , living_entity:: Health } ,
17
17
} ,
18
18
storage:: EventQueue ,
@@ -64,6 +64,7 @@ pub struct KillCount {
64
64
pub kill_count : u32 ,
65
65
}
66
66
67
+ #[ allow( clippy:: cast_possible_truncation) ]
67
68
impl Module for AttackModule {
68
69
#[ allow( clippy:: excessive_nesting) ]
69
70
fn module ( world : & World ) {
@@ -145,10 +146,11 @@ impl Module for AttackModule {
145
146
& mut Health ,
146
147
& mut Position ,
147
148
& mut Velocity ,
149
+ & Yaw ,
148
150
& CombatStats ,
149
151
& PlayerInventory
150
152
) > (
151
- |( immune_until, health, target_position, reaction, stats, target_inventory) | {
153
+ |( immune_until, health, target_position, reaction, target_yaw , stats, target_inventory) | {
152
154
if let Some ( immune_until) = immune_until {
153
155
if immune_until. tick > current_tick {
154
156
return ;
@@ -172,9 +174,15 @@ impl Module for AttackModule {
172
174
food : VarInt ( 20 ) ,
173
175
food_saturation : 5.0
174
176
} ;
177
+
178
+ let delta_x: f64 = f64:: from ( target_position. x - origin_pos. x ) ;
179
+ let delta_z: f64 = f64:: from ( target_position. z - origin_pos. z ) ;
180
+
181
+ // Seems that MC generates a random delta if the damage source is too close to the target
182
+ // let's ignore that for now
175
183
let pkt_hurt = play:: DamageTiltS2c {
176
184
entity_id : VarInt ( target. minecraft_id ( ) ) ,
177
- yaw : 0. // Todo look at how this is calculated
185
+ yaw : delta_z . atan2 ( delta_x ) . mul_add ( 57.295_776_367_187_5_f64 , -f64 :: from ( * * target_yaw ) ) as f32
178
186
} ;
179
187
// EntityDamageS2c: display red outline when taking damage (play arrow hit sound?)
180
188
let pkt_damage_event = play:: EntityDamageS2c {
@@ -440,20 +448,14 @@ impl Module for AttackModule {
440
448
}
441
449
442
450
// Calculate velocity change based on attack direction
443
- let this = * * target_position;
444
- let other = * * origin_pos;
445
-
446
- let delta_x = other. x - this. x ;
447
- let delta_z = other. z - this. z ;
448
-
449
451
if delta_x. abs ( ) >= 0.01 || delta_z. abs ( ) >= 0.01 {
450
452
let dist_xz = delta_x. hypot ( delta_z) ;
451
- let multiplier = 0.4 ;
453
+ let multiplier: f64 = 0.400_000_005_960_464_5 ;
452
454
453
455
reaction. velocity /= 2.0 ;
454
- reaction. velocity . x -= delta_x / dist_xz * multiplier;
455
- reaction. velocity . y += multiplier;
456
- reaction. velocity . z -= delta_z / dist_xz * multiplier;
456
+ reaction. velocity . x -= ( delta_x / dist_xz * multiplier) as f32 ;
457
+ reaction. velocity . y += multiplier as f32 ;
458
+ reaction. velocity . z -= ( delta_z / dist_xz * multiplier) as f32 ;
457
459
458
460
reaction. velocity . y = reaction. velocity . y . min ( 0.4 ) ;
459
461
}
0 commit comments