コード例 #1
0
ファイル: BulkChunks.cs プロジェクト: umby24/Minebot
        public BulkChunks(Wrapped.Wrapped socket, Form1 mainform)
        {
            short columncount = socket.readShort();
            int Datalength = socket.readInt();
            bool skylight = socket.readBool();

            byte[] packdata = socket.readByteArray(Datalength);
            byte[] decompressed;

            byte[] trim = new byte[Datalength - 2];
            Chunk[] chunks = new Chunk[columncount];

            // Shoutout to BjorN64 for the simplification of this.
            Array.Copy(packdata, 2, trim, 0, Datalength - 2);

            // Decompress the data

            Classes.Decompressor dc = new Classes.Decompressor(trim);
            decompressed = dc.decompress();

            for (int i = 0; columncount > i; i++) {
                // Need to store this data so it's not lost as well..
                int x = socket.readInt();
                int z = socket.readInt();
                short pbitmap = socket.readShort();
                short abitmap = socket.readShort();

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

                decompressed = chunks[i].getData(decompressed); // Calls the chunk class to take all of the bytes it needs, and return whats left.
                mainform.Chunks.Add(chunks[i]); // Add the chunk to the main form so we can use it later.
            }
        }
コード例 #2
0
        public BulkChunks(Wrapped.Wrapped socket, Form1 mainform)
        {
            short columncount = socket.readShort();
            int   Datalength  = socket.readInt();
            bool  skylight    = socket.readBool();

            byte[] packdata = socket.readByteArray(Datalength);
            byte[] decompressed;


            byte[]  trim   = new byte[Datalength - 2];
            Chunk[] chunks = new Chunk[columncount];

            // Shoutout to BjorN64 for the simplification of this.
            Array.Copy(packdata, 2, trim, 0, Datalength - 2);

            // Decompress the data

            Classes.Decompressor dc = new Classes.Decompressor(trim);
            decompressed = dc.decompress();

            for (int i = 0; columncount > i; i++)
            {
                // Need to store this data so it's not lost as well..
                int   x       = socket.readInt();
                int   z       = socket.readInt();
                short pbitmap = socket.readShort();
                short abitmap = socket.readShort();

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

                decompressed = chunks[i].getData(decompressed);                // Calls the chunk class to take all of the bytes it needs, and return whats left.
                mainform.Chunks.Add(chunks[i]);                                // Add the chunk to the main form so we can use it later.
            }
        }
コード例 #3
0
ファイル: BulkChunks - Copy.cs プロジェクト: umby24/Minebot
        public BulkChunks(Wrapped.Wrapped socket, Form1 mainform)
        {
            short columncount = socket.readShort();
            int Datalength = socket.readInt();
            bool skylight = socket.readBool();

            byte[] packdata = socket.readByteArray(Datalength);
            byte[] decompressed;

            byte[] trim = new byte[Datalength - 2];
            Chunk[] chunks = new Chunk[columncount];

            Array.Reverse(packdata);
            Array.Copy(packdata, trim, Datalength - 2);
            Array.Reverse(trim);

            // Decompress the data

            Classes.Decompressor dc = new Classes.Decompressor(trim);
            decompressed = dc.decompress();

            for (int i = 0; columncount > i; i++)
            {
                // Need to store this data so it's not lost as well..
               int x = socket.readInt();
               int z = socket.readInt();
               short pbitmap = socket.readShort();
               short abitmap = socket.readShort();

               Chunk mychunk = new Chunk(x, z, pbitmap, abitmap, skylight);

               chunks[i] = mychunk;

            }

            int offset = 0;

            foreach (Chunk b in chunks)
            {
                for (int i = 0; i < 16; i++)
                {
                    if (Convert.ToBoolean(b.pbitmap & (1 << i)))
                    {
                        byte[] newBlocks = new byte[4096];
                        byte[] temp = b.blocks;

                        Array.Copy(decompressed, offset, newBlocks, 0, 4096);

                        if (b.blocks == null)
                            b.blocks = newBlocks;
                        else
                        {
                            b.blocks = new byte[temp.Length + 4096];
                            temp.CopyTo(b.blocks, 0);
                            newBlocks.CopyTo(b.blocks, temp.Length);
                        }
                        b.numBlocks += 4096;
                        offset += 4096;
                    }
                }

                mainform.Chunks.Add(b);
                if (b.abitmap != 0)
                {
                    throw new Exception();
                }
                // we need to adjust the offset in compensation for additional metadata included with every chunk..
                int additional = 0;
                int Nibbleinfo = b.numBlocks / 2;
                int totalSections = b.numBlocks / 4096;

                if (skylight == true)
                    additional = (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo);
                else
                    additional = (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo);

                additional += 256;

                offset += additional;
                //Array.Copy(decompressed, b.blocks, b.blocks.Length);

                //temp = new byte[decompressed.Length - b.blocks.Length];

                //Array.Copy(decompressed, b.blocks.Length, temp, 0, decompressed.Length - b.blocks.Length);
                //decompressed = temp;
                //mainform.Chunks.Add(b);
                // parseChunk(b,mainform);
            }
        }
