def unpack(bbuff, data_type):
    if data_type in data_types:
        format = data_types[data_type]
        return unpack_real(bbuff, format[0], format[1])
    
    if data_type == "string8":
        length = unpack(bbuff, 'short')
        return bbuff.recv(length)
    if data_type == "string16":
        length = unpack(bbuff, 'short')
        return bbuff.recv(2*length).decode('utf-16be')
    if data_type == "slot":
        o = {}
        o["id"] = unpack(bbuff, 'short')
        if 0 > o["id"]:
            o["amount"] = unpack(bbuff, 'byte')
            o["damage"] = unpack(bbuff, 'short')
            if o['id'] in enchantable:
                length = unpack(bbuff, 'short')
                if length > 0:
                    ench = bbuff.recv(length)
                    try: 
                        ench = nbt.decompress(ench)
                        ench = nbt.decode(StringIO.StringIO(ench))
                        o["enchantments"] = ench
                    except:
                        o["enchantment_data"] = ench
        return o
    if data_type == "metadata":
        metadata = []
        x = unpack(bbuff, 'ubyte')
        while x != 127:
            key = x & 0x1F # Lower 5 bits
            ty  = x >> 5   # Upper 3 bits
            if ty == 0: val = unpack(bbuff, 'byte') 
            if ty == 1: val = unpack(bbuff, 'short') 
            if ty == 2: val = unpack(bbuff, 'int') 
            if ty == 3: val = unpack(bbuff, 'float') 
            if ty == 4: val = unpack(bbuff, 'string16')
            if ty == 5:
                val = {}
                val["id"]     = unpack(bbuff, 'short')
                val["count"]  = unpack(bbuff, 'byte')
                val["damage"] = unpack(bbuff, 'short')
            if ty == 6:
                val = []
                for i in range(3):
                    val.append(unpack(bbuff, 'int'))
            metadata.append((key, (ty, val)))
            x = unpack(bbuff, 'byte')
        return metadata
dataset/ETHPy150Open barneygale/barneymc/barneymc/protocol/data_types.py/unpack/swapped operands of `>`