Nessiesson

Untitled

Feb 4th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. package carpetclient.mixins;
  2.  
  3. import carpetclient.Config;
  4. import net.minecraft.entity.Entity;
  5.  
  6. import org.spongepowered.asm.lib.Opcodes;
  7. import org.spongepowered.asm.mixin.Mixin;
  8. import org.spongepowered.asm.mixin.Shadow;
  9. import org.spongepowered.asm.mixin.injection.At;
  10. import org.spongepowered.asm.mixin.injection.Inject;
  11. import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
  12.  
  13. /*
  14. A Mixins class to override a method to change the players aim.
  15.  */
  16. @Mixin(Entity.class)
  17. public abstract class MixinsEntity {
  18.  
  19.     @Shadow
  20.     public float rotationYaw;
  21.     @Shadow
  22.     public float rotationPitch;
  23.     @Shadow
  24.     public float prevRotationPitch;
  25.     @Shadow
  26.     public float prevRotationYaw;
  27.     @Shadow
  28.     private Entity ridingEntity;
  29.  
  30.     private float storedRotationYaw;
  31.  
  32.     /*
  33.     Injection to modify the behavior of player aiming.
  34.      */
  35.     @Inject(method = "turn", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;prevRotationPitch:F", opcode = Opcodes.PUTFIELD))
  36.     public void post(float yaw, float pitch, CallbackInfo ci) {
  37.         snapAim(this.ridingEntity != null, yaw);
  38.     }
  39.  
  40.     /**
  41.      * Overriding the aim of the player to snap to angles of 45 degrees
  42.      * @param inBoat Checks if the player is riding a boat to skip snapping.
  43.      * @param yaw The angle in which the player will turn, sent in from the turn method.
  44.      */
  45.     private void snapAim(boolean inBoat, float yaw) {
  46.         if (inBoat || !Config.snapAim) return;
  47.  
  48.         this.storedRotationYaw = (float) ((double) this.storedRotationYaw + (double) yaw * 0.15D);
  49.  
  50.         float r = storedRotationYaw - storedRotationYaw % 45;
  51.         float r2 = Math.abs(r - storedRotationYaw);
  52.         if (r2 < 5) {
  53.             this.rotationYaw = r;
  54.         } else if (r2 > 40) {
  55.             if (storedRotationYaw < 0)
  56.                 this.rotationYaw = r - 45;
  57.             else
  58.                 this.rotationYaw = r + 45;
  59.         } else {
  60.             this.rotationYaw = storedRotationYaw;
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment