public CompoundTag save(CompoundTag tag) {
        ListTag list = new ListTag();
        for (int i = 0; i < getContainerSize(); i++) {
            ItemStack stack = getItem(i);
            if (!stack.isEmpty()) {
                CompoundTag itemTag = new CompoundTag();
                itemTag.putInt(TAG_SLOT, i);
                stack.save(itemTag);
                list.add(itemTag);
            }
        }
        tag.put(TAG_ITEMS, list);
        tag.putInt(TAG_ITEM_COUNT, list.size());

        return tag;
    }
Simple extension of default vanilla Inventory class that allows for proper saving and loading
to a CompoundNBT. Default implementation does not load items back into their original slots.
<p>
Use {@link BaseContainer#save} and {@link BaseContainer#load} instead of Inventory#createTag and Inventory#fromTag
core/src/main/java/mrtjp/projectred/core/inventory/BaseContainer.java