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