    001package net.minecraft.world.gen.feature;
    002
    003import java.util.Random;
    004import net.minecraft.block.Block;
    005import net.minecraft.block.material.Material;
    006import net.minecraft.world.World;
    007
    008public class WorldGenSwamp extends WorldGenerator
    009{
    010    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    011    {
    012        int l;
    013
    014        for (l = par2Random.nextInt(4) + 5; par1World.getBlockMaterial(par3, par4 - 1, par5) == Material.water; --par4)
    015        {
    016            ;
    017        }
    018
    019        boolean flag = true;
    020
    021        if (par4 >= 1 && par4 + l + 1 <= 128)
    022        {
    023            int i1;
    024            int j1;
    025            int k1;
    026            int l1;
    027
    028            for (i1 = par4; i1 <= par4 + 1 + l; ++i1)
    029            {
    030                byte b0 = 1;
    031
    032                if (i1 == par4)
    033                {
    034                    b0 = 0;
    035                }
    036
    037                if (i1 >= par4 + 1 + l - 2)
    038                {
    039                    b0 = 3;
    040                }
    041
    042                for (j1 = par3 - b0; j1 <= par3 + b0 && flag; ++j1)
    043                {
    044                    for (k1 = par5 - b0; k1 <= par5 + b0 && flag; ++k1)
    045                    {
    046                        if (i1 >= 0 && i1 < 128)
    047                        {
    048                            l1 = par1World.getBlockId(j1, i1, k1);
    049
    050                            if (l1 != 0 && (Block.blocksList[l1] != null && !Block.blocksList[l1].isLeaves(par1World, j1, i1, k1)))
    051                            {
    052                                if (l1 != Block.waterStill.blockID && l1 != Block.waterMoving.blockID)
    053                                {
    054                                    flag = false;
    055                                }
    056                                else if (i1 > par4)
    057                                {
    058                                    flag = false;
    059                                }
    060                            }
    061                        }
    062                        else
    063                        {
    064                            flag = false;
    065                        }
    066                    }
    067                }
    068            }
    069
    070            if (!flag)
    071            {
    072                return false;
    073            }
    074            else
    075            {
    076                i1 = par1World.getBlockId(par3, par4 - 1, par5);
    077
    078                if ((i1 == Block.grass.blockID || i1 == Block.dirt.blockID) && par4 < 128 - l - 1)
    079                {
    080                    this.setBlock(par1World, par3, par4 - 1, par5, Block.dirt.blockID);
    081                    int i2;
    082                    int j2;
    083
    084                    for (j2 = par4 - 3 + l; j2 <= par4 + l; ++j2)
    085                    {
    086                        j1 = j2 - (par4 + l);
    087                        k1 = 2 - j1 / 2;
    088
    089                        for (l1 = par3 - k1; l1 <= par3 + k1; ++l1)
    090                        {
    091                            i2 = l1 - par3;
    092
    093                            for (int k2 = par5 - k1; k2 <= par5 + k1; ++k2)
    094                            {
    095                                int l2 = k2 - par5;
    096
    097                                Block block = Block.blocksList[par1World.getBlockId(l1, j2, k2)];
    098
    099                                if ((Math.abs(i2) != k1 || Math.abs(l2) != k1 || par2Random.nextInt(2) != 0 && j1 != 0) &&
    100                                    (block == null || block.canBeReplacedByLeaves(par1World, l1, j2, k2)))
    101                                {
    102                                    this.setBlock(par1World, l1, j2, k2, Block.leaves.blockID);
    103                                }
    104                            }
    105                        }
    106                    }
    107
    108                    for (j2 = 0; j2 < l; ++j2)
    109                    {
    110                        j1 = par1World.getBlockId(par3, par4 + j2, par5);
    111
    112                        Block block = Block.blocksList[j1];
    113
    114                        if (j1 == 0 || (block != null && block.isLeaves(par1World, par3, par4 + j2, par5)) || j1 == Block.waterMoving.blockID || j1 == Block.waterStill.blockID)
    115                        {
    116                            this.setBlock(par1World, par3, par4 + j2, par5, Block.wood.blockID);
    117                        }
    118                    }
    119
    120                    for (j2 = par4 - 3 + l; j2 <= par4 + l; ++j2)
    121                    {
    122                        j1 = j2 - (par4 + l);
    123                        k1 = 2 - j1 / 2;
    124
    125                        for (l1 = par3 - k1; l1 <= par3 + k1; ++l1)
    126                        {
    127                            for (i2 = par5 - k1; i2 <= par5 + k1; ++i2)
    128                            {
    129                                Block block = Block.blocksList[par1World.getBlockId(l1, j2, i2)];
    130                                if (block != null && block.isLeaves(par1World, l1, j2, i2))
    131                                {
    132                                    if (par2Random.nextInt(4) == 0 && par1World.getBlockId(l1 - 1, j2, i2) == 0)
    133                                    {
    134                                        this.generateVines(par1World, l1 - 1, j2, i2, 8);
    135                                    }
    136
    137                                    if (par2Random.nextInt(4) == 0 && par1World.getBlockId(l1 + 1, j2, i2) == 0)
    138                                    {
    139                                        this.generateVines(par1World, l1 + 1, j2, i2, 2);
    140                                    }
    141
    142                                    if (par2Random.nextInt(4) == 0 && par1World.getBlockId(l1, j2, i2 - 1) == 0)
    143                                    {
    144                                        this.generateVines(par1World, l1, j2, i2 - 1, 1);
    145                                    }
    146
    147                                    if (par2Random.nextInt(4) == 0 && par1World.getBlockId(l1, j2, i2 + 1) == 0)
    148                                    {
    149                                        this.generateVines(par1World, l1, j2, i2 + 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 i1 = 4;
    177
    178        while (true)
    179        {
    180            --par3;
    181
    182            if (par1World.getBlockId(par2, par3, par4) != 0 || i1 <= 0)
    183            {
    184                return;
    185            }
    186
    187            this.setBlockAndMetadata(par1World, par2, par3, par4, Block.vine.blockID, par5);
    188            --i1;
    189        }
    190    }
    191}