    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class WorldGenSwamp extends WorldGenerator
    006    {
    007        public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    008        {
    009            int var6;
    010
    011            for (var6 = par2Random.nextInt(4) + 5; par1World.getBlockMaterial(par3, par4 - 1, par5) == Material.water; --par4)
    012            {
    013                ;
    014            }
    015
    016            boolean var7 = true;
    017
    018            if (par4 >= 1 && par4 + var6 + 1 <= 128)
    019            {
    020                int var8;
    021                int var10;
    022                int var11;
    023                int var12;
    024
    025                for (var8 = par4; var8 <= par4 + 1 + var6; ++var8)
    026                {
    027                    byte var9 = 1;
    028
    029                    if (var8 == par4)
    030                    {
    031                        var9 = 0;
    032                    }
    033
    034                    if (var8 >= par4 + 1 + var6 - 2)
    035                    {
    036                        var9 = 3;
    037                    }
    038
    039                    for (var10 = par3 - var9; var10 <= par3 + var9 && var7; ++var10)
    040                    {
    041                        for (var11 = par5 - var9; var11 <= par5 + var9 && var7; ++var11)
    042                        {
    043                            if (var8 >= 0 && var8 < 128)
    044                            {
    045                                var12 = par1World.getBlockId(var10, var8, var11);
    046
    047                                if (var12 != 0 && (Block.blocksList[var12] != null && !Block.blocksList[var12].isLeaves(par1World, var10, var8, var11)))
    048                                {
    049                                    if (var12 != Block.waterStill.blockID && var12 != Block.waterMoving.blockID)
    050                                    {
    051                                        var7 = false;
    052                                    }
    053                                    else if (var8 > par4)
    054                                    {
    055                                        var7 = false;
    056                                    }
    057                                }
    058                            }
    059                            else
    060                            {
    061                                var7 = false;
    062                            }
    063                        }
    064                    }
    065                }
    066
    067                if (!var7)
    068                {
    069                    return false;
    070                }
    071                else
    072                {
    073                    var8 = par1World.getBlockId(par3, par4 - 1, par5);
    074
    075                    if ((var8 == Block.grass.blockID || var8 == Block.dirt.blockID) && par4 < 128 - var6 - 1)
    076                    {
    077                        this.setBlock(par1World, par3, par4 - 1, par5, Block.dirt.blockID);
    078                        int var13;
    079                        int var16;
    080
    081                        for (var16 = par4 - 3 + var6; var16 <= par4 + var6; ++var16)
    082                        {
    083                            var10 = var16 - (par4 + var6);
    084                            var11 = 2 - var10 / 2;
    085
    086                            for (var12 = par3 - var11; var12 <= par3 + var11; ++var12)
    087                            {
    088                                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.setBlock(par1World, var12, var16, var14, Block.leaves.blockID);
    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)) || var10 == Block.waterMoving.blockID || var10 == Block.waterStill.blockID)
    112                            {
    113                                this.setBlock(par1World, par3, par4 + var16, par5, Block.wood.blockID);
    114                            }
    115                        }
    116
    117                        for (var16 = par4 - 3 + var6; var16 <= par4 + var6; ++var16)
    118                        {
    119                            var10 = var16 - (par4 + var6);
    120                            var11 = 2 - var10 / 2;
    121
    122                            for (var12 = par3 - var11; var12 <= par3 + var11; ++var12)
    123                            {
    124                                for (var13 = par5 - var11; var13 <= par5 + var11; ++var13)
    125                                {
    126                                    Block block = Block.blocksList[par1World.getBlockId(var12, var16, var13)];
    127                                    if (block != null && block.isLeaves(par1World, var12, var16, var13))
    128                                    {
    129                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(var12 - 1, var16, var13) == 0)
    130                                        {
    131                                            this.generateVines(par1World, var12 - 1, var16, var13, 8);
    132                                        }
    133
    134                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(var12 + 1, var16, var13) == 0)
    135                                        {
    136                                            this.generateVines(par1World, var12 + 1, var16, var13, 2);
    137                                        }
    138
    139                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(var12, var16, var13 - 1) == 0)
    140                                        {
    141                                            this.generateVines(par1World, var12, var16, var13 - 1, 1);
    142                                        }
    143
    144                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(var12, var16, var13 + 1) == 0)
    145                                        {
    146                                            this.generateVines(par1World, var12, var16, var13 + 1, 4);
    147                                        }
    148                                    }
    149                                }
    150                            }
    151                        }
    152
    153                        return true;
    154                    }
    155                    else
    156                    {
    157                        return false;
    158                    }
    159                }
    160            }
    161            else
    162            {
    163                return false;
    164            }
    165        }
    166
    167        /**
    168         * Generates vines at the given position until it hits a block.
    169         */
    170        private void generateVines(World par1World, int par2, int par3, int par4, int par5)
    171        {
    172            this.setBlockAndMetadata(par1World, par2, par3, par4, Block.vine.blockID, par5);
    173            int var6 = 4;
    174
    175            while (true)
    176            {
    177                --par3;
    178
    179                if (par1World.getBlockId(par2, par3, par4) != 0 || var6 <= 0)
    180                {
    181                    return;
    182                }
    183
    184                this.setBlockAndMetadata(par1World, par2, par3, par4, Block.vine.blockID, par5);
    185                --var6;
    186            }
    187        }
    188    }