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