Test if player is holding something but the specified item

So I’m making a command block mechanism, but I need to test if the player is carrying something other than a specified item like testfor @p {SelectedItem:{id:minecraft:stick}}, whereas this instance it’d activate if the player is carrying anything but a stick. If that is impossible is there a way to test if the player is not carrying anything at all?

  • How do you set Minecraft offline mode player name and also pass parameters into the jar?
  • New Minecraft Launcher parameters and portability
  • How do I fix randomly moved chunks after a crash?
  • Is there some way of automatically farming wool from sheep?
  • How do you test if a player is holding a Skull with a skull owner?
  • How can I import worlds from the PE to the PC version?
  • Can mobs spawn on slabs?
  • How do friends come to my ftb server?
  • How can I change my Minecraft username?
  • What blocks can Mobs/The Player spawn on?
  • What level does lightning start at in minecraft?
  • How can I improve the performance of Minecraft?
  • 7 Solutions collect form web for “Test if player is holding something but the specified item”

    Set up a dummy objective:

     /scoreboard objectives add NotHoldingItem dummy
    

    On a clock (or just before you want to use the testfor), in this order, run the following commands:

     scoreboard players set @a NotHoldingItem 1
     scoreboard players set @a NotHoldingItem 0 {SelectedItem:{id:minecraft:stick}}
    

    The commands above set everyone’s NotHoldingItem score to 1, and then set it back to 0 for everyone holding the item, leaving only people not holding the item with a NotHoldingItem score of 1.

    You can then test for people who have a NotHoldingItem score of 1:

    /testfor @a[score_NotHoldingItem_min=1]
    

    Here’s one possible method:

    Create one command block for each item slot. Then, create a command to check the item AND if the slot is active, then connect them all to a single input on one end and a single output on the other.

    The first command block should have:

    /testfor @p {SelectedItemSlot:0,Inventory:[{Slot:0b,­id:"minecraft:stick"}]­}
    

    The second command block should have:

    /testfor @p {SelectedItemSlot:1,Inventory:[{Slot:1b,­id:"minecraft:stick"}]­}
    

    etc.

    Notice that the two slot numbers have changed for each block. Continue changing the slot values for each block until you have 0-8 (requires 9 command blocks). Then, once all the command blocks are connected to the same output (you’ll probably need a comparator and repeater for each), invert the output signal.

    Note: You may need to adjust the output to be off by default with some additional redstone circuitry.

    Just use a comparator to test if a player is holding a stick, and then invert it (via a redstone torch) and have the inverted signal leading to a command block. Now, whenever the player is holding a stick, the signal is inverted and the second command block deactivates.

    You can simply add the syntax for “not” (!) to your command.

    testfor @p {SelectedItem:!{id:minecraft:stick}}
    

    The other option would be to just invert the output. So first, you would test that the player is holding a stick:

    testfor @p {SelectedItem:{id:minecraft:stick}}
    

    enter image description here
    enter image description here

    Then if the redstone signal is inverted, this will only trigger the mechanism when the player is not holding a stick.

    Just use a T-Flip Flop….

    (comparator running out of the command block with a repeater into a block which has a redstone torch on the other side which then powers a command block)

    Then it should work

    It’s probably just easiest to use a comparator, and you can test to see whether or not they are holding the stick, and then just invert the output with a NOT gate. I did some additional research, and it turns out that in some versions of Minecraft, a player actually has the syntax of holding “minecraft:air”. This means that to check that they don’t have something in their hand, you actually have to check for air. This does not work in 1.9, as Mojang has removed “minecraft:air” from the database.

    So it might be easiest to do this:
    /testfor @p {SelectedItem:{id:minecraft:air}}
    I feel like there should be a way in 1.9 to just test that there is nothing.
    I’ll look into this a bit more.

    Sure! Just use the command: /testfor @p {SelectedItem:{id:!stick}}, the exclamation point will make do so.

    We love Playing Games, especially Video Games.