Exemplo n.º 1
0
        public void HandleChunkData(MinecraftClient client, IPacket packet) {
            var ChunkData = (CBChunkData)packet;

            byte[] trim = new byte[ChunkData.Compressedsize - 2];
            byte[] decompressedData;

            if (ChunkData.Primarybitmap == 0) {
                // -- Unload chunk.
                int cIndex = -1;

                if (client.MinecraftWorld != null)
                    cIndex = client.MinecraftWorld.GetChunk(ChunkData.ChunkX, ChunkData.ChunkZ);

                if (cIndex != -1)
                    client.MinecraftWorld.worldChunks.RemoveAt(cIndex);

                client.RaiseChunkUnload(ChunkData.ChunkX, ChunkData.ChunkZ);
                return;
            }

            // -- Remove GZip Header
            Buffer.BlockCopy(ChunkData.Compresseddata, 2, trim, 0, trim.Length);

            // -- Decompress the data
            decompressedData = Decompressor.Decompress(trim);

            // -- Create new chunk
            Chunk newChunk = new Chunk(ChunkData.ChunkX, ChunkData.ChunkZ, (short)ChunkData.Primarybitmap, (short)ChunkData.Addbitmap, true, ChunkData.GroundUpcontinuous); // -- Skylight assumed true
            newChunk.GetData(decompressedData);

            if (client.MinecraftWorld == null)
                client.MinecraftWorld = new WorldClass();

            // -- Add the chunk to the world
            client.MinecraftWorld.worldChunks.Add(newChunk);

            client.RaiseChunkLoad(ChunkData.ChunkX, ChunkData.ChunkZ);
        }