public static byte[] serialize(Inventory items) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);

        NbtTagCompound nbtTagCompound = NbtFactory.toCompound(NbtFactory.createTag(NbtType.TAG_COMPOUND));
        NbtTagList nbtTagList = NbtFactory.toList(NbtFactory.createTag(NbtType.TAG_LIST));

        for (int i = 0; i < items.getSize(); i++) {
            NbtTagCompound compound = NbtFactory.toCompound(NbtFactory.createTag(NbtType.TAG_COMPOUND));
            ItemStack stack = items.getItem(i);

            if (stack != null)
                NbtFactory.saveItemStack(stack, compound);

            nbtTagList.add(compound);
        }

        nbtTagCompound.put(VERSION_KEY, NBT_VERSION);
        nbtTagCompound.put(ITEMS_KEY, nbtTagList);

        NbtFactory.fromNbtBase(nbtTagCompound).write(dataOutputStream);

        return byteArrayOutputStream.toByteArray();
    }