HypixelDev / PublicAPI

Official Java implementation of the Hypixel Public API.
https://api.hypixel.net
MIT License
533 stars 151 forks source link

nbt in c# #426

Closed Vexea1 closed 3 years ago

Vexea1 commented 3 years ago

Hello,

I've got the bytes from the nbt data in the inv_armor property. But how do I convert this into a json object or array of bytes that represents a json format in c#. Please help!

        byte[] buffer = Convert.FromBase64String(value);
        byte[] decompressed;

        using (var inputStream = new MemoryStream(buffer))
        {
            using var outputStream = new MemoryStream();

            using (var gzip = new GZipStream(inputStream, CompressionMode.Decompress, leaveOpen: true))
            {
                gzip.CopyTo(outputStream);
            }

            decompressed = outputStream.ToArray();
            byte[] json = new byte[];//Convert from nbt bytes to json bytes...
            JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(json));
        }