    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.EnumSkyBlock;
    007    import net.minecraft.world.World;
    008    import net.minecraft.world.biome.BiomeGenBase;
    009
    010    public 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[] var6 = new boolean[2048];
    036                int var7 = par2Random.nextInt(4) + 4;
    037                int var8;
    038
    039                for (var8 = 0; var8 < var7; ++var8)
    040                {
    041                    double var9 = par2Random.nextDouble() * 6.0D + 3.0D;
    042                    double var11 = par2Random.nextDouble() * 4.0D + 2.0D;
    043                    double var13 = par2Random.nextDouble() * 6.0D + 3.0D;
    044                    double var15 = par2Random.nextDouble() * (16.0D - var9 - 2.0D) + 1.0D + var9 / 2.0D;
    045                    double var17 = par2Random.nextDouble() * (8.0D - var11 - 4.0D) + 2.0D + var11 / 2.0D;
    046                    double var19 = par2Random.nextDouble() * (16.0D - var13 - 2.0D) + 1.0D + var13 / 2.0D;
    047
    048                    for (int var21 = 1; var21 < 15; ++var21)
    049                    {
    050                        for (int var22 = 1; var22 < 15; ++var22)
    051                        {
    052                            for (int var23 = 1; var23 < 7; ++var23)
    053                            {
    054                                double var24 = ((double)var21 - var15) / (var9 / 2.0D);
    055                                double var26 = ((double)var23 - var17) / (var11 / 2.0D);
    056                                double var28 = ((double)var22 - var19) / (var13 / 2.0D);
    057                                double var30 = var24 * var24 + var26 * var26 + var28 * var28;
    058
    059                                if (var30 < 1.0D)
    060                                {
    061                                    var6[(var21 * 16 + var22) * 8 + var23] = true;
    062                                }
    063                            }
    064                        }
    065                    }
    066                }
    067
    068                int var10;
    069                int var32;
    070                boolean var33;
    071
    072                for (var8 = 0; var8 < 16; ++var8)
    073                {
    074                    for (var32 = 0; var32 < 16; ++var32)
    075                    {
    076                        for (var10 = 0; var10 < 8; ++var10)
    077                        {
    078                            var33 = !var6[(var8 * 16 + var32) * 8 + var10] && (var8 < 15 && var6[((var8 + 1) * 16 + var32) * 8 + var10] || var8 > 0 && var6[((var8 - 1) * 16 + var32) * 8 + var10] || var32 < 15 && var6[(var8 * 16 + var32 + 1) * 8 + var10] || var32 > 0 && var6[(var8 * 16 + (var32 - 1)) * 8 + var10] || var10 < 7 && var6[(var8 * 16 + var32) * 8 + var10 + 1] || var10 > 0 && var6[(var8 * 16 + var32) * 8 + (var10 - 1)]);
    079
    080                            if (var33)
    081                            {
    082                                Material var12 = par1World.getBlockMaterial(par3 + var8, par4 + var10, par5 + var32);
    083
    084                                if (var10 >= 4 && var12.isLiquid())
    085                                {
    086                                    return false;
    087                                }
    088
    089                                if (var10 < 4 && !var12.isSolid() && par1World.getBlockId(par3 + var8, par4 + var10, par5 + var32) != this.blockIndex)
    090                                {
    091                                    return false;
    092                                }
    093                            }
    094                        }
    095                    }
    096                }
    097
    098                for (var8 = 0; var8 < 16; ++var8)
    099                {
    100                    for (var32 = 0; var32 < 16; ++var32)
    101                    {
    102                        for (var10 = 0; var10 < 8; ++var10)
    103                        {
    104                            if (var6[(var8 * 16 + var32) * 8 + var10])
    105                            {
    106                                par1World.setBlock(par3 + var8, par4 + var10, par5 + var32, var10 >= 4 ? 0 : this.blockIndex);
    107                            }
    108                        }
    109                    }
    110                }
    111
    112                for (var8 = 0; var8 < 16; ++var8)
    113                {
    114                    for (var32 = 0; var32 < 16; ++var32)
    115                    {
    116                        for (var10 = 4; var10 < 8; ++var10)
    117                        {
    118                            if (var6[(var8 * 16 + var32) * 8 + var10] && par1World.getBlockId(par3 + var8, par4 + var10 - 1, par5 + var32) == Block.dirt.blockID && par1World.getSavedLightValue(EnumSkyBlock.Sky, par3 + var8, par4 + var10, par5 + var32) > 0)
    119                            {
    120                                BiomeGenBase var35 = par1World.getBiomeGenForCoords(par3 + var8, par5 + var32);
    121
    122                                if (var35.topBlock == Block.mycelium.blockID)
    123                                {
    124                                    par1World.setBlock(par3 + var8, par4 + var10 - 1, par5 + var32, Block.mycelium.blockID);
    125                                }
    126                                else
    127                                {
    128                                    par1World.setBlock(par3 + var8, par4 + var10 - 1, par5 + var32, Block.grass.blockID);
    129                                }
    130                            }
    131                        }
    132                    }
    133                }
    134
    135                if (Block.blocksList[this.blockIndex].blockMaterial == Material.lava)
    136                {
    137                    for (var8 = 0; var8 < 16; ++var8)
    138                    {
    139                        for (var32 = 0; var32 < 16; ++var32)
    140                        {
    141                            for (var10 = 0; var10 < 8; ++var10)
    142                            {
    143                                var33 = !var6[(var8 * 16 + var32) * 8 + var10] && (var8 < 15 && var6[((var8 + 1) * 16 + var32) * 8 + var10] || var8 > 0 && var6[((var8 - 1) * 16 + var32) * 8 + var10] || var32 < 15 && var6[(var8 * 16 + var32 + 1) * 8 + var10] || var32 > 0 && var6[(var8 * 16 + (var32 - 1)) * 8 + var10] || var10 < 7 && var6[(var8 * 16 + var32) * 8 + var10 + 1] || var10 > 0 && var6[(var8 * 16 + var32) * 8 + (var10 - 1)]);
    144
    145                                if (var33 && (var10 < 4 || par2Random.nextInt(2) != 0) && par1World.getBlockMaterial(par3 + var8, par4 + var10, par5 + var32).isSolid())
    146                                {
    147                                    par1World.setBlock(par3 + var8, par4 + var10, par5 + var32, Block.stone.blockID);
    148                                }
    149                            }
    150                        }
    151                    }
    152                }
    153
    154                if (Block.blocksList[this.blockIndex].blockMaterial == Material.water)
    155                {
    156                    for (var8 = 0; var8 < 16; ++var8)
    157                    {
    158                        for (var32 = 0; var32 < 16; ++var32)
    159                        {
    160                            byte var34 = 4;
    161
    162                            if (par1World.isBlockFreezable(par3 + var8, par4 + var34, par5 + var32))
    163                            {
    164                                par1World.setBlock(par3 + var8, par4 + var34, par5 + var32, Block.ice.blockID);
    165                            }
    166                        }
    167                    }
    168                }
    169
    170                return true;
    171            }
    172        }
    173    }