    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.List;
    006    import java.util.Random;
    007
    008    public class BlockSapling extends BlockFlower
    009    {
    010        public static final String[] WOOD_TYPES = new String[] {"oak", "spruce", "birch", "jungle"};
    011
    012        protected BlockSapling(int par1, int par2)
    013        {
    014            super(par1, par2);
    015            float var3 = 0.4F;
    016            this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, var3 * 2.0F, 0.5F + var3);
    017            this.setCreativeTab(CreativeTabs.tabDecorations);
    018        }
    019
    020        /**
    021         * Ticks the block if it's been scheduled
    022         */
    023        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    024        {
    025            if (!par1World.isRemote)
    026            {
    027                super.updateTick(par1World, par2, par3, par4, par5Random);
    028
    029                if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9 && par5Random.nextInt(7) == 0)
    030                {
    031                    int var6 = par1World.getBlockMetadata(par2, par3, par4);
    032
    033                    if ((var6 & 8) == 0)
    034                    {
    035                        par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 | 8);
    036                    }
    037                    else
    038                    {
    039                        this.growTree(par1World, par2, par3, par4, par5Random);
    040                    }
    041                }
    042            }
    043        }
    044
    045        /**
    046         * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    047         */
    048        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    049        {
    050            par2 &= 3;
    051            return par2 == 1 ? 63 : (par2 == 2 ? 79 : (par2 == 3 ? 30 : super.getBlockTextureFromSideAndMetadata(par1, par2)));
    052        }
    053
    054        /**
    055         * Attempts to grow a sapling into a tree
    056         */
    057        public void growTree(World par1World, int par2, int par3, int par4, Random par5Random)
    058        {
    059            int var6 = par1World.getBlockMetadata(par2, par3, par4) & 3;
    060            Object var7 = null;
    061            int var8 = 0;
    062            int var9 = 0;
    063            boolean var10 = false;
    064
    065            if (var6 == 1)
    066            {
    067                var7 = new WorldGenTaiga2(true);
    068            }
    069            else if (var6 == 2)
    070            {
    071                var7 = new WorldGenForest(true);
    072            }
    073            else if (var6 == 3)
    074            {
    075                for (var8 = 0; var8 >= -1; --var8)
    076                {
    077                    for (var9 = 0; var9 >= -1; --var9)
    078                    {
    079                        if (this.isSameSapling(par1World, par2 + var8, par3, par4 + var9, 3) && this.isSameSapling(par1World, par2 + var8 + 1, par3, par4 + var9, 3) && this.isSameSapling(par1World, par2 + var8, par3, par4 + var9 + 1, 3) && this.isSameSapling(par1World, par2 + var8 + 1, par3, par4 + var9 + 1, 3))
    080                        {
    081                            var7 = new WorldGenHugeTrees(true, 10 + par5Random.nextInt(20), 3, 3);
    082                            var10 = true;
    083                            break;
    084                        }
    085                    }
    086
    087                    if (var7 != null)
    088                    {
    089                        break;
    090                    }
    091                }
    092
    093                if (var7 == null)
    094                {
    095                    var9 = 0;
    096                    var8 = 0;
    097                    var7 = new WorldGenTrees(true, 4 + par5Random.nextInt(7), 3, 3, false);
    098                }
    099            }
    100            else
    101            {
    102                var7 = new WorldGenTrees(true);
    103
    104                if (par5Random.nextInt(10) == 0)
    105                {
    106                    var7 = new WorldGenBigTree(true);
    107                }
    108            }
    109
    110            if (var10)
    111            {
    112                par1World.setBlock(par2 + var8, par3, par4 + var9, 0);
    113                par1World.setBlock(par2 + var8 + 1, par3, par4 + var9, 0);
    114                par1World.setBlock(par2 + var8, par3, par4 + var9 + 1, 0);
    115                par1World.setBlock(par2 + var8 + 1, par3, par4 + var9 + 1, 0);
    116            }
    117            else
    118            {
    119                par1World.setBlock(par2, par3, par4, 0);
    120            }
    121
    122            if (!((WorldGenerator)var7).generate(par1World, par5Random, par2 + var8, par3, par4 + var9))
    123            {
    124                if (var10)
    125                {
    126                    par1World.setBlockAndMetadata(par2 + var8, par3, par4 + var9, this.blockID, var6);
    127                    par1World.setBlockAndMetadata(par2 + var8 + 1, par3, par4 + var9, this.blockID, var6);
    128                    par1World.setBlockAndMetadata(par2 + var8, par3, par4 + var9 + 1, this.blockID, var6);
    129                    par1World.setBlockAndMetadata(par2 + var8 + 1, par3, par4 + var9 + 1, this.blockID, var6);
    130                }
    131                else
    132                {
    133                    par1World.setBlockAndMetadata(par2, par3, par4, this.blockID, var6);
    134                }
    135            }
    136        }
    137
    138        /**
    139         * Determines if the same sapling is present at the given location.
    140         */
    141        public boolean isSameSapling(World par1World, int par2, int par3, int par4, int par5)
    142        {
    143            return par1World.getBlockId(par2, par3, par4) == this.blockID && (par1World.getBlockMetadata(par2, par3, par4) & 3) == par5;
    144        }
    145
    146        /**
    147         * Determines the damage on the item the block drops. Used in cloth and wood.
    148         */
    149        public int damageDropped(int par1)
    150        {
    151            return par1 & 3;
    152        }
    153
    154        @SideOnly(Side.CLIENT)
    155
    156        /**
    157         * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
    158         */
    159        public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    160        {
    161            par3List.add(new ItemStack(par1, 1, 0));
    162            par3List.add(new ItemStack(par1, 1, 1));
    163            par3List.add(new ItemStack(par1, 1, 2));
    164            par3List.add(new ItemStack(par1, 1, 3));
    165        }
    166    }