Coinage

Parse World Data

Oct 7th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. public void Parse(PlayerIOClient.Message m)
  2.         {
  3.             uint currentIndex = 0;
  4.             switch (m.Type)
  5.             {
  6.                 case "init":
  7.                     currentIndex = 43;
  8.                     break;
  9.                 case "reset":
  10.                     currentIndex = 1;
  11.                     break;
  12.             }
  13.             while (currentIndex < m.Count)
  14.             {
  15.                 if (m[currentIndex].ToString() == "we")  // it will stop map data if the end of world data is reached.
  16.                 {
  17.                     Console.WriteLine("Map data read!");
  18.                 }
  19.                 else
  20.                 {
  21.                     int blockid = m.GetInt(currentIndex);
  22.                     int layer = m.GetInt(currentIndex + 1);
  23.                     int amount = m.GetByteArray(currentIndex + 2).Length;
  24.                     byte[] bytearray1 = m.GetByteArray(currentIndex + 2);
  25.                     byte[] bytearray2 = m.GetByteArray(currentIndex + 3);
  26.                     if (Data.AllBlocks[blockid] != null) // you need a Block[] as a master list of all existing blocks for checking purposes
  27.                     {
  28.                         uint par = Data.AllBlocks[blockid].ParamCount;
  29.                         for (int n = 0; n < amount; n += 2) // checks every x,y for a certain blockid
  30.                         {
  31.                             int x = Convert.ToInt32(bytearray1[n] << 8 | bytearray1[n + 1]);
  32.                             int y = Convert.ToInt32(bytearray2[n] << 8 | bytearray2[n + 1]);
  33.                             Block newBlock = new Block { Layer = layer, X = x, Y = y, ID = blockid, ParamCount = par, Values = new object[par - 3] };
  34.                             for (uint i = 4; i < par + 1; i++)
  35.                             {
  36.                                 newBlock.Values[i - 4] = m[i];
  37.                             }
  38.                             WorldData[layer, x, y] = newBlock;
  39.                         }
  40.                         currentIndex += (uint)par + 1;
  41.                     }
  42.                     else
  43.                     {
  44.                         // blockid not in master list.
  45.                         // Console.WriteLine(blockid + " is missing in master list of blocks.");
  46.                         break;
  47.                     }
  48.                 }
  49.             }
Add Comment
Please, Sign In to add comment