How can I remove a specific amount of items from a player with commands, only when the player has equal or more than the requiered items?

I know how to do it, with specific quantity of items, such as 2 ender eyes, for example: /execute if data entity @p {Inventory:[{id:"minecraft:eye_of_ender",Count:2b}]}

But it doesn't work if the player has more than 2, what can I do?


Solution 1:

Setup:

scoreboard objectives add eyesOfEnder dummy

Run these commands every tick:

execute store result score #count eyesOfEnder run clear @p minecraft:eye_of_ender 0

execute if score #count eyesOfEnder matches 2.. run clear @p minecraft:eye_of_ender 2