public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            var ssLength = reader.ReadVarInt();
            SharedSecret = reader.ReadByteArray(ssLength);
            var vtLength = reader.ReadVarInt();
            VerificationToken = reader.ReadByteArray(vtLength);

            return this;
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            var ssLength = reader.ReadVarInt();

            SharedSecret = reader.ReadByteArray(ssLength);
            var vtLength = reader.ReadVarInt();

            VerificationToken = reader.ReadByteArray(vtLength);

            return(this);
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            ServerId = reader.ReadString();
            var pkLength = reader.ReadVarInt();
            PublicKey = reader.ReadByteArray(pkLength);
            var vtLength = reader.ReadVarInt();
            VerificationToken = reader.ReadByteArray(vtLength);

            SharedKey = new byte[16];

            var random = RandomNumberGenerator.Create();
            random.GetBytes(SharedKey);

            return this;
        }
        public static ItemStackList FromReader(IMinecraftDataReader reader)
        {
            var value = new ItemStackList();

            var count = reader.ReadShort();

            for (int i = 0; i < count; i++)
            {
                var slot = new ItemStack(reader.ReadShort()); // -- ID

                if (slot.ID == -1 || slot.Count == -1)
                {
                    value[i] = ItemStack.EmptyStack;
                    break;
                }

                slot.Count  = reader.ReadSByte();
                slot.Damage = reader.ReadShort();

                var length = reader.ReadVarInt();
                if (length == -1)
                {
                    value[i] = slot;
                    break;
                }

                slot.NBTData = reader.ReadByteArray(length);
            }

            return(value);
        }
        public static ItemStack FromReader(IMinecraftDataReader reader)
        {
            var itemStack = new ItemStack(reader.ReadShort()); // -- ID

            if (itemStack.ID == -1 || itemStack.Count == -1)
            {
                return(EmptyStack);
            }


            itemStack.Count  = reader.ReadSByte();
            itemStack.Damage = reader.ReadShort();

            var length = reader.ReadVarInt();

            if (length == -1 || length == 0)
            {
                return(itemStack);
            }

            itemStack.NBTData = reader.ReadByteArray(length);
            // TODO: NBTTag reading

            return(itemStack);
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            Channel = reader.ReadString();
            var length = reader.ReadVarInt();
            Data = reader.ReadByteArray(length);

            return this;
        }
        public IPacketWithSize ReadPacket(IMinecraftDataReader reader)
        {
            ChunkLength = reader.ReadShort();
            ChunkData = reader.ReadByteArray(1024);
            PercentComplete = reader.ReadByte();

            return this;
        }
Exemple #8
0
        public IPacketWithSize ReadPacket(IMinecraftDataReader reader)
        {
            ChunkLength     = reader.ReadShort();
            ChunkData       = reader.ReadByteArray(1024);
            PercentComplete = reader.ReadByte();

            return(this);
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            EntityID = reader.ReadVarInt();
            var length = reader.ReadVarInt(); // TODO: Check that
            NBTTag = reader.ReadByteArray(length);

            return this;
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            Channel = reader.ReadString();
            int length = reader.ReadShort();

            Data = reader.ReadByteArray(length);

            return(this);
        }
Exemple #11
0
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            EntityID = reader.ReadVarInt();
            var length = reader.ReadVarInt(); // TODO: Check that

            NBTTag = reader.ReadByteArray(length);

            return(this);
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            Location = Position.FromReaderLong(reader);
            Action = (UpdateBlockEntityAction) reader.ReadByte();
            int length = reader.ReadVarInt();
            NBTData = reader.ReadByteArray(length);

            return this;
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            ServerId = reader.ReadString();
            var pkLength = reader.ReadVarInt();

            PublicKey = reader.ReadByteArray(pkLength);
            var vtLength = reader.ReadVarInt();

            VerificationToken = reader.ReadByteArray(vtLength);

            SharedKey = new byte[16];

            var random = RandomNumberGenerator.Create();

            random.GetBytes(SharedKey);

            return(this);
        }
