Advertisement
Guest User

Untitled

a guest
Mar 4th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.80 KB | None | 0 0
  1.         public static void LoadColumnOnClient(RemoteClient Client, Vector3 ChunkLocation, MultiplayerServer Server)
  2.         {
  3.             Client.PacketQueue.Enqueue(new PreChunkPacket(ChunkLocation.X, ChunkLocation.Z));
  4.  
  5.             MapChunkPacket mcp = new MapChunkPacket();
  6.             mcp.GroundUpContinuous = true;
  7.             mcp.BiomeData = new byte[256];
  8.             mcp.Location = ChunkLocation;
  9.  
  10.             byte[] blockData = new byte[0];
  11.             byte[] metadata = new byte[0];
  12.             byte[] blockLight = new byte[0];
  13.             byte[] skyLight = new byte[0];
  14.  
  15.             Vector3 location = ChunkLocation.Clone();
  16.             location.Y = 240;
  17.  
  18.             ushort mask = 1;
  19.             bool nonAir = true;
  20.             for (int i = 15; i >= 0; i--)
  21.             {
  22.                 Chunk c = Server.GetWorld(Client).GetChunk(location - new Vector3(0, i * 16, 0));
  23.  
  24.                 if (c.IsAir)
  25.                     nonAir = false;
  26.                 if (nonAir)
  27.                 {
  28.                     blockData = blockData.Concat(c.Blocks).ToArray();
  29.                     metadata = metadata.Concat(c.GetMetadata()).ToArray();
  30.                     blockLight = blockLight.Concat(c.GetBlockLight()).ToArray();
  31.                     skyLight = skyLight.Concat(c.GetSkyLight()).ToArray();
  32.  
  33.                     mcp.PrimaryBitMap |= mask;
  34.                 }
  35.  
  36.                 mask <<= 1;
  37.             }
  38.  
  39.             byte[] columnData = blockData.Concat(metadata).Concat(blockLight).Concat(skyLight).ToArray();
  40.  
  41.             zLibDeflater.SetInput(columnData);
  42.             zLibDeflater.Finish();
  43.             byte[] compressed = new byte[columnData.Length];
  44.             int l = zLibDeflater.Deflate(compressed);
  45.             zLibDeflater.Reset();
  46.  
  47.             mcp.Data = new byte[l];
  48.             Array.Copy(compressed, mcp.Data, l);
  49.  
  50.             Client.PacketQueue.Enqueue(mcp);
  51.             Client.PlayerEntity.LoadedChunks.Add(ChunkLocation);
  52.  
  53.             for (int i = 15; i >= 0; i--)
  54.             {
  55.                 Chunk c = Server.GetWorld(Client).GetChunk(location - new Vector3(0, i * 16, 0));
  56.                 foreach (KeyValuePair<Vector3, byte[]> kvp in c.AdditionalData)
  57.                 {
  58.                     if (kvp.Value[0] == 63)
  59.                     {
  60.                         Block b = Server.GetWorld(Client).GetBlock(kvp.Key);
  61.                         if (b is WallSignBlock)
  62.                             Client.PacketQueue.Enqueue(new UpdateSignPacket(kvp.Key,
  63.                                 (b as WallSignBlock).Data.Text));
  64.                         if (b is SignPostBlock)
  65.                             Client.PacketQueue.Enqueue(new UpdateSignPacket(kvp.Key,
  66.                                 (b as SignPostBlock).Data.Text));
  67.                     }
  68.                 }
  69.             }
  70.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement