public void packetHandler(object sender, Client.packetReceivedEventArgs e) { switch ((byte)e.Type) { case 0x0D: Packet_PlayerPosAndLook p = (Packet_PlayerPosAndLook)e.packet; moveCamera((float)p.X, (float)p.Y + 3f, (float)p.Z); break; case 8: Packet_UpdateHealth h = (Packet_UpdateHealth)e.packet; Console.WriteLine("Health Update: {0} {1}", h.Health, h.Food); if (h.Health <= 0) { Packet_Respawn r = new Packet_Respawn(); r.Dimension = 0; r.Difficulty = 1; r.Gamemode = 0; r.LevelType = "default"; r.WorldHeight = 256; mc.sendPacket(r); } break; /* case 0x32: * Packet_PreChunk c = (Packet_PreChunk)e.packet; * if (c.Mode) * { * if (!chunks.ContainsKey(c.X + "_" + c.Z)) * chunks.Add(c.X + "_" + c.Z, new Chunk()); * } * else * if (chunks.ContainsKey(c.X + "_" + c.Z)) * chunks.Remove(c.X + "_" + c.Z); * break; */ case 0x33: Packet_MapChunk mch = (Packet_MapChunk)e.packet; int cx, cz; cx = mch.X; cz = mch.Z; string key = cx + "_" + cz; //output("Chunk: " + key, true); if (!chunks.ContainsKey(key)) { chunks.Add(key, new Chunk()); //output("Chunk had to be added! " + key, true); } chunks[key].update(mch); QueueChunk(chunks[key]); break; case 0x34: Packet_MultiBlockChange mb = (Packet_MultiBlockChange)e.packet; chunks[mb.X + "_" + mb.Z].update(mb); QueueChunk(chunks[mb.X + "_" + mb.Z]); break; } }
public void update(Packet_MapChunk data) { x = data.X; z = data.Z; byte[] cubic_chunk_data = new byte[4096]; //Loop over 16x16x16 chunks in the 16x256x16 column int ii = -1; for (int i = 0; i < 16; i++) { //If the bitmask indicates this chunk has been sent... if ((data.PrimaryBM & (1 << i)) != 0) { ii = ii + 1; //Read data... Array.ConstrainedCopy(data.ChunkData, 4096 * ii, cubic_chunk_data, 0, 4096); for (int j = 0; j < cubic_chunk_data.Length; j++) { //Retrieve x,y,z and data from each element in cubic_chunk_array //Byte arrays //int bx = data.x * 16 + j & 0x0F; //int by = i * 16 + j >> 8; //int bz = data.z * 16 + (j & 0xF0) >> 4; int bx = j & 0x0F; int by = (i * 16) + (j >> 8); int bz = (j & 0xF0) >> 4; short bid = cubic_chunk_data[j]; //Nibble arrays int data1 = cubic_chunk_data[j] & 0x0F; int data2 = cubic_chunk_data[j] >> 4; int k = 2 * j; int bx1 = data.X * 16 + k & 0x0F; int by1 = i * 16 + k >> 8; int bz1 = data.Z * 16 + (k & 0xF0) >> 4; k++; int bx2 = data.X * 16 + k & 0x0F; int by2 = i * 16 + k >> 8; int bz2 = data.Z * 16 + (k & 0xF0) >> 4; blocks[bx, by, bz] = new Block(bx, by, bz, bid, 0); } } } }