Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Parse(PlayerIOClient.Message m)
- {
- uint currentIndex = 0;
- switch (m.Type)
- {
- case "init":
- currentIndex = 43;
- break;
- case "reset":
- currentIndex = 1;
- break;
- }
- while (currentIndex < m.Count)
- {
- if (m[currentIndex].ToString() == "we") // it will stop map data if the end of world data is reached.
- {
- Console.WriteLine("Map data read!");
- }
- else
- {
- int blockid = m.GetInt(currentIndex);
- int layer = m.GetInt(currentIndex + 1);
- int amount = m.GetByteArray(currentIndex + 2).Length;
- byte[] bytearray1 = m.GetByteArray(currentIndex + 2);
- byte[] bytearray2 = m.GetByteArray(currentIndex + 3);
- if (Data.AllBlocks[blockid] != null) // you need a Block[] as a master list of all existing blocks for checking purposes
- {
- uint par = Data.AllBlocks[blockid].ParamCount;
- for (int n = 0; n < amount; n += 2) // checks every x,y for a certain blockid
- {
- int x = Convert.ToInt32(bytearray1[n] << 8 | bytearray1[n + 1]);
- int y = Convert.ToInt32(bytearray2[n] << 8 | bytearray2[n + 1]);
- Block newBlock = new Block { Layer = layer, X = x, Y = y, ID = blockid, ParamCount = par, Values = new object[par - 3] };
- for (uint i = 4; i < par + 1; i++)
- {
- newBlock.Values[i - 4] = m[i];
- }
- WorldData[layer, x, y] = newBlock;
- }
- currentIndex += (uint)par + 1;
- }
- else
- {
- // blockid not in master list.
- // Console.WriteLine(blockid + " is missing in master list of blocks.");
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment