    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 l = par2Random.nextInt(4) + 6;
    019        int i1 = 1 + par2Random.nextInt(2);
    020        int j1 = l - i1;
    021        int k1 = 2 + par2Random.nextInt(2);
    022        boolean flag = true;
    023
    024        if (par4 >= 1 && par4 + l + 1 <= 256)
    025        {
    026            int l1;
    027            int i2;
    028            int j2;
    029            int k2;
    030
    031            for (l1 = par4; l1 <= par4 + 1 + l && flag; ++l1)
    032            {
    033                boolean flag1 = true;
    034
    035                if (l1 - par4 < i1)
    036                {
    037                    k2 = 0;
    038                }
    039                else
    040                {
    041                    k2 = k1;
    042                }
    043
    044                for (i2 = par3 - k2; i2 <= par3 + k2 && flag; ++i2)
    045                {
    046                    for (int l2 = par5 - k2; l2 <= par5 + k2 && flag; ++l2)
    047                    {
    048                        if (l1 >= 0 && l1 < 256)
    049                        {
    050                            j2 = par1World.getBlockId(i2, l1, l2);
    051
    052                            Block block = Block.blocksList[j2];
    053
    054                            if (j2 != 0 && block != null && !block.isLeaves(par1World, i2, l1, l2))
    055                            {
    056                                flag = false;
    057                            }
    058                        }
    059                        else
    060                        {
    061                            flag = false;
    062                        }
    063                    }
    064                }
    065            }
    066
    067            if (!flag)
    068            {
    069                return false;
    070            }
    071            else
    072            {
    073                l1 = par1World.getBlockId(par3, par4 - 1, par5);
    074                Block soil = Block.blocksList[l1];
    075                boolean isValidSoil = soil != null && soil.canSustainPlant(par1World, par3, par4 - 1, par5, ForgeDirection.UP, (BlockSapling)Block.sapling);
    076
    077                if (isValidSoil && par4 < 256 - l - 1)
    078                {
    079                    soil.onPlantGrow(par1World, par3, par4 - 1, par5, par3, par4, par5);
    080                    k2 = par2Random.nextInt(2);
    081                    i2 = 1;
    082                    byte b0 = 0;
    083                    int i3;
    084                    int j3;
    085
    086                    for (j2 = 0; j2 <= j1; ++j2)
    087                    {
    088                        j3 = par4 + l - j2;
    089
    090                        for (i3 = par3 - k2; i3 <= par3 + k2; ++i3)
    091                        {
    092                            int k3 = i3 - par3;
    093
    094                            for (int l3 = par5 - k2; l3 <= par5 + k2; ++l3)
    095                            {
    096                                int i4 = l3 - par5;
    097
    098                                Block block = Block.blocksList[par1World.getBlockId(i3, j3, l3)];
    099
    100                                if ((Math.abs(k3) != k2 || Math.abs(i4) != k2 || k2 <= 0) &&
    101                                    (block == null || block.canBeReplacedByLeaves(par1World, i3, j3, l3)))
    102                                {
    103                                    this.setBlockAndMetadata(par1World, i3, j3, l3, Block.leaves.blockID, 1);
    104                                }
    105                            }
    106                        }
    107
    108                        if (k2 >= i2)
    109                        {
    110                            k2 = b0;
    111                            b0 = 1;
    112                            ++i2;
    113
    114                            if (i2 > k1)
    115                            {
    116                                i2 = k1;
    117                            }
    118                        }
    119                        else
    120                        {
    121                            ++k2;
    122                        }
    123                    }
    124
    125                    j2 = par2Random.nextInt(3);
    126
    127                    for (j3 = 0; j3 < l - j2; ++j3)
    128                    {
    129                        i3 = par1World.getBlockId(par3, par4 + j3, par5);
    130
    131                        Block block = Block.blocksList[i3];
    132
    133                        if (i3 == 0 || block == null || block.isLeaves(par1World, par3, par4 + j3, par5))
    134                        {
    135                            this.setBlockAndMetadata(par1World, par3, par4 + j3, 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}