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