001package net.minecraft.block;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.util.Random;
006import net.minecraft.block.material.Material;
007import net.minecraft.item.Item;
008import net.minecraft.util.AxisAlignedBB;
009import net.minecraft.world.World;
010
011import net.minecraftforge.common.EnumPlantType;
012import net.minecraftforge.common.ForgeDirection;
013import net.minecraftforge.common.IPlantable;
014
015public class BlockReed extends Block implements IPlantable
016{
017    protected BlockReed(int par1, int par2)
018    {
019        super(par1, Material.plants);
020        this.blockIndexInTexture = par2;
021        float var3 = 0.375F;
022        this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 1.0F, 0.5F + var3);
023        this.setTickRandomly(true);
024    }
025
026    /**
027     * Ticks the block if it's been scheduled
028     */
029    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
030    {
031        if (par1World.isAirBlock(par2, par3 + 1, par4))
032        {
033            int var6;
034
035            for (var6 = 1; par1World.getBlockId(par2, par3 - var6, par4) == this.blockID; ++var6)
036            {
037                ;
038            }
039
040            if (var6 < 3)
041            {
042                int var7 = par1World.getBlockMetadata(par2, par3, par4);
043
044                if (var7 == 15)
045                {
046                    par1World.setBlockWithNotify(par2, par3 + 1, par4, this.blockID);
047                    par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
048                }
049                else
050                {
051                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var7 + 1);
052                }
053            }
054        }
055    }
056
057    /**
058     * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
059     */
060    public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
061    {
062        Block block = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
063        return (block != null && block.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
064    }
065
066    /**
067     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
068     * their own) Args: x, y, z, neighbor blockID
069     */
070    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
071    {
072        this.checkBlockCoordValid(par1World, par2, par3, par4);
073    }
074
075    /**
076     * Checks if current block pos is valid, if not, breaks the block as dropable item. Used for reed and cactus.
077     */
078    protected final void checkBlockCoordValid(World par1World, int par2, int par3, int par4)
079    {
080        if (!this.canBlockStay(par1World, par2, par3, par4))
081        {
082            this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
083            par1World.setBlockWithNotify(par2, par3, par4, 0);
084        }
085    }
086
087    /**
088     * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
089     */
090    public boolean canBlockStay(World par1World, int par2, int par3, int par4)
091    {
092        return this.canPlaceBlockAt(par1World, par2, par3, par4);
093    }
094
095    /**
096     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
097     * cleared to be reused)
098     */
099    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
100    {
101        return null;
102    }
103
104    /**
105     * Returns the ID of the items to drop on destruction.
106     */
107    public int idDropped(int par1, Random par2Random, int par3)
108    {
109        return Item.reed.itemID;
110    }
111
112    /**
113     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
114     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
115     */
116    public boolean isOpaqueCube()
117    {
118        return false;
119    }
120
121    /**
122     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
123     */
124    public boolean renderAsNormalBlock()
125    {
126        return false;
127    }
128
129    /**
130     * The type of render function that is called for this block
131     */
132    public int getRenderType()
133    {
134        return 1;
135    }
136
137    @SideOnly(Side.CLIENT)
138
139    /**
140     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
141     */
142    public int idPicked(World par1World, int par2, int par3, int par4)
143    {
144        return Item.reed.itemID;
145    }
146
147    @Override
148    public EnumPlantType getPlantType(World world, int x, int y, int z)
149    {
150        return EnumPlantType.Beach;
151    }
152
153    @Override
154    public int getPlantID(World world, int x, int y, int z)
155    {
156        return blockID;
157    }
158
159    @Override
160    public int getPlantMetadata(World world, int x, int y, int z)
161    {
162        return world.getBlockMetadata(x, y, z);
163    }
164}