My question is how could I go about testing if a player is holding an Enderpearl in Slot 0 without mods, plugins or updates?


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.

| improve this answer | |

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.

| improve this answer | |

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

| improve this answer | |
  • 2
    Please don't capitalize the first letter of every word. It makes the text way harder to read. – Arperum Nov 11 '15 at 21:47
  • In another note: are you sure the clear command just checks the content of an iunventory? to me that sounds like it would remove that item. (I did not check this on the wiki, so I could be mistaken) – Arperum Nov 11 '15 at 21:48
  • @Arperum, he uses a max count of 0, so it will try to clear at most 0 items, and it will fail if you don't have the item. – Ben Aubin Jan 1 '16 at 20:18
  • @penne12 Ooooh... I learned something today. – Arperum Jan 2 '16 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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