Craft.Net.Server.Slot.ReadSlot C# (CSharp) Method

ReadSlot() public static method

Reads a slot from the given stream.
public static ReadSlot ( Stream stream ) : Slot
stream Stream The stream to read from.
return Slot
        public static Slot ReadSlot(Stream stream)
        {
            Slot s = new Slot();
            s.Id = ReadShort(stream);
            if (s.Id == -1)
                return s;
            s.Count = (byte)stream.ReadByte();
            s.Metadata = ReadShort(stream);

            short length = ReadShort(stream);
            if (length != -1)
            {
                byte[] compressed = new byte[length];
                stream.Read(compressed, 0, length);
                MemoryStream output = new MemoryStream();
                GZipStream gzs = new GZipStream(new MemoryStream(compressed), CompressionMode.Decompress, false);
                gzs.CopyTo(output);
                gzs.Close();
                s.Nbt = new NbtFile();
                s.Nbt.LoadFile(output, false);
            }

            return s;
        }