How could I test if a player is holding a specific item in slot 0 in Minecraft 1.7.9/10?
My question is how could I go about testing if a player is holding an Enderpearl in Slot 0 without mods, plugins or updates?
Best Answer
You can't. The SelectedItem and SelectedItemSlot data tags are new in Minecraft 1.8. Furthermore, testfor can only check NBT data as of Minecraft 1.8. The scoreboard command checking players based on NBT data is new as of 1.8 as well. Therefore, the only way to be able to do this is to update to Minecraft 1.8.
But let's say you do update to 1.8. You can do a simple testfor and get a redstone output like so:
/testfor @a {Inventory:[{Slot:0,id:"minecraft:ender_pearl"}]}
This will output a redstone signal if any player has an ender pearl in slot 0 (it doesn't check if they have slot 0 selected, though; to do that, change the above data tag to {SelectedItemSlot:0,Inventory:[{Slot:0,id:"minecraft:ender_pearl"}]})
This command isn't particularly useful though. All it does is output a redstone signal if any player meets the criteria. In order to do anything with it, /scoreboard becomes your best friend. To start, create a dummy objective:
/scoreboard objectives add pearls dummy
Next, we want to reset this score for all players, and then set it to 1 for players with a pearl in slot 0:
/scoreboard players set @a pearls 0
/scoreboard players set @a pearls 1 {Inventory:[{Slot:0,id:"minecraft:ender_pearl"}]}
Now you can actually use this information in a target selector, by using @a[score_pearls_min:1] as your player argument in other commands.
But the short answer to your question, if you really don't want to update, is you can't.
Pictures about "How could I test if a player is holding a specific item in slot 0 in Minecraft 1.7.9/10?"



How do you detect if a player is holding an item in Minecraft?
How to Keep Your Inventory When You Die in Minecraft on Android[1.17] How to Detect If a Player Is Holding a Named Item
More answers regarding how could I test if a player is holding a specific item in slot 0 in Minecraft 1.7.9/10?
Answer 2
You can't detect an item in an specific slot in 1.7. In 1.8 you can. The best you can do is detect wether or not an item in in a player's inventory, regarless of the slot using a comparator and the /clear command clearing 0 items.
Answer 3
You can't...
The best you do in versions before 1.8 is test if the player has a item in their inventory with the command /clear @p minecraft: (item name) 0 0 by updating to 1.8 you can use the command /testfor @a {Inventory:[{Slot:0,id:"minecraft:ender_pearl"}]} But.. that won't be much use without scoreboards
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: RODNAE Productions, RODNAE Productions, RODNAE Productions, RODNAE Productions
