55import  dev .nero .aimassistance .core .TargetType ;
66import  net .minecraft .client .Minecraft ;
77import  net .minecraft .entity .Entity ;
8+ import  net .minecraft .entity .MobEntity ;
89import  net .minecraft .util .math .*;
910import  net .minecraft .util .math .vector .Vector3d ;
1011
@@ -103,6 +104,13 @@ private static BlockRayTraceResult rayTrace(double range) {
103104        );
104105    }
105106
107+     /** 
108+      * @return true if the player is currently aiming at a mob 
109+      */ 
110+     public  static  boolean  isPlayerAimingMob () {
111+         return  Wrapper .MC .pointedEntity  instanceof  MobEntity ;
112+     }
113+ 
106114    /** 
107115     * @param range in blocks, defines the range around the player to scan for entities 
108116     * @param entityClass the entity type to look for (Check the Entity class: MobEntity.class for mobs for example) 
@@ -131,7 +139,7 @@ public static Entity getClosestEntityToCrosshair(List<Entity> entities) {
131139
132140        for (Entity  entity  : entities ){
133141            // Get distance between the two entities (rotations) 
134-             float [] yawPitch  = getYawPitchBetween (
142+             float [] yawPitch  = getClosestYawPitchBetween (
135143                    Wrapper .MC .player , entity 
136144            );
137145
@@ -154,22 +162,32 @@ public static Entity getClosestEntityToCrosshair(List<Entity> entities) {
154162     * @param source the source entity 
155163     * @param target the target of the source entity 
156164     */ 
157-     public  static  float [] getYawPitchBetween (Entity  source , Entity  target ) {
165+     public  static  float [] getClosestYawPitchBetween (Entity  source , Entity  target ) {
158166        // getPosY returns the ground position 
159167        // getPosY + EyeHeight return the eye's position 
160168        // getPosY + EyeHeight/1.5 returns the upper body position 
161-         final  float  SHIFT_FACTOR  = 1.25f ;
162- 
163-         return  Wrapper .getYawPitchBetween (
164-                 // source 
165-                 source .getPosX (),
166-                 source .getPosY () + source .getEyeHeight (),
167-                 source .getPosZ (),
168-                 // target 
169-                 target .getPosX (),
170-                 target .getPosY () + (target .getEyeHeight () / SHIFT_FACTOR ),
171-                 target .getPosZ ()
172-         );
169+         //final float SHIFT_FACTOR = 1.25f; 
170+ 
171+         float [] bestYawPitch  = new  float [] { Float .MAX_VALUE , Float .MAX_VALUE  };
172+ 
173+         for  (float  factor  : new  float []{0f , 0.05f , 0.1f , 0.25f , 0.5f , 0.75f , 1.0f }) {
174+             float [] yawPitch  = Wrapper .getYawPitchBetween (
175+                     // source 
176+                     source .getPosX (),
177+                     source .getPosY () + source .getEyeHeight (),
178+                     source .getPosZ (),
179+                     // target 
180+                     target .getPosX (),
181+                     target .getPosY () + target .getEyeHeight () * factor ,
182+                     target .getPosZ ()
183+             );
184+ 
185+             if  (Math .abs (yawPitch [0 ]) + Math .abs (yawPitch [1 ]) < Math .abs (bestYawPitch [0 ]) + Math .abs (bestYawPitch [1 ])) {
186+                 bestYawPitch  = yawPitch ;
187+             }
188+         }
189+ 
190+         return  bestYawPitch ;
173191    }
174192
175193    /** 
@@ -206,7 +224,7 @@ public static float[] getRotationsNeeded(Target target, float fovX, float fovY,
206224        // We calculate the yaw/pitch difference between the target and the player 
207225        float [] yawPitch ;
208226        if  (target .getType () == TargetType .ENTITY ) {
209-             yawPitch  = getYawPitchBetween (
227+             yawPitch  = getClosestYawPitchBetween (
210228                    Wrapper .MC .player ,
211229                    (Entity ) target .getTarget ()
212230            );
0 commit comments