I was doing some fun things with command blocks, to ensure an item spawned if it doesn't exist in someone's inventory, or already on the pedestal.
(command block 1 repeating, unconditional, always active) --- is it not on the pedestal or in the room (defined by coordinates)?
execute unless entity @e[x=234,y=71,z=-190,dx=9,dy=1,dz=9,tag=Thingie]
(command block 2 chain, conditional, always active) --- is it not in someone's inventory?
execute unless entity @a[nbt={Inventory:[{id:"minecraft:light_gray_stained_glass",tag:{display:{Name:"{\"text\":\"Thingie\",\"color\":\"gold\"}"}}}]}]
(command block 3 chain, conditional, always active) --- then summon one.
summon item 234 70 -186 {Tags:["Thingie"],CustomName:"{\"text\":\"\"}",Item:{id:"minecraft:light_gray_stained_glass",Count:1b,tag:{display:{Name:"{\"text\":\"Thingie\",\"color\":\"gold\"}"}}}}
Everything works... mostly. (sometimes spawns several)
If I open my inventory, click on the item to drag it, or move it around inside my inventory, another gets summoned. Is there another check somewhere to see if it is picked up, but not in my inventory? I've looked all over my player data, and can't find anything... bug?
Anyone have any ideas or suggestions for a better way to do what I want?
/clear
with a count of 0, but I'll have to check, in about 10 hours or so./clear
is the number of matching items you have, if you specify 0 items to be cleared. It's a bit weird and unintuitive, since clearing 0 items seems useless, but the return value is the only thing you want.