NBTTagList itemList = new NBTTagList();
// Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) {
NBTTagCompound outputObject = new NBTTagCompound();
CraftItemStack craft = getCraftVersion(inventory.getItem(i));
// Convert the item stack to a NBT compound
if (craft != null)
CraftItemStack.asNMSCopy(craft).save(outputObject);
itemList.add(outputObject);