Advertisement
Guest User

SafeOrient - SafeControllerMove.java

a guest
Dec 12th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. package net.isageek.joethornton.Orientation;
  2.  
  3. import net.minecraft.server.ControllerMove;
  4. import net.minecraft.server.MathHelper;
  5.  
  6. public class SafeControllerMove extends ControllerMove {
  7.  
  8.     // Hiding variable a from ControllerMove
  9.     private SafePlayer a;
  10.     private double b;
  11.     private double c;
  12.     private double d;
  13.     private float e;
  14.     private boolean f = false;
  15.    
  16.     public SafeControllerMove(SafePlayer safeplayer) {
  17.         super(safeplayer);
  18.         this.a = safeplayer;
  19.         this.b = safeplayer.locX;
  20.         this.c = safeplayer.locY;
  21.         this.d = safeplayer.locZ;
  22.     }
  23.    
  24.     @Override
  25.     public boolean a() {
  26.         return this.f;
  27.     }
  28.  
  29.     @Override
  30.     public float b() {
  31.         return this.e;
  32.     }
  33.  
  34.     @Override
  35.     public void a(double d0, double d1, double d2, float f) {
  36.         this.b = d0;
  37.         this.c = d1;
  38.         this.d = d2;
  39.         this.e = f;
  40.         this.f = true;
  41.     }
  42.  
  43.     @Override
  44.     public void c() {
  45.         this.a.e(0.0F);
  46.         if (this.f) {
  47.             this.f = false;
  48.             int i = MathHelper.floor(this.a.boundingBox.b + 0.5D);
  49.             double d0 = this.b - this.a.locX;
  50.             double d1 = this.d - this.a.locZ;
  51.             double d2 = this.c - (double) i;
  52.             double d3 = d0 * d0 + d2 * d2 + d1 * d1;
  53.  
  54.             if (d3 >= 2.500000277905201E-7D) {
  55.                 float f = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
  56.  
  57.                 this.a.setYaw(this.a(this.a.yaw, f, 30.0F));
  58.                 this.a.d(this.e);
  59.                 if (d2 > 0.0D && d0 * d0 + d1 * d1 < 1.0D) {
  60.                     this.a.getControllerJump().a();
  61.                 }
  62.             }
  63.         }
  64.     }
  65.    
  66.     private float a(float f, float f1, float f2) {
  67.         float f3;
  68.  
  69.         for (f3 = f1 - f; f3 < -180.0F; f3 += 360.0F) {
  70.             ;
  71.         }
  72.  
  73.         while (f3 >= 180.0F) {
  74.             f3 -= 360.0F;
  75.         }
  76.  
  77.         if (f3 > f2) {
  78.             f3 = f2;
  79.         }
  80.  
  81.         if (f3 < -f2) {
  82.             f3 = -f2;
  83.         }
  84.  
  85.         return f + f3;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement