Beispiel #1
0
        public void LoadChunk(Chunk chunk, int x, int z)
        {
            string filePath = GetChunkFilePath(x, z);

            if (File.Exists(filePath))
            {
                ReadChunkFromFile(chunk, filePath);
            }
            else
            {
                chunk.Init(x, z, Seed, m_WorldType);
            }
        }
Beispiel #2
0
        private void ReadChunkFromFile(Chunk chunk, string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                int x_b0 = fs.ReadByte();
                int x_b1 = fs.ReadByte();
                int x_b2 = fs.ReadByte();
                int x_b3 = fs.ReadByte();

                int posX = x_b0 | (x_b1 << 8) | (x_b2 << 16) | (x_b3 << 24);

                int z_b0 = fs.ReadByte();
                int z_b1 = fs.ReadByte();
                int z_b2 = fs.ReadByte();
                int z_b3 = fs.ReadByte();

                int posZ = z_b0 | (z_b1 << 8) | (z_b2 << 16) | (z_b3 << 24);

                chunk.GetRawData(out byte[] blocks, out byte[] states);

                int count = 0;

                do
                {
                    count += fs.Read(blocks, count, BlockCountInChunk);
                } while (count < BlockCountInChunk);

                count = 0;

                do
                {
                    count += fs.Read(states, count, BlockCountInChunk);
                } while (count < BlockCountInChunk);

                chunk.Init(posX, posZ);
            }
        }