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.client.renderer.texture.IconRegister;
008import net.minecraft.creativetab.CreativeTabs;
009import net.minecraft.util.Icon;
010import net.minecraft.world.IBlockAccess;
011import net.minecraft.world.World;
012
013public class BlockMycelium extends Block
014{
015    @SideOnly(Side.CLIENT)
016    private Icon field_94422_a;
017    @SideOnly(Side.CLIENT)
018    private Icon field_94421_b;
019
020    protected BlockMycelium(int par1)
021    {
022        super(par1, Material.grass);
023        this.setTickRandomly(true);
024        this.setCreativeTab(CreativeTabs.tabBlock);
025    }
026
027    @SideOnly(Side.CLIENT)
028
029    /**
030     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
031     */
032    public Icon getIcon(int par1, int par2)
033    {
034        return par1 == 1 ? this.field_94422_a : (par1 == 0 ? Block.dirt.getBlockTextureFromSide(par1) : this.blockIcon);
035    }
036
037    /**
038     * Ticks the block if it's been scheduled
039     */
040    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
041    {
042        if (!par1World.isRemote)
043        {
044            if (par1World.getBlockLightValue(par2, par3 + 1, par4) < 4 && par1World.getBlockLightOpacity(par2, par3 + 1, par4) > 2)
045            {
046                par1World.setBlock(par2, par3, par4, Block.dirt.blockID);
047            }
048            else if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9)
049            {
050                for (int l = 0; l < 4; ++l)
051                {
052                    int i1 = par2 + par5Random.nextInt(3) - 1;
053                    int j1 = par3 + par5Random.nextInt(5) - 3;
054                    int k1 = par4 + par5Random.nextInt(3) - 1;
055                    int l1 = par1World.getBlockId(i1, j1 + 1, k1);
056
057                    if (par1World.getBlockId(i1, j1, k1) == Block.dirt.blockID && par1World.getBlockLightValue(i1, j1 + 1, k1) >= 4 && par1World.getBlockLightOpacity(i1, j1 + 1, k1) <= 2)
058                    {
059                        par1World.setBlock(i1, j1, k1, this.blockID);
060                    }
061                }
062            }
063        }
064    }
065
066    /**
067     * Returns the ID of the items to drop on destruction.
068     */
069    public int idDropped(int par1, Random par2Random, int par3)
070    {
071        return Block.dirt.idDropped(0, par2Random, par3);
072    }
073
074    @SideOnly(Side.CLIENT)
075
076    /**
077     * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side
078     */
079    public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
080    {
081        if (par5 == 1)
082        {
083            return this.field_94422_a;
084        }
085        else if (par5 == 0)
086        {
087            return Block.dirt.getBlockTextureFromSide(par5);
088        }
089        else
090        {
091            Material material = par1IBlockAccess.getBlockMaterial(par2, par3 + 1, par4);
092            return material != Material.snow && material != Material.craftedSnow ? this.blockIcon : this.field_94421_b;
093        }
094    }
095
096    @SideOnly(Side.CLIENT)
097
098    /**
099     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
100     * is the only chance you get to register icons.
101     */
102    public void registerIcons(IconRegister par1IconRegister)
103    {
104        this.blockIcon = par1IconRegister.registerIcon("mycel_side");
105        this.field_94422_a = par1IconRegister.registerIcon("mycel_top");
106        this.field_94421_b = par1IconRegister.registerIcon("snow_side");
107    }
108
109    @SideOnly(Side.CLIENT)
110
111    /**
112     * A randomly called display update to be able to add particles or other items for display
113     */
114    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
115    {
116        super.randomDisplayTick(par1World, par2, par3, par4, par5Random);
117
118        if (par5Random.nextInt(10) == 0)
119        {
120            par1World.spawnParticle("townaura", (double)((float)par2 + par5Random.nextFloat()), (double)((float)par3 + 1.1F), (double)((float)par4 + par5Random.nextFloat()), 0.0D, 0.0D, 0.0D);
121        }
122    }
123}