I'm trying to make sort of a command block trade shop thing. I've got it working with these commands in a chain of command blocks:

execute as @a if data entity @s {Inventory:[{id:"minecraft:diamond",Count:5b}]} run tag @s add lostDoubloon

clear @p[tag=lostDoubloon] minecraft:diamond 5

give @a[tag=lostDoubloon] sunflower 1

tag @p[tag=lostDoubloon] remove lostDoubloon

This works as it removes 5 diamonds and gives 1 sunflower. But it only does this if there is a EXACTLY 5 diamond stack in the inventory. If it is anything above or less this doesn't work. How can I make it so that it works even if the diamonds are spread in the inventory or has more than 5 in a stack? I tried this but it didn't seem to work:

execute as @a store result score @s itemsCleared run clear @s minecraft:diamond 0
tag @a[scores={itemsCleared=5}] add lostDoubloon

I feel like I'm really close but I don't know where I'm going wrong. Please help~!



Browse other questions tagged .