    001    package net.minecraft.world.gen.feature;
    002
    003    import java.util.Random;
    004    import net.minecraft.block.Block;
    005    import net.minecraft.world.World;
    006
    007    public class WorldGenForest extends WorldGenerator
    008    {
    009        public WorldGenForest(boolean par1)
    010        {
    011            super(par1);
    012        }
    013
    014        public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    015        {
    016            int var6 = par2Random.nextInt(3) + 5;
    017            boolean var7 = true;
    018
    019            if (par4 >= 1 && par4 + var6 + 1 <= 256)
    020            {
    021                int var8;
    022                int var10;
    023                int var11;
    024                int var12;
    025
    026                for (var8 = par4; var8 <= par4 + 1 + var6; ++var8)
    027                {
    028                    byte var9 = 1;
    029
    030                    if (var8 == par4)
    031                    {
    032                        var9 = 0;
    033                    }
    034
    035                    if (var8 >= par4 + 1 + var6 - 2)
    036                    {
    037                        var9 = 2;
    038                    }
    039
    040                    for (var10 = par3 - var9; var10 <= par3 + var9 && var7; ++var10)
    041                    {
    042                        for (var11 = par5 - var9; var11 <= par5 + var9 && var7; ++var11)
    043                        {
    044                            if (var8 >= 0 && var8 < 256)
    045                            {
    046                                var12 = par1World.getBlockId(var10, var8, var11);
    047
    048                                Block block = Block.blocksList[var12];
    049
    050                                if (var12 != 0 && (block != null && !block.isLeaves(par1World, var10,  var8, var11)))
    051                                {
    052                                    var7 = false;
    053                                }
    054                            }
    055                            else
    056                            {
    057                                var7 = false;
    058                            }
    059                        }
    060                    }
    061                }
    062
    063                if (!var7)
    064                {
    065                    return false;
    066                }
    067                else
    068                {
    069                    var8 = par1World.getBlockId(par3, par4 - 1, par5);
    070
    071                    if ((var8 == Block.grass.blockID || var8 == Block.dirt.blockID) && par4 < 256 - var6 - 1)
    072                    {
    073                        this.setBlock(par1World, par3, par4 - 1, par5, Block.dirt.blockID);
    074                        int var16;
    075
    076                        for (var16 = par4 - 3 + var6; var16 <= par4 + var6; ++var16)
    077                        {
    078                            var10 = var16 - (par4 + var6);
    079                            var11 = 1 - var10 / 2;
    080
    081                            for (var12 = par3 - var11; var12 <= par3 + var11; ++var12)
    082                            {
    083                                int var13 = var12 - par3;
    084
    085                                for (int var14 = par5 - var11; var14 <= par5 + var11; ++var14)
    086                                {
    087                                    int var15 = var14 - par5;
    088
    089                                    Block block = Block.blocksList[par1World.getBlockId(var12, var16, var14)];
    090
    091                                    if ((Math.abs(var13) != var11 || Math.abs(var15) != var11 || par2Random.nextInt(2) != 0 && var10 != 0) &&
    092                                        (block == null || block.canBeReplacedByLeaves(par1World, var12, var16, var14)))
    093                                    {
    094                                        this.setBlockAndMetadata(par1World, var12, var16, var14, Block.leaves.blockID, 2);
    095                                    }
    096                                }
    097                            }
    098                        }
    099
    100                        for (var16 = 0; var16 < var6; ++var16)
    101                        {
    102                            var10 = par1World.getBlockId(par3, par4 + var16, par5);
    103
    104                            Block block = Block.blocksList[var10];
    105
    106                            if (var10 == 0 || block == null || block.isLeaves(par1World, par3, par4 + var16, par5))
    107                            {
    108                                this.setBlockAndMetadata(par1World, par3, par4 + var16, par5, Block.wood.blockID, 2);
    109                            }
    110                        }
    111
    112                        return true;
    113                    }
    114                    else
    115                    {
    116                        return false;
    117                    }
    118                }
    119            }
    120            else
    121            {
    122                return false;
    123            }
    124        }
    125    }