package net.minecraft.server;

import java.util.Random;

public class BlockStem extends BlockFlower
{
  private Block a;

  protected BlockStem(int paramInt, Block paramBlock)
  {
    super(paramInt, 111);

    this.a = paramBlock;

    a(true);
    float f = 0.125F;
    a(0.5F - f, 0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
  }

  protected boolean d(int paramInt) {
    return (paramInt == Block.SOIL.id);
  }

  public void a(World paramWorld, int paramInt1, int paramInt2, int paramInt3, Random paramRandom) {
    super.a(paramWorld, paramInt1, paramInt2, paramInt3, paramRandom);
    if (paramWorld.getLightLevel(paramInt1, paramInt2 + 1, paramInt3) >= 9)
    {
      float f = i(paramWorld, paramInt1, paramInt2, paramInt3);

      if (paramRandom.nextInt((int)(25.0F / f) + 1) == 0) {
        int i = paramWorld.getData(paramInt1, paramInt2, paramInt3);
        if (i < 7)
        {
          paramWorld.setData(paramInt1, paramInt2, paramInt3, ++i);
        } else {
          if (paramWorld.getTypeId(paramInt1 - 1, paramInt2, paramInt3) == this.a.id) return;
          if (paramWorld.getTypeId(paramInt1 + 1, paramInt2, paramInt3) == this.a.id) return;
          if (paramWorld.getTypeId(paramInt1, paramInt2, paramInt3 - 1) == this.a.id) return;
          if (paramWorld.getTypeId(paramInt1, paramInt2, paramInt3 + 1) == this.a.id) return;

          int j = paramRandom.nextInt(4);
          int k = paramInt1;
          int l = paramInt3;
          if (j == 0) --k;
          if (j == 1) ++k;
          if (j == 2) --l;
          if (j == 3) ++l;
          
          if  ((((paramWorld.getTypeId(k, paramInt2 - 1, l) == Block.DIRT.id)) || 
            		((paramWorld.getTypeId(k, paramInt2 - 1, l) == Block.GRASS.id)))
            		&& (paramWorld.getTypeId(k, paramInt2, l) == 0))
            paramWorld.setTypeId(k, paramInt2, l, this.a.id);
        }
      }
    }
  }

  public void g(World paramWorld, int paramInt1, int paramInt2, int paramInt3)
  {
    paramWorld.setData(paramInt1, paramInt2, paramInt3, 7);
  }

  private float i(World paramWorld, int paramInt1, int paramInt2, int paramInt3) {
    float f1 = 1F;

    int i = paramWorld.getTypeId(paramInt1, paramInt2, paramInt3 - 1);
    int j = paramWorld.getTypeId(paramInt1, paramInt2, paramInt3 + 1);
    int k = paramWorld.getTypeId(paramInt1 - 1, paramInt2, paramInt3);
    int l = paramWorld.getTypeId(paramInt1 + 1, paramInt2, paramInt3);

    int i1 = paramWorld.getTypeId(paramInt1 - 1, paramInt2, paramInt3 - 1);
    int i2 = paramWorld.getTypeId(paramInt1 + 1, paramInt2, paramInt3 - 1);
    int i3 = paramWorld.getTypeId(paramInt1 + 1, paramInt2, paramInt3 + 1);
    int i4 = paramWorld.getTypeId(paramInt1 - 1, paramInt2, paramInt3 + 1);

    byte b1 = (byte)(((k == this.id) || (l == this.id)) ? 1 : 0);
    byte b2 = (byte)(((i == this.id) || (j == this.id)) ? 1 : 0);
    byte b3 = (byte)(((i1 == this.id) || (i2 == this.id) || (i3 == this.id) || (i4 == this.id)) ? 1 : 0);

    for (int i5 = paramInt1 - 1; i5 <= paramInt1 + 1; ++i5)
      for (int i6 = paramInt3 - 1; i6 <= paramInt3 + 1; ++i6) {
        int i7 = paramWorld.getTypeId(i5, paramInt2 - 1, i6);

        float f2 = 0F;
        if (i7 == Block.SOIL.id) {
          f2 = 1F;
          if (paramWorld.getData(i5, paramInt2 - 1, i6) > 0) f2 = 3.0F;
        }

        if ((i5 != paramInt1) || (i6 != paramInt3)) f2 = f2 / 4.0F;

        f1 = f1 + f2;
      }

    if ((b3 != 0) || ((b1 != 0) && (b2 != 0))) f1 = f1 / 2F;

    return f1;
  }

  public int a(int paramInt1, int paramInt2)
  {
    return this.textureId;
  }

  public void f() {
    float f = 0.125F;
    a(0.5F - f, 0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
  }

  public void updateShape(IBlockAccess paramIBlockAccess, int paramInt1, int paramInt2, int paramInt3) {
    this.maxY = ((paramIBlockAccess.getData(paramInt1, paramInt2, paramInt3) * 2 + 2) / 16.0F);
    float f = 0.125F;
    a(0.5F - f, 0F, 0.5F - f, 0.5F + f, (float)this.maxY, 0.5F + f);
  }

  public int c() {
    return 19;
  }

  public void dropNaturally(World paramWorld, int paramInt1, int paramInt2, int paramInt3, int paramInt4, float paramFloat, int paramInt5)
  {
    super.dropNaturally(paramWorld, paramInt1, paramInt2, paramInt3, paramInt4, paramFloat, paramInt5);

    if (paramWorld.isStatic) {
      return;
    }

    Item localItem = null;
    if (this.a == Block.PUMPKIN) localItem = Item.PUMPKIN_SEEDS;
    if (this.a == Block.MELON) { localItem = Item.MELON_SEEDS;
    }

    float f1 = 0.69999998807907104F;
    float f2 = paramWorld.random.nextFloat() * f1 + (1F - f1) * 0.5F;
    float f3 = paramWorld.random.nextFloat() * f1 + (1F - f1) * 0.5F;
    float f4 = paramWorld.random.nextFloat() * f1 + (1F - f1) * 0.5F;
    EntityItem localEntityItem = new EntityItem(paramWorld, paramInt1 + f2, paramInt2 + f3, paramInt3 + f4, new ItemStack(localItem));
    localEntityItem.pickupDelay = 10;
    paramWorld.addEntity(localEntityItem);
  }

  public int getDropType(int paramInt1, Random paramRandom, int paramInt2)
  {
    if (paramInt1 == 7);
    return -1;
  }

  public int a(Random paramRandom) {
    return 1;
  }
}