    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.EnumSkyBlock;
    007import net.minecraft.world.World;
    008import net.minecraft.world.biome.BiomeGenBase;
    009
    010public class WorldGenLakes extends WorldGenerator
    011{
    012    private int blockIndex;
    013
    014    public WorldGenLakes(int par1)
    015    {
    016        this.blockIndex = par1;
    017    }
    018
    019    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    020    {
    021        par3 -= 8;
    022
    023        for (par5 -= 8; par4 > 5 && par1World.isAirBlock(par3, par4, par5); --par4)
    024        {
    025            ;
    026        }
    027
    028        if (par4 <= 4)
    029        {
    030            return false;
    031        }
    032        else
    033        {
    034            par4 -= 4;
    035            boolean[] aboolean = new boolean[2048];
    036            int l = par2Random.nextInt(4) + 4;
    037            int i1;
    038
    039            for (i1 = 0; i1 < l; ++i1)
    040            {
    041                double d0 = par2Random.nextDouble() * 6.0D + 3.0D;
    042                double d1 = par2Random.nextDouble() * 4.0D + 2.0D;
    043                double d2 = par2Random.nextDouble() * 6.0D + 3.0D;
    044                double d3 = par2Random.nextDouble() * (16.0D - d0 - 2.0D) + 1.0D + d0 / 2.0D;
    045                double d4 = par2Random.nextDouble() * (8.0D - d1 - 4.0D) + 2.0D + d1 / 2.0D;
    046                double d5 = par2Random.nextDouble() * (16.0D - d2 - 2.0D) + 1.0D + d2 / 2.0D;
    047
    048                for (int j1 = 1; j1 < 15; ++j1)
    049                {
    050                    for (int k1 = 1; k1 < 15; ++k1)
    051                    {
    052                        for (int l1 = 1; l1 < 7; ++l1)
    053                        {
    054                            double d6 = ((double)j1 - d3) / (d0 / 2.0D);
    055                            double d7 = ((double)l1 - d4) / (d1 / 2.0D);
    056                            double d8 = ((double)k1 - d5) / (d2 / 2.0D);
    057                            double d9 = d6 * d6 + d7 * d7 + d8 * d8;
    058
    059                            if (d9 < 1.0D)
    060                            {
    061                                aboolean[(j1 * 16 + k1) * 8 + l1] = true;
    062                            }
    063                        }
    064                    }
    065                }
    066            }
    067
    068            int i2;
    069            int j2;
    070            boolean flag;
    071
    072            for (i1 = 0; i1 < 16; ++i1)
    073            {
    074                for (j2 = 0; j2 < 16; ++j2)
    075                {
    076                    for (i2 = 0; i2 < 8; ++i2)
    077                    {
    078                        flag = !aboolean[(i1 * 16 + j2) * 8 + i2] && (i1 < 15 && aboolean[((i1 + 1) * 16 + j2) * 8 + i2] || i1 > 0 && aboolean[((i1 - 1) * 16 + j2) * 8 + i2] || j2 < 15 && aboolean[(i1 * 16 + j2 + 1) * 8 + i2] || j2 > 0 && aboolean[(i1 * 16 + (j2 - 1)) * 8 + i2] || i2 < 7 && aboolean[(i1 * 16 + j2) * 8 + i2 + 1] || i2 > 0 && aboolean[(i1 * 16 + j2) * 8 + (i2 - 1)]);
    079
    080                        if (flag)
    081                        {
    082                            Material material = par1World.getBlockMaterial(par3 + i1, par4 + i2, par5 + j2);
    083
    084                            if (i2 >= 4 && material.isLiquid())
    085                            {
    086                                return false;
    087                            }
    088
    089                            if (i2 < 4 && !material.isSolid() && par1World.getBlockId(par3 + i1, par4 + i2, par5 + j2) != this.blockIndex)
    090                            {
    091                                return false;
    092                            }
    093                        }
    094                    }
    095                }
    096            }
    097
    098            for (i1 = 0; i1 < 16; ++i1)
    099            {
    100                for (j2 = 0; j2 < 16; ++j2)
    101                {
    102                    for (i2 = 0; i2 < 8; ++i2)
    103                    {
    104                        if (aboolean[(i1 * 16 + j2) * 8 + i2])
    105                        {
    106                            par1World.setBlock(par3 + i1, par4 + i2, par5 + j2, i2 >= 4 ? 0 : this.blockIndex, 0, 2);
    107                        }
    108                    }
    109                }
    110            }
    111
    112            for (i1 = 0; i1 < 16; ++i1)
    113            {
    114                for (j2 = 0; j2 < 16; ++j2)
    115                {
    116                    for (i2 = 4; i2 < 8; ++i2)
    117                    {
    118                        if (aboolean[(i1 * 16 + j2) * 8 + i2] && par1World.getBlockId(par3 + i1, par4 + i2 - 1, par5 + j2) == Block.dirt.blockID && par1World.getSavedLightValue(EnumSkyBlock.Sky, par3 + i1, par4 + i2, par5 + j2) > 0)
    119                        {
    120                            BiomeGenBase biomegenbase = par1World.getBiomeGenForCoords(par3 + i1, par5 + j2);
    121
    122                            if (biomegenbase.topBlock == Block.mycelium.blockID)
    123                            {
    124                                par1World.setBlock(par3 + i1, par4 + i2 - 1, par5 + j2, Block.mycelium.blockID, 0, 2);
    125                            }
    126                            else
    127                            {
    128                                par1World.setBlock(par3 + i1, par4 + i2 - 1, par5 + j2, Block.grass.blockID, 0, 2);
    129                            }
    130                        }
    131                    }
    132                }
    133            }
    134
    135            if (Block.blocksList[this.blockIndex].blockMaterial == Material.lava)
    136            {
    137                for (i1 = 0; i1 < 16; ++i1)
    138                {
    139                    for (j2 = 0; j2 < 16; ++j2)
    140                    {
    141                        for (i2 = 0; i2 < 8; ++i2)
    142                        {
    143                            flag = !aboolean[(i1 * 16 + j2) * 8 + i2] && (i1 < 15 && aboolean[((i1 + 1) * 16 + j2) * 8 + i2] || i1 > 0 && aboolean[((i1 - 1) * 16 + j2) * 8 + i2] || j2 < 15 && aboolean[(i1 * 16 + j2 + 1) * 8 + i2] || j2 > 0 && aboolean[(i1 * 16 + (j2 - 1)) * 8 + i2] || i2 < 7 && aboolean[(i1 * 16 + j2) * 8 + i2 + 1] || i2 > 0 && aboolean[(i1 * 16 + j2) * 8 + (i2 - 1)]);
    144
    145                            if (flag && (i2 < 4 || par2Random.nextInt(2) != 0) && par1World.getBlockMaterial(par3 + i1, par4 + i2, par5 + j2).isSolid())
    146                            {
    147                                par1World.setBlock(par3 + i1, par4 + i2, par5 + j2, Block.stone.blockID, 0, 2);
    148                            }
    149                        }
    150                    }
    151                }
    152            }
    153
    154            if (Block.blocksList[this.blockIndex].blockMaterial == Material.water)
    155            {
    156                for (i1 = 0; i1 < 16; ++i1)
    157                {
    158                    for (j2 = 0; j2 < 16; ++j2)
    159                    {
    160                        byte b0 = 4;
    161
    162                        if (par1World.isBlockFreezable(par3 + i1, par4 + b0, par5 + j2))
    163                        {
    164                            par1World.setBlock(par3 + i1, par4 + b0, par5 + j2, Block.ice.blockID, 0, 2);
    165                        }
    166                    }
    167                }
    168            }
    169
    170            return true;
    171        }
    172    }
    173}