Exemple #14
0
        public static Chunk FromReader(IMinecraftDataReader reader)
        {
            var overWorld     = true;// TODO: From World class
            var coordinates   = new Coordinates2D(reader.ReadInt(), reader.ReadInt());
            var groundUp      = reader.ReadBoolean();
            var primaryBitMap = reader.ReadUShort();

            var value = new Chunk(coordinates);

            value.OverWorld     = overWorld;
            value.GroundUp      = groundUp;
            value.PrimaryBitMap = primaryBitMap;

            var size = reader.ReadVarInt();
            var data = reader.ReadByteArray(size);

            var sectionCount = GetSectionCount(value.PrimaryBitMap);

            var chunkRawBlocks      = new byte[sectionCount * TwoByteData];
            var chunkRawBlocksLight = new byte[sectionCount * HalfByteData];
            var chunkRawSkylight    = new byte[sectionCount * HalfByteData];

            Array.Copy(data, 0, chunkRawBlocks, 0, chunkRawBlocks.Length);
            Array.Copy(data, chunkRawBlocks.Length, chunkRawBlocksLight, 0, chunkRawBlocksLight.Length);
            Array.Copy(data, chunkRawBlocks.Length + chunkRawBlocksLight.Length, chunkRawSkylight, 0, chunkRawSkylight.Length);

            for (int y = 0, i = 0; y < 16; y++)
            {
                if ((value.PrimaryBitMap & (1 << y)) > 0)
                {
                    // Blocks & Metadata
                    var rawBlocks = new byte[TwoByteData];
                    Array.Copy(chunkRawBlocks, i * rawBlocks.Length, rawBlocks, 0, rawBlocks.Length);

                    // Light, convert to 1 byte per block
                    var rawBlockLight = new byte[HalfByteData];
                    Array.Copy(chunkRawSkylight, i * rawBlockLight.Length, rawBlockLight, 0, rawBlockLight.Length);

                    // Sky light, convert to 1 byte per block
                    var rawSkyLight = new byte[HalfByteData];
                    if (value.OverWorld)
                    {
                        Array.Copy(chunkRawSkylight, i * rawSkyLight.Length, rawSkyLight, 0, rawSkyLight.Length);
                    }

                    value.Sections[i].BuildFromRawData(rawBlocks, rawBlockLight, rawSkyLight);
                    i++;
                }
            }
            if (value.GroundUp)
            {
                Array.Copy(data, data.Length - value.Biomes.Length, value.Biomes, 0, value.Biomes.Length);
            }

            return(value);
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            Location = Position.FromReaderLong(reader);
            Action   = (UpdateBlockEntityAction)reader.ReadByte();
            int length = reader.ReadVarInt();

            NBTData = reader.ReadByteArray(length);

            return(this);
        }
Exemple #16
0
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            X             = reader.ReadFloat();
            Y             = reader.ReadFloat();
            Z             = reader.ReadFloat();
            Radius        = reader.ReadFloat();
            RecordCount   = reader.ReadInt();
            Records       = reader.ReadByteArray(3 * RecordCount);
            PlayerMotionX = reader.ReadFloat();
            PlayerMotionY = reader.ReadFloat();
            PlayerMotionZ = reader.ReadFloat();

            return(this);
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            X = reader.ReadFloat();
            Y = reader.ReadFloat();
            Z = reader.ReadFloat();
            Radius = reader.ReadFloat();
            RecordCount = reader.ReadInt();
            Records = reader.ReadByteArray(3 * RecordCount);
            PlayerMotionX = reader.ReadFloat();
            PlayerMotionY = reader.ReadFloat();
            PlayerMotionZ = reader.ReadFloat();

            return this;
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            ItemDamage = reader.ReadVarInt();
            Scale      = reader.ReadSByte();
            IconList   = IconList.FromReader(reader);
            Columns    = reader.ReadSByte();

            if (Columns > 0)
            {
                Rows = reader.ReadSByte();
                X    = reader.ReadSByte();
                Y    = reader.ReadSByte();
                var dataLength = reader.ReadShort();
                Data = reader.ReadByteArray(dataLength);
            }

            return(this);
        }
        public IPacket ReadPacket(IMinecraftDataReader reader)
        {
            ItemDamage = reader.ReadVarInt();
            Scale = reader.ReadSByte();
            IconList = IconList.FromReader(reader);
            Columns = reader.ReadSByte();

            if (Columns > 0)
            {
                Rows = reader.ReadSByte();
                X = reader.ReadSByte();
                Y = reader.ReadSByte();
                var dataLength = reader.ReadShort();
                Data = reader.ReadByteArray(dataLength);
            }

            return this;
        }
