Advertisement
Guest User

SafeOrient - SafeControllerLook.java

a guest
Dec 12th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package net.isageek.joethornton.Orientation;
  2.  
  3. import net.minecraft.server.ControllerLook;
  4. import net.minecraft.server.Entity;
  5. import net.minecraft.server.EntityLiving;
  6. import net.minecraft.server.MathHelper;
  7.  
  8. public class SafeControllerLook extends ControllerLook {
  9.  
  10.     // Hiding variable a from ControllerLook
  11.     private SafePlayer a;
  12.     private float b;
  13.     private float c;
  14.     private boolean d = false;
  15.     private double e;
  16.     private double f;
  17.     private double g;
  18.    
  19.     public SafeControllerLook(SafePlayer safeplayer) {
  20.         super(safeplayer);
  21.         this.a = safeplayer;
  22.     }
  23.    
  24.     @Override
  25.     public void a(Entity entity, float f, float f1) {
  26.         this.e = entity.locX;
  27.         if (entity instanceof EntityLiving) {
  28.             this.f = entity.locY + (double) entity.getHeadHeight();
  29.         } else {
  30.             this.f = (entity.boundingBox.b + entity.boundingBox.e) / 2.0D;
  31.         }
  32.  
  33.         this.g = entity.locZ;
  34.         this.b = f;
  35.         this.c = f1;
  36.         this.d = true;
  37.     }
  38.  
  39.     @Override
  40.     public void a(double d0, double d1, double d2, float f, float f1) {
  41.         this.e = d0;
  42.         this.f = d1;
  43.         this.g = d2;
  44.         this.b = f;
  45.         this.c = f1;
  46.         this.d = true;
  47.     }
  48.  
  49.     @Override
  50.     public void a() {
  51.         this.a.pitch = 0.0F;
  52.         if (this.d) {
  53.             this.d = false;
  54.             double d0 = this.e - this.a.locX;
  55.             double d1 = this.f - (this.a.locY + (double) this.a.getHeadHeight());
  56.             double d2 = this.g - this.a.locZ;
  57.             double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
  58.             float f = (float) (Math.atan2(d2, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
  59.             float f1 = (float) (-(Math.atan2(d1, d3) * 180.0D / 3.1415927410125732D));
  60.  
  61.             this.a.setPitch(this.a(this.a.pitch, f1, this.c));
  62.             this.a.X = this.a(this.a.X, f, this.b);
  63.         } else {
  64.             this.a.X = this.a(this.a.X, this.a.V, 10.0F);
  65.         }
  66.  
  67.         float f2;
  68.  
  69.         for (f2 = this.a.X - this.a.V; f2 < -180.0F; f2 += 360.0F) {
  70.             ;
  71.         }
  72.  
  73.         while (f2 >= 180.0F) {
  74.             f2 -= 360.0F;
  75.         }
  76.  
  77.         if (!this.a.al().e()) {
  78.             if (f2 < -75.0F) {
  79.                 this.a.X = this.a.V - 75.0F;
  80.             }
  81.  
  82.             if (f2 > 75.0F) {
  83.                 this.a.X = this.a.V + 75.0F;
  84.             }
  85.         }
  86.     }
  87.  
  88.     private float a(float f, float f1, float f2) {
  89.         float f3;
  90.  
  91.         for (f3 = f1 - f; f3 < -180.0F; f3 += 360.0F) {
  92.             ;
  93.         }
  94.  
  95.         while (f3 >= 180.0F) {
  96.             f3 -= 360.0F;
  97.         }
  98.  
  99.         if (f3 > f2) {
  100.             f3 = f2;
  101.         }
  102.  
  103.         if (f3 < -f2) {
  104.             f3 = -f2;
  105.         }
  106.  
  107.         return f + f3;
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement