That’s how I make a player view an inventory. Maybe the CustomInventory was a bad example, but I want to set the player’s actual inventory to something else.
In short, I’m trying to make a snapshot of the player’s Inventory, so I can set it to the side and restore it later.
What you need is not directly available in the API, but I think it’s still possible.
You need to iterate over the inventory, it’s children and each itemstack. Store the data in some structure.
Then at a later date you rebuild the inventory from the structure.