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