    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import java.util.Random;
    005
    006    public class ChunkProviderEnd implements IChunkProvider
    007    {
    008        private Random endRNG;
    009        private NoiseGeneratorOctaves noiseGen1;
    010        private NoiseGeneratorOctaves noiseGen2;
    011        private NoiseGeneratorOctaves noiseGen3;
    012        public NoiseGeneratorOctaves noiseGen4;
    013        public NoiseGeneratorOctaves noiseGen5;
    014        private World endWorld;
    015        private double[] densities;
    016
    017        /** The biomes that are used to generate the chunk */
    018        private BiomeGenBase[] biomesForGeneration;
    019        double[] noiseData1;
    020        double[] noiseData2;
    021        double[] noiseData3;
    022        double[] noiseData4;
    023        double[] noiseData5;
    024        int[][] field_73203_h = new int[32][32];
    025
    026        public ChunkProviderEnd(World par1World, long par2)
    027        {
    028            this.endWorld = par1World;
    029            this.endRNG = new Random(par2);
    030            this.noiseGen1 = new NoiseGeneratorOctaves(this.endRNG, 16);
    031            this.noiseGen2 = new NoiseGeneratorOctaves(this.endRNG, 16);
    032            this.noiseGen3 = new NoiseGeneratorOctaves(this.endRNG, 8);
    033            this.noiseGen4 = new NoiseGeneratorOctaves(this.endRNG, 10);
    034            this.noiseGen5 = new NoiseGeneratorOctaves(this.endRNG, 16);
    035        }
    036
    037        public void generateTerrain(int par1, int par2, byte[] par3ArrayOfByte, BiomeGenBase[] par4ArrayOfBiomeGenBase)
    038        {
    039            byte var5 = 2;
    040            int var6 = var5 + 1;
    041            byte var7 = 33;
    042            int var8 = var5 + 1;
    043            this.densities = this.initializeNoiseField(this.densities, par1 * var5, 0, par2 * var5, var6, var7, var8);
    044
    045            for (int var9 = 0; var9 < var5; ++var9)
    046            {
    047                for (int var10 = 0; var10 < var5; ++var10)
    048                {
    049                    for (int var11 = 0; var11 < 32; ++var11)
    050                    {
    051                        double var12 = 0.25D;
    052                        double var14 = this.densities[((var9 + 0) * var8 + var10 + 0) * var7 + var11 + 0];
    053                        double var16 = this.densities[((var9 + 0) * var8 + var10 + 1) * var7 + var11 + 0];
    054                        double var18 = this.densities[((var9 + 1) * var8 + var10 + 0) * var7 + var11 + 0];
    055                        double var20 = this.densities[((var9 + 1) * var8 + var10 + 1) * var7 + var11 + 0];
    056                        double var22 = (this.densities[((var9 + 0) * var8 + var10 + 0) * var7 + var11 + 1] - var14) * var12;
    057                        double var24 = (this.densities[((var9 + 0) * var8 + var10 + 1) * var7 + var11 + 1] - var16) * var12;
    058                        double var26 = (this.densities[((var9 + 1) * var8 + var10 + 0) * var7 + var11 + 1] - var18) * var12;
    059                        double var28 = (this.densities[((var9 + 1) * var8 + var10 + 1) * var7 + var11 + 1] - var20) * var12;
    060
    061                        for (int var30 = 0; var30 < 4; ++var30)
    062                        {
    063                            double var31 = 0.125D;
    064                            double var33 = var14;
    065                            double var35 = var16;
    066                            double var37 = (var18 - var14) * var31;
    067                            double var39 = (var20 - var16) * var31;
    068
    069                            for (int var41 = 0; var41 < 8; ++var41)
    070                            {
    071                                int var42 = var41 + var9 * 8 << 11 | 0 + var10 * 8 << 7 | var11 * 4 + var30;
    072                                short var43 = 128;
    073                                double var44 = 0.125D;
    074                                double var46 = var33;
    075                                double var48 = (var35 - var33) * var44;
    076
    077                                for (int var50 = 0; var50 < 8; ++var50)
    078                                {
    079                                    int var51 = 0;
    080
    081                                    if (var46 > 0.0D)
    082                                    {
    083                                        var51 = Block.whiteStone.blockID;
    084                                    }
    085
    086                                    par3ArrayOfByte[var42] = (byte)var51;
    087                                    var42 += var43;
    088                                    var46 += var48;
    089                                }
    090
    091                                var33 += var37;
    092                                var35 += var39;
    093                            }
    094
    095                            var14 += var22;
    096                            var16 += var24;
    097                            var18 += var26;
    098                            var20 += var28;
    099                        }
    100                    }
    101                }
    102            }
    103        }
    104
    105        public void replaceBlocksForBiome(int par1, int par2, byte[] par3ArrayOfByte, BiomeGenBase[] par4ArrayOfBiomeGenBase)
    106        {
    107            for (int var5 = 0; var5 < 16; ++var5)
    108            {
    109                for (int var6 = 0; var6 < 16; ++var6)
    110                {
    111                    byte var7 = 1;
    112                    int var8 = -1;
    113                    byte var9 = (byte)Block.whiteStone.blockID;
    114                    byte var10 = (byte)Block.whiteStone.blockID;
    115
    116                    for (int var11 = 127; var11 >= 0; --var11)
    117                    {
    118                        int var12 = (var6 * 16 + var5) * 128 + var11;
    119                        byte var13 = par3ArrayOfByte[var12];
    120
    121                        if (var13 == 0)
    122                        {
    123                            var8 = -1;
    124                        }
    125                        else if (var13 == Block.stone.blockID)
    126                        {
    127                            if (var8 == -1)
    128                            {
    129                                if (var7 <= 0)
    130                                {
    131                                    var9 = 0;
    132                                    var10 = (byte)Block.whiteStone.blockID;
    133                                }
    134
    135                                var8 = var7;
    136
    137                                if (var11 >= 0)
    138                                {
    139                                    par3ArrayOfByte[var12] = var9;
    140                                }
    141                                else
    142                                {
    143                                    par3ArrayOfByte[var12] = var10;
    144                                }
    145                            }
    146                            else if (var8 > 0)
    147                            {
    148                                --var8;
    149                                par3ArrayOfByte[var12] = var10;
    150                            }
    151                        }
    152                    }
    153                }
    154            }
    155        }
    156
    157        /**
    158         * loads or generates the chunk at the chunk location specified
    159         */
    160        public Chunk loadChunk(int par1, int par2)
    161        {
    162            return this.provideChunk(par1, par2);
    163        }
    164
    165        /**
    166         * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
    167         * specified chunk from the map seed and chunk seed
    168         */
    169        public Chunk provideChunk(int par1, int par2)
    170        {
    171            this.endRNG.setSeed((long)par1 * 341873128712L + (long)par2 * 132897987541L);
    172            byte[] var3 = new byte[32768];
    173            this.biomesForGeneration = this.endWorld.getWorldChunkManager().loadBlockGeneratorData(this.biomesForGeneration, par1 * 16, par2 * 16, 16, 16);
    174            this.generateTerrain(par1, par2, var3, this.biomesForGeneration);
    175            this.replaceBlocksForBiome(par1, par2, var3, this.biomesForGeneration);
    176            Chunk var4 = new Chunk(this.endWorld, var3, par1, par2);
    177            byte[] var5 = var4.getBiomeArray();
    178
    179            for (int var6 = 0; var6 < var5.length; ++var6)
    180            {
    181                var5[var6] = (byte)this.biomesForGeneration[var6].biomeID;
    182            }
    183
    184            var4.generateSkylightMap();
    185            return var4;
    186        }
    187
    188        /**
    189         * generates a subset of the level's terrain data. Takes 7 arguments: the [empty] noise array, the position, and the
    190         * size.
    191         */
    192        private double[] initializeNoiseField(double[] par1ArrayOfDouble, int par2, int par3, int par4, int par5, int par6, int par7)
    193        {
    194            if (par1ArrayOfDouble == null)
    195            {
    196                par1ArrayOfDouble = new double[par5 * par6 * par7];
    197            }
    198
    199            double var8 = 684.412D;
    200            double var10 = 684.412D;
    201            this.noiseData4 = this.noiseGen4.generateNoiseOctaves(this.noiseData4, par2, par4, par5, par7, 1.121D, 1.121D, 0.5D);
    202            this.noiseData5 = this.noiseGen5.generateNoiseOctaves(this.noiseData5, par2, par4, par5, par7, 200.0D, 200.0D, 0.5D);
    203            var8 *= 2.0D;
    204            this.noiseData1 = this.noiseGen3.generateNoiseOctaves(this.noiseData1, par2, par3, par4, par5, par6, par7, var8 / 80.0D, var10 / 160.0D, var8 / 80.0D);
    205            this.noiseData2 = this.noiseGen1.generateNoiseOctaves(this.noiseData2, par2, par3, par4, par5, par6, par7, var8, var10, var8);
    206            this.noiseData3 = this.noiseGen2.generateNoiseOctaves(this.noiseData3, par2, par3, par4, par5, par6, par7, var8, var10, var8);
    207            int var12 = 0;
    208            int var13 = 0;
    209
    210            for (int var14 = 0; var14 < par5; ++var14)
    211            {
    212                for (int var15 = 0; var15 < par7; ++var15)
    213                {
    214                    double var16 = (this.noiseData4[var13] + 256.0D) / 512.0D;
    215
    216                    if (var16 > 1.0D)
    217                    {
    218                        var16 = 1.0D;
    219                    }
    220
    221                    double var18 = this.noiseData5[var13] / 8000.0D;
    222
    223                    if (var18 < 0.0D)
    224                    {
    225                        var18 = -var18 * 0.3D;
    226                    }
    227
    228                    var18 = var18 * 3.0D - 2.0D;
    229                    float var20 = (float)(var14 + par2 - 0) / 1.0F;
    230                    float var21 = (float)(var15 + par4 - 0) / 1.0F;
    231                    float var22 = 100.0F - MathHelper.sqrt_float(var20 * var20 + var21 * var21) * 8.0F;
    232
    233                    if (var22 > 80.0F)
    234                    {
    235                        var22 = 80.0F;
    236                    }
    237
    238                    if (var22 < -100.0F)
    239                    {
    240                        var22 = -100.0F;
    241                    }
    242
    243                    if (var18 > 1.0D)
    244                    {
    245                        var18 = 1.0D;
    246                    }
    247
    248                    var18 /= 8.0D;
    249                    var18 = 0.0D;
    250
    251                    if (var16 < 0.0D)
    252                    {
    253                        var16 = 0.0D;
    254                    }
    255
    256                    var16 += 0.5D;
    257                    var18 = var18 * (double)par6 / 16.0D;
    258                    ++var13;
    259                    double var23 = (double)par6 / 2.0D;
    260
    261                    for (int var25 = 0; var25 < par6; ++var25)
    262                    {
    263                        double var26 = 0.0D;
    264                        double var28 = ((double)var25 - var23) * 8.0D / var16;
    265
    266                        if (var28 < 0.0D)
    267                        {
    268                            var28 *= -1.0D;
    269                        }
    270
    271                        double var30 = this.noiseData2[var12] / 512.0D;
    272                        double var32 = this.noiseData3[var12] / 512.0D;
    273                        double var34 = (this.noiseData1[var12] / 10.0D + 1.0D) / 2.0D;
    274
    275                        if (var34 < 0.0D)
    276                        {
    277                            var26 = var30;
    278                        }
    279                        else if (var34 > 1.0D)
    280                        {
    281                            var26 = var32;
    282                        }
    283                        else
    284                        {
    285                            var26 = var30 + (var32 - var30) * var34;
    286                        }
    287
    288                        var26 -= 8.0D;
    289                        var26 += (double)var22;
    290                        byte var36 = 2;
    291                        double var37;
    292
    293                        if (var25 > par6 / 2 - var36)
    294                        {
    295                            var37 = (double)((float)(var25 - (par6 / 2 - var36)) / 64.0F);
    296
    297                            if (var37 < 0.0D)
    298                            {
    299                                var37 = 0.0D;
    300                            }
    301
    302                            if (var37 > 1.0D)
    303                            {
    304                                var37 = 1.0D;
    305                            }
    306
    307                            var26 = var26 * (1.0D - var37) + -3000.0D * var37;
    308                        }
    309
    310                        var36 = 8;
    311
    312                        if (var25 < var36)
    313                        {
    314                            var37 = (double)((float)(var36 - var25) / ((float)var36 - 1.0F));
    315                            var26 = var26 * (1.0D - var37) + -30.0D * var37;
    316                        }
    317
    318                        par1ArrayOfDouble[var12] = var26;
    319                        ++var12;
    320                    }
    321                }
    322            }
    323
    324            return par1ArrayOfDouble;
    325        }
    326
    327        /**
    328         * Checks to see if a chunk exists at x, y
    329         */
    330        public boolean chunkExists(int par1, int par2)
    331        {
    332            return true;
    333        }
    334
    335        /**
    336         * Populates chunk with ores etc etc
    337         */
    338        public void populate(IChunkProvider par1IChunkProvider, int par2, int par3)
    339        {
    340            BlockSand.fallInstantly = true;
    341            int var4 = par2 * 16;
    342            int var5 = par3 * 16;
    343            BiomeGenBase var6 = this.endWorld.getBiomeGenForCoords(var4 + 16, var5 + 16);
    344            var6.decorate(this.endWorld, this.endWorld.rand, var4, var5);
    345            BlockSand.fallInstantly = false;
    346        }
    347
    348        /**
    349         * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
    350         * Return true if all chunks have been saved.
    351         */
    352        public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate)
    353        {
    354            return true;
    355        }
    356
    357        /**
    358         * Unloads the 100 oldest chunks from memory, due to a bug with chunkSet.add() never being called it thinks the list
    359         * is always empty and will not remove any chunks.
    360         */
    361        public boolean unload100OldestChunks()
    362        {
    363            return false;
    364        }
    365
    366        /**
    367         * Returns if the IChunkProvider supports saving.
    368         */
    369        public boolean canSave()
    370        {
    371            return true;
    372        }
    373
    374        /**
    375         * Converts the instance data to a readable string.
    376         */
    377        public String makeString()
    378        {
    379            return "RandomLevelSource";
    380        }
    381
    382        /**
    383         * Returns a list of creatures of the specified type that can spawn at the given location.
    384         */
    385        public List getPossibleCreatures(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
    386        {
    387            BiomeGenBase var5 = this.endWorld.getBiomeGenForCoords(par2, par4);
    388            return var5 == null ? null : var5.getSpawnableList(par1EnumCreatureType);
    389        }
    390
    391        /**
    392         * Returns the location of the closest structure of the specified type. If not found returns null.
    393         */
    394        public ChunkPosition findClosestStructure(World par1World, String par2Str, int par3, int par4, int par5)
    395        {
    396            return null;
    397        }
    398
    399        public int getLoadedChunkCount()
    400        {
    401            return 0;
    402        }
    403
    404        public void func_82695_e(int par1, int par2) {}
    405    }