Beispiel #1
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)));
     }
 }
Beispiel #2
0
        private static void AddChunk(MinecraftClient client, int x, int z, ushort primaryBitMap, ushort addBitMap, bool lightIncluded, bool groundUp, byte[] data)
        {
            var position         = new Vector3(x, 0, z);
            var relativePosition = World.GetRelativeChunkPosition(position);
            var chunk            = new Chunk(relativePosition);
            var sectionCount     = GetSectionCount(primaryBitMap);

            // Run through the sections
            // TODO: Support block IDs >255
            for (int y = 0; y < 16; y++)
            {
                if ((primaryBitMap & (1 << y)) > 0)
                {
                    // Add this section

                    // Blocks
                    Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);

                    // Metadata
                    Array.Copy(data, (BlockDataLength * sectionCount) + (y * NibbleDataLength),
                               chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);

                    // Light
                    Array.Copy(data, ((BlockDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                               chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);

                    // Sky light
                    if (lightIncluded)
                    {
                        Array.Copy(data, ((BlockDataLength + NibbleDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                                   chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
                    }
                }
            }

            // biomes
            if (groundUp)
            {
                Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
            }

            client.World.SetChunk(position, chunk);
            client.OnChunkRecieved(new ChunkRecievedEventArgs(position, new ReadOnlyChunk(chunk)));
        }
Beispiel #3
0
        private static void AddChunk(MinecraftClient client, int x, int z, ushort primaryBitMap, ushort addBitMap, bool lightIncluded, bool groundUp, byte[] data)
        {
            var position = new Vector3(x, 0, z);
            var relativePosition = World.GetRelativeChunkPosition(position);
            var chunk = new Chunk(relativePosition);
            var sectionCount = GetSectionCount(primaryBitMap);

            // Run through the sections
            // TODO: Support block IDs >255
            for (int y = 0; y < 16; y++)
            {
                if ((primaryBitMap & (1 << y)) > 0)
                {
                    // Add this section

                    // Blocks
                    Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);

                    // Metadata
                    Array.Copy(data, (BlockDataLength * sectionCount) + (y * NibbleDataLength),
                        chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);

                    // Light
                    Array.Copy(data, ((BlockDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                        chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);

                    // Sky light
                    if (lightIncluded)
                        Array.Copy(data, ((BlockDataLength + NibbleDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                            chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
                }
            }

            // biomes
            if (groundUp)
                Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);

            client.World.SetChunk(position, chunk);
            client.OnChunkRecieved(new ChunkRecievedEventArgs(position, new ReadOnlyChunk(chunk)));
        }
Beispiel #4
0
 public static void ChunkData(MinecraftClient client, IPacket _packet)
 {
     var packet = (ChunkDataPacket)_packet;
     if (packet.Data == ChunkRemovalSequence)
     {
         client.World.RemoveChunk(packet.X, packet.Z);
         return;
     }
     var chunk = new Chunk(World.GetRelativeChunkPosition(new Vector3(packet.X, 0, packet.Z)));
     var data = ZlibStream.UncompressBuffer(packet.Data);
     var sectionCount = 0;
     // Get the total sections included in the packet
     for (int y = 0; y < 16; y++)
     {
         if ((packet.PrimaryBitMap & (1 << y)) > 0)
             sectionCount++;
     }
     // Run through the sections
     // TODO: Support block IDs >255
     for (int y = 0; y < 16; y++)
     {
         if ((packet.PrimaryBitMap & (1 << y)) > 0)
         {
             // Add this section
             Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);
             Array.Copy(data, y * BlockDataLength + (BlockDataLength * sectionCount),
                 chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
             Array.Copy(data, y * BlockDataLength + (BlockDataLength * sectionCount + NibbleDataLength),
                 chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
             Array.Copy(data, y * BlockDataLength + (BlockDataLength * sectionCount + (NibbleDataLength * 2)),
                 chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
         }
     }
     if (packet.GroundUpContinuous)
         Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
     client.World.SetChunk(new Vector3(packet.X, 0, packet.Z), chunk);
     client.OnChunkRecieved(new ChunkRecievedEventArgs(new Vector3(packet.X, 0, packet.Z), new ReadOnlyChunk(chunk)));
 }