示例#1
0
        public Chunk ProvideChunk(int x, int z, WorldManager world)
        {
            Chunk chunk = new Chunk(world, UniversalCoords.FromChunk(x, z));
            InitGen();

            byte[] data = new byte[32768];
            #if PROFILE
            Stopwatch watch = new Stopwatch();
            watch.Start();
            #endif
            GenerateTerrain(chunk, data, x, z);
            GenerateFlora(chunk, data, x, z);
            chunk.SetAllBlocks(data);

            chunk.RecalculateHeight();
            chunk.LightToRecalculate = true;
            #if PROFILE
            watch.Stop();

            _World.Logger.Log(Logger.LogLevel.Info, "Chunk {0} {1}, {2}", false, x, z, watch.ElapsedMilliseconds);
            #endif

            _World.AddChunk(chunk);
            chunk.MarkToSave();

            return chunk;
        }
示例#2
0
        public void ProvideChunk(int x, int z, Chunk chunk, bool recalculate)
        {
            InitGen();

            byte[] data = new byte[32768];
            Stopwatch watch = new Stopwatch();
            watch.Start();
            GenerateTerrain(chunk, data, x, z);
            GenerateFlora(chunk, data, x, z);
            chunk.SetAllBlocks(data);
            watch.Stop();
            if(recalculate)
                chunk.Recalculate();

            Console.WriteLine("Chunk {0} {1}, {2}", x, z, watch.ElapsedMilliseconds);

            //chunk.Save();
            _World.AddChunk(chunk);
            chunk.MarkToSave();
        }
示例#3
0
        public Chunk ProvideChunk(int x, int z, Chunk chunk, bool recalculate)
        {
            InitGen();

            byte[] data = new byte[32768];
            Stopwatch watch = new Stopwatch();
            watch.Start();
            GenerateTerrain(chunk, data, x, z);
            GenerateFlora(chunk, data, x, z);
            chunk.SetAllBlocks(data);
            if(recalculate)
                chunk.Recalculate();
            watch.Stop();

            Console.WriteLine("Chunk {0} {1}", x, z);

            //chunk.Save();
            _World.AddChunk(chunk);

            return chunk;
        }
示例#4
0
        public Chunk ProvideChunk(int x, int z, Chunk chunk, bool recalculate)
        {
            Rand.setSeed((long)x * 0x4f9939f508L + (long)z * 0x1ef1565bd5L);
            BiomesForGeneration = World.GetWorldChunkManager().GetBlockGeneratorData(BiomesForGeneration, x << 4, z << 4, 16, 16);
            double[] ad = World.GetWorldChunkManager().Temperatures;
            byte[] data = new byte[32768];
            GenerateTerrain(x, z, data, BiomesForGeneration, ad);
            ReplaceBlocksForBiome(x, z, data, BiomesForGeneration);
            CaveGen.GenerateA(this, World, x, z, data);

            for (int bx = 0; bx < 16; bx++)
            {
                for (int by = 0; by < 128; by++)
                {
                    for (int bz = 0; bz < 16; bz++)
                    {
                        if (data[bx << 11 | bz << 7 | by] == 1)
                        {
                            if (Rand.nextInt(100 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Diamond_Ore;
                            else if (Rand.nextInt(100 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Lapis_Lazuli_Ore;
                            else if (Rand.nextInt(40 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Gold_Ore;
                            else if (Rand.nextInt(10 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Redstone_Ore_Glowing;
                            else if (Rand.nextInt(4 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Iron_Ore;
                            else if (Rand.nextInt(2 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Coal_Ore;
                        }
                        chunk.SetAllBlocks(data);
                    }
                }
            }

            World.AddChunk(chunk);

            for (int bx = 0; bx < 16; bx++)
            {
                for (int by = 0; by < 128; by++)
                {
                    for (int bz = 0; bz < 16; bz++)
                    {
                        // TODO: Consider temperature/biome for trees & cacti.
                        UniversalCoords coords = UniversalCoords.FromBlock(x, z, bx, by, bz);
                        if (by > 0 && chunk.GetType(UniversalCoords.FromWorld(coords.WorldX, coords.WorldY - 1, coords.WorldZ)) == BlockData.Blocks.Grass && Rand.nextInt(140) == 0)
                        {
                            switch (Rand.nextInt(3))
                            {
                                case 0: chunk.GrowTree(coords); break;
                                case 1: chunk.GrowTree(coords, 2); break;
                                case 2: chunk.GrowTree(coords, 1); break;
                            }
                        }

                        //if (by > 63 && chunk.GetType(bx, by - 1, bz) == BlockData.Blocks.Sand && Rand.nextInt(80) == 0)
                        //chunk.PlaceCactus(bx, by, bz);
                    }
                }
            }
            if(recalculate)
            chunk.Recalculate();
            chunk.Save();
            return chunk;
        }