Minecraft /testfor Players Using Items

minecraft-java-edition

I am trying to create a hydration system for my Minecraft adventure map that displays hydration levels on the scoreboard. To restore the players hydration a player should need to drink a water bottle, and so I figured this command would do the trick: /testfor @p {stat.useItem:373}

However I receive an error: (player) did not match the required data structure

Does anyone know why I recieve this error and if there is any way to make the command work? (preferably without using scoreboard values instead as I want to use the scoreboard values to display the hydration levels themselves)

Best Answer

stat.useItem is not a NBTag, it's a scoreboard objective type. Moreover, if it even was an data tag, you'd be testing for someone who has used an item 373 times, not someone who's used water once.

You are going to need to use scoreboard objectives for this. I feel like your concern may be a misunderstanding though; you can have as many different objectives as you want, and don't have to display the ones you don't want to be seen.

To set up this objective, type:

/scoreboard objectives add drankWater stat.useItem.minecraft.potion

You can then test for people who drank water like this:

/testfor @a[score_drankWater_min=1]

And reset their score to 0 like this:

/scoreboard players set @a[score_drankWater_min=1] drankWater 0