import java.util.Random;

public class gh extends dw
{
  public hj a;
  private int e;
  public int b = 0;
  public int c;
  private int f = 5;

  public float d = (float)(Math.random() * 3.141592653589793D * 2.0D);

  public gh(em paramem, double paramDouble1, double paramDouble2, double paramDouble3, hj paramhj) {
    super(paramem);
    a(0.25F, 0.25F);
    this.G = (this.I / 2.0F);
    a(paramDouble1, paramDouble2, paramDouble3);
    this.a = paramhj;

    this.v = (float)(Math.random() * 360.0D);

    this.s = (float)(Math.random() * 0.2000000029802322D - 0.1000000014901161D);
    this.t = 0.2000000029802322D;
    this.u = (float)(Math.random() * 0.2000000029802322D - 0.1000000014901161D);
    this.L = false;
  }

  public gh(em paramem) {
    super(paramem);
    a(0.25F, 0.25F);
    this.G = (this.I / 2.0F);
  }

  public void b_() {
    super.b_();
    if (this.c > 0) this.c -= 1;
    this.m = this.p;
    this.n = this.q;
    this.o = this.r;

    this.t -= 0.03999999910593033D;
    if (this.l.c(hd.b(this.p), hd.b(this.q), hd.b(this.r)) == jt.g) {
      this.t = 0.2000000029802322D;
      this.s = ((this.V.nextFloat() - this.V.nextFloat()) * 0.2F);
      this.u = ((this.V.nextFloat() - this.V.nextFloat()) * 0.2F);
      this.l.a(this, "random.fizz", 0.4F, 2.0F + this.V.nextFloat() * 0.4F);
    }
    g(this.p, this.q, this.r);
    r();
    c(this.s, this.t, this.u);

    float f1 = 0.98F;
    if (this.A) {
      f1 = 0.5880001F;
      int i = this.l.a(hd.b(this.p), hd.b(this.z.b) - 1, hd.b(this.r));
      if (i > 0) {
        f1 = fy.m[i].bt * 0.98F;
      }
    }

    this.s *= f1;
    this.t *= 0.9800000190734863D;
    this.u *= f1;

    if (this.A) {
      this.t *= -0.5D;
    }

    this.e += 1;
    this.b += 1;
    if (this.b >= 600)
      l();
  }

  public boolean r()
  {
    return this.l.a(this.z, jt.f, this);
  }

  private boolean g(double paramDouble1, double paramDouble2, double paramDouble3) {
    int i = hd.b(paramDouble1);
    int j = hd.b(paramDouble2);
    int k = hd.b(paramDouble3);

    double d1 = paramDouble1 - i;
    double d2 = paramDouble2 - j;
    double d3 = paramDouble3 - k;

    if (fy.o[this.l.a(i, j, k)]) {
      int m = !fy.o[this.l.a(i - 1, j, k)] ? 1 : 0;
      int n = !fy.o[this.l.a(i + 1, j, k)] ? 1 : 0;
      int i1 = !fy.o[this.l.a(i, j - 1, k)] ? 1 : 0;
      int i2 = !fy.o[this.l.a(i, j + 1, k)] ? 1 : 0;
      int i3 = !fy.o[this.l.a(i, j, k - 1)] ? 1 : 0;
      int i4 = !fy.o[this.l.a(i, j, k + 1)] ? 1 : 0;

      int i5 = -1;
      double d4 = 9999.0D;
      if ((m != 0) && (d1 < d4)) {
        d4 = d1;
        i5 = 0;
      }
      if ((n != 0) && (1.0D - d1 < d4)) {
        d4 = 1.0D - d1;
        i5 = 1;
      }
      if ((i1 != 0) && (d2 < d4)) {
        d4 = d2;
        i5 = 2;
      }
      if ((i2 != 0) && (1.0D - d2 < d4)) {
        d4 = 1.0D - d2;
        i5 = 3;
      }
      if ((i3 != 0) && (d3 < d4)) {
        d4 = d3;
        i5 = 4;
      }
      if ((i4 != 0) && (1.0D - d3 < d4)) {
        d4 = 1.0D - d3;
        i5 = 5;
      }

      float f1 = this.V.nextFloat() * 0.2F + 0.1F;
      if (i5 == 0) this.s = (-f1);
      if (i5 == 1) this.s = f1;
      if (i5 == 2) this.t = (-f1);
      if (i5 == 3) this.t = f1;
      if (i5 == 4) this.u = (-f1);
      if (i5 == 5) this.u = f1;
    }

    return false;
  }

  protected void b(int paramInt) {
    a(null, paramInt);
  }

  public boolean a(dw paramdw, int paramInt) {
    this.f -= paramInt;
    if (this.f <= 0) {
      l();
    }
    return false;
  }

  public void a(v paramv) {
    paramv.a("Health", (short)(byte)this.f);
    paramv.a("Age", (short)this.b);
    paramv.a("Item", this.a.a(new v()));
  }

  public void b(v paramv) {
    this.f = (paramv.c("Health") & 0xFF);
    this.b = paramv.c("Age");
    v localv = paramv.j("Item");
    this.a = new hj(localv);
  }

  public void b(fv paramfv) {
    if (this.l.z) return;

    int i = this.a.a;
    if ((this.c == 0) && (paramfv.ak.a(this.a))) {
      this.l.a(this, "random.pop", 0.2F, ((this.V.nextFloat() - this.V.nextFloat()) * 0.7F + 1.0F) * 2.0F);
      paramfv.c(this, i);
      l();
    }
  }
}