You are watching: How to test if a player is holding an item
However, the over command has actually been fully deprecated in 1.13. Testfor is currently Bedrock only, and also the
To incorporate the two dataTags you require to move the tag link from an initial command right into the list item link in the second:
You deserve to use the SelectedItem tag instead of the SelectedItemSlot tag. This will allow you come target any player who at this time has the specified item selected no issue which slot the is in:
scoreboard football player tag
a add SelectedItem:id:"minecraft:diamond_sword",tag:display:Name:"Item Name"This permits you come target the football player within an additional command. Allows make the players through the selected knife say hello:
Then to eliminate the tags from all player:
scoreboard players tag
a remove If you want to check for any type of player hold any item v the exactly name, merely omit the id part of the dataTag:
If you are using a data pack, for better performance, a predicate have to be supplied to recognize holding things in the main hand.
Predicates are much more efficient 보다 /execute if entity
s … due to the fact that NBT checks on football player are hefty on performance.
Predicates go in the /data//predicates folder of your data pack.
See more: If A Snowball Melts So That Its Surface Area Decreases At A Rate Of 1 Cm^2/Min Find The Rate
A sample predicate for this purpose would look favor this:
"condition": "minecraft:entity_properties", "entity": "this", "predicate": "equipment": "mainhand": "items": <"minecraft:diamond_sword">, "nbt": "CustomItemTag:1b"
/scoreboard objectives add ItemHold stat.useItem.minecraft.diamond.sword I have tested it and it works so try that...
Highly energetic question. Knife 10 reputation (not counting the combination bonus) in order come answer this question. The reputation need helps safeguard this question from spam and also non-answer activity.
Not the price you're spring for? Browse various other questions tagged minecraft-java-edition minecraft-commands or questioning your own question.
How carry out I make it so as soon as a player is stop a details item in your hotbar or offhand, that a potion effect is provided to them?
site design / logo © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.10.8.40416