Пример #1
0
 public override void MessageRecieved(RemoteClient client, byte[] data)
 {
     if (ServerPingReceived != null)
     {
         var stream    = new MinecraftStream(new MemoryStream(data));
         var eventArgs = new ServerPingEventArgs(
             stream.ReadInt32(),
             stream.ReadString(),
             stream.ReadInt32());
         ServerPingReceived(this, eventArgs);
     }
 }
Пример #2
0
 public static void MapChunkBulk(MinecraftClient client, IPacket _packet)
 {
     var packet = (MapChunkBulkPacket)_packet;
     var metadataStrem = new MemoryStream(packet.ChunkMetadata);
     var minecraftStream = new MinecraftStream(metadataStrem);
     var data = ZlibStream.UncompressBuffer(packet.ChunkData);
     int chunkLength = BlockDataLength + (NibbleDataLength * 2) + (Chunk.Width * Chunk.Depth);
     if (packet.LightIncluded)
         chunkLength += NibbleDataLength;
     for (int i = 0; i < packet.ChunkCount; i++)
     {
         int x = minecraftStream.ReadInt32();
         int z = minecraftStream.ReadInt32();
         ushort primaryBitMap = minecraftStream.ReadUInt16();
         ushort addBitMap = minecraftStream.ReadUInt16(); // TODO
         int offset = i * chunkLength;
         // Read chunk data
         var chunk = new Chunk(World.GetRelativeChunkPosition(new Vector3(x, 0, z)));
         var sectionCount = 0;
         // Get the total sections included in the packet
         for (int y = 0; y < 16; y++)
         {
             if ((primaryBitMap & (1 << y)) > 0)
                 sectionCount++;
         }
         // Run through the sections
         // TODO: Support block IDs >255
         for (int y = 0; y < 16; y++)
         {
             if ((primaryBitMap & (1 << y)) > 0)
             {
                 // Add this section
                 Array.Copy(data, offset + (y * BlockDataLength), chunk.Sections[y].Blocks, 0, BlockDataLength);
                 Array.Copy(data, offset + (y * BlockDataLength + (BlockDataLength * sectionCount)),
                     chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
                 Array.Copy(data, offset + (y * BlockDataLength + (BlockDataLength * sectionCount + NibbleDataLength)),
                     chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
                 if (packet.LightIncluded)
                 {
                     Array.Copy(data, offset + (y * BlockDataLength + (BlockDataLength * sectionCount + (NibbleDataLength * 2))),
                         chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
                 }
             }
         }
         Array.Copy(data, offset + chunkLength - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
         client.World.SetChunk(new Vector3(x, 0, z), chunk);
         client.OnChunkRecieved(new ChunkRecievedEventArgs(new Vector3(x, 0, z), new ReadOnlyChunk(chunk)));
     }
 }
Пример #3
0
 public override void FromStream(MinecraftStream stream)
 {
     Value = stream.ReadInt32();
 }
Пример #4
0
 public override void FromStream(MinecraftStream stream)
 {
     Value = stream.ReadInt32();
 }