ignore this

done, please ignore this

Your problem is, that your sorted item list only references the items that are in the inventory. So when you call replaceItems and then trash the “old” ones, the item count gets set back to zero. But your sorted item list references exactly these values and you andup with zero amount for all items. I recommend to stop trashing all items and then to replace them with them self. Try just to swap the items in your inventory to the right position. So in sorting terms: Instead of sorting out-of-place, sort in-place. That would be memory friendlier too.