Пример #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);
        }
Пример #2
0
        public void HandleMapChunkBulk(MinecraftClient client, IPacket packet) {
            var ChunkPacket = (CBMapChunkBulk)packet;
            int Offset = 0;

            byte[] trim = new byte[ChunkPacket.Datalength - 2];
            byte[] DecompressedData;

            Chunk[] chunks = new Chunk[ChunkPacket.Chunkcolumncount];

            Buffer.BlockCopy(ChunkPacket.Data, 2, trim, 0, trim.Length);

            DecompressedData = Decompressor.Decompress(trim);

            for (int i = 0; ChunkPacket.Chunkcolumncount > i; i++) {
                int x = BitConverter.ToInt32(ChunkPacket.Metainformation, Offset);
                int z = BitConverter.ToInt32(ChunkPacket.Metainformation, Offset + 4);
                short pbitmap = ReverseBytes(BitConverter.ToInt16(ChunkPacket.Metainformation, Offset + 8));
                short abitmap = ReverseBytes(BitConverter.ToInt16(ChunkPacket.Metainformation, Offset + 10));
                Offset += 12;

                chunks[i] = new Chunk(x, z, pbitmap, abitmap, ChunkPacket.Skylightsent, true); // -- Assume true for Ground Up Continuous

                DecompressedData = chunks[i].GetData(DecompressedData); // -- Calls the chunk class to take all of the bytes it needs, and return whats left.

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

                client.MinecraftWorld.worldChunks.Add(chunks[i]);
            }
        }
Пример #3
0
        public void HandleMapChunkBulk(MinecraftClient client, IPacket packet) {
            var chunkPacket = (CbMapChunkBulk)packet;
            var offset = 0;

            var trim = new byte[chunkPacket.Datalength - 2];

            var chunks = new Chunk[chunkPacket.Chunkcolumncount];

            Buffer.BlockCopy(chunkPacket.Data, 2, trim, 0, trim.Length);

            byte[] decompressedData = Decompressor.Decompress(trim);

            for (var i = 0; chunkPacket.Chunkcolumncount > i; i++) {
                var x = BitConverter.ToInt32(chunkPacket.Metainformation, offset);
                var z = BitConverter.ToInt32(chunkPacket.Metainformation, offset + 4);
                var pbitmap = ReverseBytes(BitConverter.ToInt16(chunkPacket.Metainformation, offset + 8));
                var abitmap = ReverseBytes(BitConverter.ToInt16(chunkPacket.Metainformation, offset + 10));
                offset += 12;

                chunks[i] = new Chunk(x, z, pbitmap, abitmap, chunkPacket.Skylightsent, true); // -- Assume true for Ground Up Continuous

                decompressedData = chunks[i].GetData(decompressedData); // -- Calls the chunk class to take all of the bytes it needs, and return whats left.

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

                client.MinecraftWorld.WorldChunks.Add(chunks[i]);
            }
        }