コード例 #4
0
        public BulkChunks(Wrapped.Wrapped socket, Form1 mainform)
        {
            short columncount = socket.readShort();
            int   Datalength  = socket.readInt();
            bool  skylight    = socket.readBool();

            byte[] packdata = socket.readByteArray(Datalength);
            byte[] decompressed;


            byte[]  trim   = new byte[Datalength - 2];
            Chunk[] chunks = new Chunk[columncount];

            Array.Reverse(packdata);
            Array.Copy(packdata, trim, Datalength - 2);
            Array.Reverse(trim);

            // Decompress the data

            Classes.Decompressor dc = new Classes.Decompressor(trim);
            decompressed = dc.decompress();

            for (int i = 0; columncount > i; i++)
            {
                // Need to store this data so it's not lost as well..
                int   x       = socket.readInt();
                int   z       = socket.readInt();
                short pbitmap = socket.readShort();
                short abitmap = socket.readShort();

                Chunk mychunk = new Chunk(x, z, pbitmap, abitmap, skylight);

                chunks[i] = mychunk;
            }

            int offset = 0;

            foreach (Chunk b in chunks)
            {
                for (int i = 0; i < 16; i++)
                {
                    if (Convert.ToBoolean(b.pbitmap & (1 << i)))
                    {
                        byte[] newBlocks = new byte[4096];
                        byte[] temp      = b.blocks;

                        Array.Copy(decompressed, offset, newBlocks, 0, 4096);

                        if (b.blocks == null)
                        {
                            b.blocks = newBlocks;
                        }
                        else
                        {
                            b.blocks = new byte[temp.Length + 4096];
                            temp.CopyTo(b.blocks, 0);
                            newBlocks.CopyTo(b.blocks, temp.Length);
                        }
                        b.numBlocks += 4096;
                        offset      += 4096;
                    }
                }

                mainform.Chunks.Add(b);
                if (b.abitmap != 0)
                {
                    throw new Exception();
                }
                // we need to adjust the offset in compensation for additional metadata included with every chunk..
                int additional    = 0;
                int Nibbleinfo    = b.numBlocks / 2;
                int totalSections = b.numBlocks / 4096;


                if (skylight == true)
                {
                    additional = (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo);
                }
                else
                {
                    additional = (totalSections * Nibbleinfo) + (totalSections * Nibbleinfo);
                }

                additional += 256;

                offset += additional;
                //Array.Copy(decompressed, b.blocks, b.blocks.Length);

                //temp = new byte[decompressed.Length - b.blocks.Length];

                //Array.Copy(decompressed, b.blocks.Length, temp, 0, decompressed.Length - b.blocks.Length);
                //decompressed = temp;
                //mainform.Chunks.Add(b);
                // parseChunk(b,mainform);
            }
        }