Q. What is the most effective /testfor command?

Q. What is the most effective /testfor command? - Black Dart Hit a Bullseye

Ok, I've tried many variants of /testforcommand and tried them in the lastest snapshot, 15w31c, to 1.8.6 and nothing works AT ALL.

The list of commands I've tried:

  • /testfor @p {Inventory:[{id:"minecraft:iron_­sword"}]}
  • /testfor @p {Inventory:[{Slot:0b,id:"minecraft:­iron_sword"}]}
  • /testfor @p {SelectedItemSlot:0,Inventory:[{Slot:0b,id:"minecraft:iron_sword"}]­}
  • /testfor @p {Inventory:[{tag:{display:{Name:"Iron_Sword"}}}]}
  • And more but I can't remember them due to the frustration

The idea I'm trying to get at is you have a special book when right-clicked it'll spawn two items. One of them you must have on the second hand, in 15w31c, at all time that will interact with whatever weapon of your choosing, Swords, Axes, and Bow & Arrows. The second item is just a book so no real need for it to be forced on right now. I know I have to use /testfor for the book, second hand item, and weapons, but like I said nothing is working.



Best Answer

Tested the first 2 commands. Removing the quotes from minecraft:iron_sword and places a space after @p produces expected results.

enter image description here/testfor @p {Inventory:[{id:minecraft:ironsword}]}


enter image description here/testfor @p {Inventory:[{slot:0b,id:minecraft:iron_sword}]}


enter image description hereSame as above, but sword in wrong slot


In the first two examples, if you had those in a command block with a comparator attached, the comparator would output a 1 redstone strength. The last example would not output any redstone strength.




Pictures about "Q. What is the most effective /testfor command?"

Q. What is the most effective /testfor command? - What Text on a Pink Surface
Q. What is the most effective /testfor command? - Male Portrait
Q. What is the most effective /testfor command? - Brown Wooden Blocks on White Table



What is the Testfor command?

You can test for a certain target in the game using the /testfor command in Minecraft.

How do you use the Testfor command in Minecraft Java Edition?

The /testfor command became obsolete in Minecraft 1.13, and has been replaced by the /execute command*. It will do the same as typing /testfor @e {SelectedItem:{id:"<item>"}} and then putting a comparator to the command block with the command, and then running the command which you wanna run.



Minecraft Bedrock - Test For Items In Inventory (Mobile/Xbox/PS4/Windows 10/Switch)




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Skitterphoto, Ann H, Angelica Reyn, Brett Jordan