package net.minecraft.src;

import java.util.Random;

// Referenced classes of package net.minecraft.src:
//            Block, Material, World, BlockGrass, 
//            AxisAlignedBB

public class fltul extends Block
{

    protected fltul(int i, int j)
    {
        super(i, Material.plants);
        blockIndexInTexture = j;
        setTickOnLoad(true);
        float f = 0.2F;
        setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 3F, 0.5F + f);
    }

    public boolean canPlaceBlockAt(World world, int i, int j, int k)
    {
        return super.canPlaceBlockAt(world, i, j, k) && canThisPlantGrowOnThisBlockID(world.getBlockId(i, j - 1, k));
    }

    protected boolean canThisPlantGrowOnThisBlockID(int i)
    {
        return i == Block.grass.blockID || i == Block.dirt.blockID || i == Block.tilledField.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        super.onNeighborBlockChange(world, i, j, k, l);
        checkFlowerChange(world, i, j, k);
    }

    public void updateTick(World world, int i, int j, int k, Random random)
    {
  
    
           
           byte byte0 = 4;
            int l = 5;
            for(int i1 = i - byte0; i1 <= i + byte0; i1++)
            {
                for(int k1 = k - byte0; k1 <= k + byte0; k1++)
                {
                    for(int i2 = j - 1; i2 <= j + 1; i2++)
                    {
                        if(world.getBlockId(i1, i2, k1) == blockID && --l <= 0)
                        {
                            return;
                        }
                    }

                }

            }

            int j1 = (i + random.nextInt(3)) - 1;
            int l1 = (j + random.nextInt(2)) - random.nextInt(2);
            int j2 = (k + random.nextInt(3)) - 1;
            for(int k2 = 0; k2 < 4; k2++)
            {
                if(world.isAirBlock(j1, l1, j2) && canBlockStay(world, j1, l1, j2))
                {
                    i = j1;
                    j = l1;
                    k = j2;
                }
                j1 = (i + random.nextInt(3)) - 1;
                l1 = (j + random.nextInt(2)) - random.nextInt(2);
                j2 = (k + random.nextInt(3)) - 1;
           }

            if(world.isAirBlock(j1, l1, j2) && canBlockStay(world, j1, l1, j2))
            {
            	
            	 if(random.nextInt(10) == 0)
            	 {
                       world.setBlockWithNotify(j1, l1, j2, mod_decor.fltul.blockID);
            	 }
            }
       

        checkFlowerChange(world, i, j, k);
    }

    protected final void checkFlowerChange(World world, int i, int j, int k)
    {
        if(!canBlockStay(world, i, j, k))
        {
            dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0);
            world.setBlockWithNotify(i, j, k, 0);
        }
    }

    public boolean canBlockStay(World world, int i, int j, int k)
    {
        return (world.getFullBlockLightValue(i, j, k) >= 8 || world.canBlockSeeTheSky(i, j, k)) && canThisPlantGrowOnThisBlockID(world.getBlockId(i, j - 1, k));
    }

    public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
    {
        return null;
    }
    public int idDropped(int i, Random random, int j)
    {
        return mod_decor.fltulItem.shiftedIndex;
    }
    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

    public int getRenderType()
    {
        return 1;
    }
}
