コード例 #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
ファイル: commandHandler.cs プロジェクト: roger2000hk/Minebot
        void findBlock(string[] args)
        {
            // Attempt on an alternitive block lookup method, for speed's sake..
            functions lookup = new functions();

            if (!lookup.isNumeric(args[2]))
            {
                return;
            }
            if (!lookup.isNumeric(args[3]))
            {
                return;
            }
            if (!lookup.isNumeric(args[4]))
            {
                return;
            }

            int blockX = int.Parse(args[2]);
            int blockY = int.Parse(args[3]);
            int blockZ = int.Parse(args[4]);

            decimal ChunkX = decimal.Divide(blockX, 16);
            decimal ChunkZ = decimal.Divide(blockZ, 16);

            ChunkX = Math.Floor(ChunkX);
            ChunkZ = Math.Floor(ChunkZ);

            Classes.Chunk    thisChunk = null;
            Classes.MapBlock thisblock = null;

            foreach (Classes.Chunk b in Mainform.Chunks)
            {
                if (b.x == ChunkX & b.z == ChunkZ)
                {
                    thisChunk = b;
                    break;
                }
            }

            thisblock = thisChunk.getBlock(blockX, blockY, blockZ);

            if (thisblock != null)
            {
                Packets.chatMessage cm = new Packets.chatMessage(Socket, Mainform, "FOUND IT. " + thisblock.Name, true);
            }
            else
            {
                Packets.chatMessage cm = new Packets.chatMessage(Socket, Mainform, "Fail :(", true);
            }
        }
コード例 #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
ファイル: BulkChunks - Copy.cs プロジェクト: umby24/Minebot
        void parseChunk(Chunk toparse, Form1 thisform)
        {
            // Get all of the blocks, and load them into memory.
            for (byte i = 0; i < 16; i++)
            {
                if (Convert.ToBoolean(toparse.pbitmap & (1 << i)))
                {
                    for (int f= 0; f < 4096; f++)
                    {
                        int blockX = (toparse.x * 16) + (f & 0x0F); // f & 0x0f
                        int blockY = (i * 16) + (blockX >> 8); // i*16 + (f >> 8)
                        int blockZ = (toparse.z * 16) + (f & 0xF0) >> 4; // (f & F0) >> 4
                        int blockID = toparse.blocks[f];

                        MapBlock myBlock = new MapBlock(blockID, blockX, blockY, blockZ);

                        if (thisform.blocks == null)
                            thisform.blocks = new MapBlock[] { myBlock };
                        else
                        {
                            MapBlock[] temp = thisform.blocks;
                            thisform.blocks = new MapBlock[temp.Length + 1];
                            Array.Copy(temp, thisform.blocks, temp.Length);
                            thisform.blocks[temp.Length] = myBlock;
                        }
                    }
                }
            }
        }