I wanted to use the /item command to switch the item in the offhand to the players mainhand. I wanted to use an advancement reward with an inventory_changed trigger and thought at first that the /item command itself doesn't work. As it turns out, the commands will work (if there are no syntax errors, heh), it's just that the item it's supposed to switch is still deleted.
- To reproduce the Isse, I have an advancement called "offhand" which will trigger when there is either a carrot, a stick, a stone or a carrot on a stick in the players offhand and no item in the mainhand. So essentially, get an item in the mainhand and press the button to switch it to your offhand. The function is called: "switch_items". I attached a data pack with the function and the advancement file.
As soon as any of those 4 items are in the offhand they disappear when you're in creative. When you're in survival, the item becomes a ghost item. you can recover it by clicking on free slots in your inventory.