Exemple #20
0
        public static ChunkList FromReader(IMinecraftDataReader reader)
        {
            var value = new ChunkList();

            value.GroundUp = reader.ReadBoolean();
            value.Metadata = ChunkColumnMetadataList.FromReader(reader);

            int totalSections = 0;

            foreach (var metadata in value.Metadata.GetMetadata())
            {
                totalSections += Chunk.GetSectionCount(metadata.PrimaryBitMap);
            }


            var size = totalSections * (Chunk.TwoByteData + Chunk.HalfByteData + (value.GroundUp ? Chunk.HalfByteData : 0)) + value.Metadata.Count * Chunk.BiomesLength;
            var data = reader.ReadByteArray(size);

            int offset = 0;

            foreach (var metadata in value.Metadata.GetMetadata())
            {
                var chunk = new Chunk(metadata.Coordinates);
                chunk.PrimaryBitMap = metadata.PrimaryBitMap;
                chunk.OverWorld     = true;

                var sectionCount = Chunk.GetSectionCount(chunk.PrimaryBitMap);

                var chunkRawBlocks      = new byte[sectionCount * Chunk.TwoByteData];
                var chunkRawBlocksLight = new byte[sectionCount * Chunk.HalfByteData];
                var chunkRawSkylight    = new byte[sectionCount * Chunk.HalfByteData];

                var chunkLength = sectionCount * (Chunk.TwoByteData + Chunk.HalfByteData + (chunk.OverWorld ? Chunk.HalfByteData : 0)) + Chunk.BiomesLength;
                var chunkData   = new byte[chunkLength];
                Array.Copy(data, offset, chunkData, 0, chunkData.Length);

                Array.Copy(chunkData, 0, chunkRawBlocks, 0, chunkRawBlocks.Length);
                Array.Copy(chunkData, chunkRawBlocks.Length, chunkRawBlocksLight, 0, chunkRawBlocksLight.Length);
                Array.Copy(chunkData, chunkRawBlocks.Length + chunkRawBlocksLight.Length, chunkRawSkylight, 0, chunkRawSkylight.Length);
                if (value.GroundUp)
                {
                    Array.Copy(chunkData, chunkRawBlocks.Length + chunkRawBlocksLight.Length + chunkRawSkylight.Length, chunk.Biomes, 0, Chunk.BiomesLength);
                }

                for (int y = 0, i = 0; y < 16; y++)
                {
                    if ((chunk.PrimaryBitMap & (1 << y)) > 0)
                    {
                        // Blocks & Metadata
                        var rawBlocks = new byte[Chunk.TwoByteData];
                        Array.Copy(chunkRawBlocks, i * rawBlocks.Length, rawBlocks, 0, rawBlocks.Length);

                        // Light
                        var rawBlockLight = new byte[Chunk.HalfByteData];
                        Array.Copy(chunkRawSkylight, i * rawBlockLight.Length, rawBlockLight, 0, rawBlockLight.Length);

                        // Sky light
                        var rawSkyLight = new byte[Chunk.HalfByteData];
                        if (chunk.OverWorld)
                        {
                            Array.Copy(chunkRawSkylight, i * rawSkyLight.Length, rawSkyLight, 0, rawSkyLight.Length);
                        }

                        chunk.Sections[i].BuildFromRawData(rawBlocks, rawBlockLight, rawSkyLight);
                        i++;
                    }
                }
                value._entries.Add(chunk);

                offset += chunkLength;
            }

            return(value);
        }