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