Just a quick question about the inventory API. I would like to save the whole inventory (armor, hotbar, etc.) of a player and give him back later. But how can I keep the exact same inventory: each item should be placed back in the same slot ?
For now, I manage to give back the inventory without keeping the item position. This is how I do that:
What do you mean? If you mean that only part of the player’s inventory gets filled, that’s because the full inventory isn’t just a grid. The hotbar is seperate and not a grid, as is the armour and crafting.
I think best way to do what you want is to use Inventory#iterator(). This will allow you to get all items in the hotbar, inventory and armor slots. I’m not certain how you’d restore this, however.