def pack(data_type, data):
    if data_type in data_types:
        format = data_types[data_type]
        return pack_real(format[0], data)
    
    if data_type == "string8": return pack("short", len(data)) + data
    if data_type == "string16": return pack("short", len(data)) + data.encode('utf-16be')
    if data_type == "slot":
        o = pack('short', data['id'])
        if data['id'] > 0:
            o += pack('byte',  data['amount'])
            o += pack('short', data['damage'])
            if enchantable in data['id']:
                if 'enchantment_data' in data:

                    o += pack('short', len(data['enchantment_data']))
                    o += data['enchantment_data']

                elif 'enchantments' in data:
                    ench = nbt.encode(data['enchantments'])
                    ench = nbt.compress(ench)
                    o += pack('short', len(ench))
                    o += ench
                else:
                    o += pack('short', -1)
                
        return o
    if data_type == "metadata":
        o = ''
        for key, tmp in data:
            ty, val = tmp
            x = key | (ty << 5)
            o += pack('ubyte', x)

            if ty == 0: o += pack('byte', val) 
            if ty == 1: o += pack('short', val) 
            if ty == 2: o += pack('int', val) 
            if ty == 3: o += pack('float', val) 
            if ty == 4: o += pack('string16', val)
            if ty == 5:
                o += pack('short', val['id'])
                o += pack('byte',  val['count'])
                o += pack('short', val['damage'])
            if ty == 6:
                for i in range(3):
                    o += pack('int', val[i])
        o += pack('byte', 127)
        return o
dataset/ETHPy150Open barneygale/barneymc/barneymc/protocol/data_types.py/pack/swapped operands of `in`