1

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

Frank
  • 22,281
  • 30
  • 97
  • 143
MCCG
  • 169
  • 2
  • 2
  • 8

3 Answers3

4

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.

Unionhawk
  • 33,722
  • 34
  • 159
  • 243
0

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.

Moddl
  • 4,080
  • 1
  • 17
  • 41
-1

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

Arperum
  • 8,620
  • 11
  • 65
  • 91
  • 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 01 '16 at 20:18
  • @penne12 Ooooh... I learned something today. – Arperum Jan 02 '16 at 00:17