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