    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    import net.minecraftforge.common.ForgeDirection;
    006
    007    public class BlockMushroom extends BlockFlower
    008    {
    009        protected BlockMushroom(int par1, int par2)
    010        {
    011            super(par1, par2);
    012            float var3 = 0.2F;
    013            this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, var3 * 2.0F, 0.5F + var3);
    014            this.setTickRandomly(true);
    015        }
    016
    017        /**
    018         * Ticks the block if it's been scheduled
    019         */
    020        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    021        {
    022            if (par5Random.nextInt(25) == 0)
    023            {
    024                byte var6 = 4;
    025                int var7 = 5;
    026                int var8;
    027                int var9;
    028                int var10;
    029
    030                for (var8 = par2 - var6; var8 <= par2 + var6; ++var8)
    031                {
    032                    for (var9 = par4 - var6; var9 <= par4 + var6; ++var9)
    033                    {
    034                        for (var10 = par3 - 1; var10 <= par3 + 1; ++var10)
    035                        {
    036                            if (par1World.getBlockId(var8, var10, var9) == this.blockID)
    037                            {
    038                                --var7;
    039
    040                                if (var7 <= 0)
    041                                {
    042                                    return;
    043                                }
    044                            }
    045                        }
    046                    }
    047                }
    048
    049                var8 = par2 + par5Random.nextInt(3) - 1;
    050                var9 = par3 + par5Random.nextInt(2) - par5Random.nextInt(2);
    051                var10 = par4 + par5Random.nextInt(3) - 1;
    052
    053                for (int var11 = 0; var11 < 4; ++var11)
    054                {
    055                    if (par1World.isAirBlock(var8, var9, var10) && this.canBlockStay(par1World, var8, var9, var10))
    056                    {
    057                        par2 = var8;
    058                        par3 = var9;
    059                        par4 = var10;
    060                    }
    061
    062                    var8 = par2 + par5Random.nextInt(3) - 1;
    063                    var9 = par3 + par5Random.nextInt(2) - par5Random.nextInt(2);
    064                    var10 = par4 + par5Random.nextInt(3) - 1;
    065                }
    066
    067                if (par1World.isAirBlock(var8, var9, var10) && this.canBlockStay(par1World, var8, var9, var10))
    068                {
    069                    par1World.setBlockWithNotify(var8, var9, var10, this.blockID);
    070                }
    071            }
    072        }
    073
    074        /**
    075         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    076         */
    077        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    078        {
    079            return super.canPlaceBlockAt(par1World, par2, par3, par4) && this.canBlockStay(par1World, par2, par3, par4);
    080        }
    081
    082        /**
    083         * Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
    084         * blockID passed in. Args: blockID
    085         */
    086        protected boolean canThisPlantGrowOnThisBlockID(int par1)
    087        {
    088            return Block.opaqueCubeLookup[par1];
    089        }
    090
    091        /**
    092         * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
    093         */
    094        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
    095        {
    096            if (par3 >= 0 && par3 < 256)
    097            {
    098                int var5 = par1World.getBlockId(par2, par3 - 1, par4);
    099                Block soil = Block.blocksList[var5];
    100                return (var5 == Block.mycelium.blockID || par1World.getFullBlockLightValue(par2, par3, par4) < 13) &&
    101                       (soil != null && soil.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
    102            }
    103            else
    104            {
    105                return false;
    106            }
    107        }
    108
    109        /**
    110         * Fertilize the mushroom.
    111         */
    112        public boolean fertilizeMushroom(World par1World, int par2, int par3, int par4, Random par5Random)
    113        {
    114            int var6 = par1World.getBlockMetadata(par2, par3, par4);
    115            par1World.setBlock(par2, par3, par4, 0);
    116            WorldGenBigMushroom var7 = null;
    117
    118            if (this.blockID == Block.mushroomBrown.blockID)
    119            {
    120                var7 = new WorldGenBigMushroom(0);
    121            }
    122            else if (this.blockID == Block.mushroomRed.blockID)
    123            {
    124                var7 = new WorldGenBigMushroom(1);
    125            }
    126
    127            if (var7 != null && var7.generate(par1World, par5Random, par2, par3, par4))
    128            {
    129                return true;
    130            }
    131            else
    132            {
    133                par1World.setBlockAndMetadata(par2, par3, par4, this.blockID, var6);
    134                return false;
    135            }
    136        }
    137    }