How can I use /testfor to see if someone is holding a diamond in their main hand?

  • 2
    @pppery I believe that adding NBT-tags to an item and testing for NBT-tags are fundamentally different things. They may have the same answer, but the question is not the same. If this was possible, then the answers would be very different from another. (Also sorry, I feel like you only hear from me when I disagree with you, I really appreciate what you do for the most part though and I don't want you to think that I disagree just to diagree) – user232393 Jul 23 '19 at 20:37
  • 1
    @bearb001 The question I tried to dupe this to is titled "How do you add NBT tags to commands ...", not "How do you add NBT tags to items ...". This question is asking something that would require the usage of NBT (in Java Edition), and the answer to it is, as explained by the duplicate, "this is impossible". By leaving this question open, you are introducing an artificial distinction not supported by the wording of the duplicate. – pppery Jul 23 '19 at 21:24
  • @pppery Sorry, I meant adding NBT tags in general and testing for NBT tags in general, those are two different things. They could maybe be combined with "how do you use NBT tags in commands" though, as "using" includes both "adding" and "testing for" – user232393 Jul 23 '19 at 21:27
  • @bearb001 The operation of transforming a /testfor command from "find all players" to "find all players holding diamond" is adding NBT to the command in exactly the same way as transforming a /give command from "give <players> a sword" to "give <players> a sword named 'Foo'" or "give <players> an enchanted sword" is. There's no difference. – pppery Jul 23 '19 at 21:30
  • @pppery no it is not. In one case you add NBT tags, this would be done in the NBT part of the command in Java. In the other you want to test for NBT tags, this would usually be done in the target selector, or in the if or unless part of an /execute command – user232393 Jul 23 '19 at 21:32

Unfortunately, MCPE doesn’t support NBT tags and therefore this is not possible.

Source: Commands/testfor on Minecraft Gamepedia

Not the answer you're looking for? Browse other questions tagged or ask your own question.