@@ -12,7 +12,7 @@ use hyperion::{
1212 packets:: { BossBarAction , BossBarS2c } ,
1313 } ,
1414 simulation:: {
15- PacketState , Player , Position , Velocity , event,
15+ PacketState , Player , Position , Velocity , Yaw , event,
1616 metadata:: { entity:: Pose , living_entity:: Health } ,
1717 } ,
1818 storage:: EventQueue ,
@@ -64,6 +64,7 @@ pub struct KillCount {
6464 pub kill_count : u32 ,
6565}
6666
67+ #[ allow( clippy:: cast_possible_truncation) ]
6768impl Module for AttackModule {
6869 #[ allow( clippy:: excessive_nesting) ]
6970 fn module ( world : & World ) {
@@ -145,10 +146,11 @@ impl Module for AttackModule {
145146 & mut Health ,
146147 & mut Position ,
147148 & mut Velocity ,
149+ & Yaw ,
148150 & CombatStats ,
149151 & PlayerInventory
150152 ) > (
151- |( immune_until, health, target_position, reaction, stats, target_inventory) | {
153+ |( immune_until, health, target_position, reaction, target_yaw , stats, target_inventory) | {
152154 if let Some ( immune_until) = immune_until {
153155 if immune_until. tick > current_tick {
154156 return ;
@@ -172,9 +174,15 @@ impl Module for AttackModule {
172174 food : VarInt ( 20 ) ,
173175 food_saturation : 5.0
174176 } ;
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
175183 let pkt_hurt = play:: DamageTiltS2c {
176184 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
178186 } ;
179187 // EntityDamageS2c: display red outline when taking damage (play arrow hit sound?)
180188 let pkt_damage_event = play:: EntityDamageS2c {
@@ -440,20 +448,14 @@ impl Module for AttackModule {
440448 }
441449
442450 // 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-
449451 if delta_x. abs ( ) >= 0.01 || delta_z. abs ( ) >= 0.01 {
450452 let dist_xz = delta_x. hypot ( delta_z) ;
451- let multiplier = 0.4 ;
453+ let multiplier: f64 = 0.400_000_005_960_464_5 ;
452454
453455 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 ;
457459
458460 reaction. velocity . y = reaction. velocity . y . min ( 0.4 ) ;
459461 }
0 commit comments