    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class WorldGenHugeTrees extends WorldGenerator
    006    {
    007        /** The base height of the tree */
    008        private final int baseHeight;
    009
    010        /** Sets the metadata for the wood blocks used */
    011        private final int woodMetadata;
    012
    013        /** Sets the metadata for the leaves used in huge trees */
    014        private final int leavesMetadata;
    015
    016        public WorldGenHugeTrees(boolean par1, int par2, int par3, int par4)
    017        {
    018            super(par1);
    019            this.baseHeight = par2;
    020            this.woodMetadata = par3;
    021            this.leavesMetadata = par4;
    022        }
    023
    024        public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    025        {
    026            int var6 = par2Random.nextInt(3) + this.baseHeight;
    027            boolean var7 = true;
    028
    029            if (par4 >= 1 && par4 + var6 + 1 <= 256)
    030            {
    031                int var8;
    032                int var10;
    033                int var11;
    034                int var12;
    035
    036                for (var8 = par4; var8 <= par4 + 1 + var6; ++var8)
    037                {
    038                    byte var9 = 2;
    039
    040                    if (var8 == par4)
    041                    {
    042                        var9 = 1;
    043                    }
    044
    045                    if (var8 >= par4 + 1 + var6 - 2)
    046                    {
    047                        var9 = 2;
    048                    }
    049
    050                    for (var10 = par3 - var9; var10 <= par3 + var9 && var7; ++var10)
    051                    {
    052                        for (var11 = par5 - var9; var11 <= par5 + var9 && var7; ++var11)
    053                        {
    054                            if (var8 >= 0 && var8 < 256)
    055                            {
    056                                var12 = par1World.getBlockId(var10, var8, var11);
    057
    058                                if (var12 != 0 &&
    059                                   (Block.blocksList[var12] != null && !Block.blocksList[var12].isLeaves(par1World, var10, var8, var11)) &&
    060                                   var12 != Block.grass.blockID &&
    061                                   var12 != Block.dirt.blockID &&
    062                                   (Block.blocksList[var12] != null && !Block.blocksList[var12].isWood(par1World, var10, var8, var11)) &&
    063                                   var12 != Block.sapling.blockID)
    064                                {
    065                                    var7 = false;
    066                                }
    067                            }
    068                            else
    069                            {
    070                                var7 = false;
    071                            }
    072                        }
    073                    }
    074                }
    075
    076                if (!var7)
    077                {
    078                    return false;
    079                }
    080                else
    081                {
    082                    var8 = par1World.getBlockId(par3, par4 - 1, par5);
    083
    084                    if ((var8 == Block.grass.blockID || var8 == Block.dirt.blockID) && par4 < 256 - var6 - 1)
    085                    {
    086                        par1World.setBlock(par3, par4 - 1, par5, Block.dirt.blockID);
    087                        par1World.setBlock(par3 + 1, par4 - 1, par5, Block.dirt.blockID);
    088                        par1World.setBlock(par3, par4 - 1, par5 + 1, Block.dirt.blockID);
    089                        par1World.setBlock(par3 + 1, par4 - 1, par5 + 1, Block.dirt.blockID);
    090                        this.growLeaves(par1World, par3, par5, par4 + var6, 2, par2Random);
    091
    092                        for (int var14 = par4 + var6 - 2 - par2Random.nextInt(4); var14 > par4 + var6 / 2; var14 -= 2 + par2Random.nextInt(4))
    093                        {
    094                            float var15 = par2Random.nextFloat() * (float)Math.PI * 2.0F;
    095                            var11 = par3 + (int)(0.5F + MathHelper.cos(var15) * 4.0F);
    096                            var12 = par5 + (int)(0.5F + MathHelper.sin(var15) * 4.0F);
    097                            this.growLeaves(par1World, var11, var12, var14, 0, par2Random);
    098
    099                            for (int var13 = 0; var13 < 5; ++var13)
    100                            {
    101                                var11 = par3 + (int)(1.5F + MathHelper.cos(var15) * (float)var13);
    102                                var12 = par5 + (int)(1.5F + MathHelper.sin(var15) * (float)var13);
    103                                this.setBlockAndMetadata(par1World, var11, var14 - 3 + var13 / 2, var12, Block.wood.blockID, this.woodMetadata);
    104                            }
    105                        }
    106
    107                        for (var10 = 0; var10 < var6; ++var10)
    108                        {
    109                            var11 = par1World.getBlockId(par3, par4 + var10, par5);
    110
    111                            if (var11 == 0 || Block.blocksList[var11] == null || Block.blocksList[var11].isLeaves(par1World, par3, par4 + var10, par5))
    112                            {
    113                                this.setBlockAndMetadata(par1World, par3, par4 + var10, par5, Block.wood.blockID, this.woodMetadata);
    114
    115                                if (var10 > 0)
    116                                {
    117                                    if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 - 1, par4 + var10, par5))
    118                                    {
    119                                        this.setBlockAndMetadata(par1World, par3 - 1, par4 + var10, par5, Block.vine.blockID, 8);
    120                                    }
    121
    122                                    if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + var10, par5 - 1))
    123                                    {
    124                                        this.setBlockAndMetadata(par1World, par3, par4 + var10, par5 - 1, Block.vine.blockID, 1);
    125                                    }
    126                                }
    127                            }
    128
    129                            if (var10 < var6 - 1)
    130                            {
    131                                var11 = par1World.getBlockId(par3 + 1, par4 + var10, par5);
    132
    133                                if (var11 == 0 || Block.blocksList[var11] == null || Block.blocksList[var11].isLeaves(par1World, par3 + 1, par4 + var10, par5))
    134                                {
    135                                    this.setBlockAndMetadata(par1World, par3 + 1, par4 + var10, par5, Block.wood.blockID, this.woodMetadata);
    136
    137                                    if (var10 > 0)
    138                                    {
    139                                        if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 + 2, par4 + var10, par5))
    140                                        {
    141                                            this.setBlockAndMetadata(par1World, par3 + 2, par4 + var10, par5, Block.vine.blockID, 2);
    142                                        }
    143
    144                                        if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 + 1, par4 + var10, par5 - 1))
    145                                        {
    146                                            this.setBlockAndMetadata(par1World, par3 + 1, par4 + var10, par5 - 1, Block.vine.blockID, 1);
    147                                        }
    148                                    }
    149                                }
    150
    151                                var11 = par1World.getBlockId(par3 + 1, par4 + var10, par5 + 1);
    152
    153                                if (var11 == 0 || Block.blocksList[var11] == null || Block.blocksList[var11].isLeaves(par1World, par3 + 1, par4 + var10, par5 + 1))
    154                                {
    155                                    this.setBlockAndMetadata(par1World, par3 + 1, par4 + var10, par5 + 1, Block.wood.blockID, this.woodMetadata);
    156
    157                                    if (var10 > 0)
    158                                    {
    159                                        if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 + 2, par4 + var10, par5 + 1))
    160                                        {
    161                                            this.setBlockAndMetadata(par1World, par3 + 2, par4 + var10, par5 + 1, Block.vine.blockID, 2);
    162                                        }
    163
    164                                        if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 + 1, par4 + var10, par5 + 2))
    165                                        {
    166                                            this.setBlockAndMetadata(par1World, par3 + 1, par4 + var10, par5 + 2, Block.vine.blockID, 4);
    167                                        }
    168                                    }
    169                                }
    170
    171                                var11 = par1World.getBlockId(par3, par4 + var10, par5 + 1);
    172
    173                                if (var11 == 0 || Block.blocksList[var11] == null || Block.blocksList[var11].isLeaves(par1World, par3, par4 + var10, par5 + 1))
    174                                {
    175                                    this.setBlockAndMetadata(par1World, par3, par4 + var10, par5 + 1, Block.wood.blockID, this.woodMetadata);
    176
    177                                    if (var10 > 0)
    178                                    {
    179                                        if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 - 1, par4 + var10, par5 + 1))
    180                                        {
    181                                            this.setBlockAndMetadata(par1World, par3 - 1, par4 + var10, par5 + 1, Block.vine.blockID, 8);
    182                                        }
    183
    184                                        if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + var10, par5 + 2))
    185                                        {
    186                                            this.setBlockAndMetadata(par1World, par3, par4 + var10, par5 + 2, Block.vine.blockID, 4);
    187                                        }
    188                                    }
    189                                }
    190                            }
    191                        }
    192
    193                        return true;
    194                    }
    195                    else
    196                    {
    197                        return false;
    198                    }
    199                }
    200            }
    201            else
    202            {
    203                return false;
    204            }
    205        }
    206
    207        private void growLeaves(World par1World, int par2, int par3, int par4, int par5, Random par6Random)
    208        {
    209            byte var7 = 2;
    210
    211            for (int var8 = par4 - var7; var8 <= par4; ++var8)
    212            {
    213                int var9 = var8 - par4;
    214                int var10 = par5 + 1 - var9;
    215
    216                for (int var11 = par2 - var10; var11 <= par2 + var10 + 1; ++var11)
    217                {
    218                    int var12 = var11 - par2;
    219
    220                    for (int var13 = par3 - var10; var13 <= par3 + var10 + 1; ++var13)
    221                    {
    222                        int var14 = var13 - par3;
    223
    224                        Block block = Block.blocksList[par1World.getBlockId(var11, var8, var13)];
    225
    226                        if ((var12 >= 0 || var14 >= 0 || var12 * var12 + var14 * var14 <= var10 * var10) &&
    227                            (var12 <= 0 && var14 <= 0 || var12 * var12 + var14 * var14 <= (var10 + 1) * (var10 + 1)) &&
    228                            (par6Random.nextInt(4) != 0 || var12 * var12 + var14 * var14 <= (var10 - 1) * (var10 - 1)) &&
    229                            (block == null || block.canBeReplacedByLeaves(par1World, var11, var8, var13)))
    230                        {
    231                            this.setBlockAndMetadata(par1World, var11, var8, var13, Block.leaves.blockID, this.leavesMetadata);
    232                        }
    233                    }
    234                }
    235            }
    236        }
    237    }