I would like to test if the player has say, an empty bucket in their inventory, and replace it with a filled lava bucket. It only works if the stack size of the buckets is 1, and works in any inventory or hotbar slot.

I have a similar working command: /replaceitem entity @a slot.hotbar.8 minecraft:wool 1 11 {HideFlags:1,ench:[{id:71,lvl:1}]}

But this does 2 things wrong: first, it sets hotbar slot 8 to wool regardless of what is already in that slot, and it only sets slot 8 specifically.

Edit: I'm on 1.12


Solution 1:

You can't do that dynamically, you need one command per item. You basically need the commands from this answer.