How to use the scoreboard command to testfor for a player that selected a snowball, namely "Blast" in Minecraft 1.9?
Minecraft – how to testfor a player that selected an item
minecraft-commandsminecraft-java-edition
Related Solutions
It's very difficult to see whether someone has an object anywhere in their inventory. That would take 36 command blocks, one for each slot! You can, however, take the object, then see if taking the object worked.
The Commands
- Set up a fast clock (but not as fast as a fill clock)
- One command block does
/clear @p iron_ingot 0 1
(clears 1 iron ingot from the nearest player. You can choose which player, but it must be exactly one. Also, you must use the same selector throughout all these commands.) - Run a comparator from that command block to another command block running this command:
/scoreboard players add @p ironIngots 1
(Increases the player'sironIngots
score by 1. Make sure you createironIngots
first!) - Create another command block that does whatever you want. In the case of giving them a diamond, you would do this:
/give @p[score_ironIngots_min=10] diamond
. Note the target selector; it gives the player the diamond only if their ironIngots score is 10 or greater. - The last thing you want to do is take the ironIngots score away so they don't keep getting items. Just run
/scoreboard players remove @p[score_ironIngots_min=10] ironIngots 10
. This removes 10 iron ingots from the player if they have anironIngots
score of 10 or greater. Any player who matches this will have received a diamond in the previous step.
How to Set Them Up
The commands listed above must run in order. It is actually very simple to put them in order. Just open the debug menu and look at the stylish new crosshair. Align the command blocks along either the green or red line so that one of those lines points down the first to the last command block.
Notes
- You don't have to press a button to use this, you just have to be the nearest player. You can change the command to the nearest player within 10 blocks, nearest player on a team, etc.
- The commands will take a short amount of time to finish, but for 10 iron ingots, it will only take half a second. It's one tick (1/20 of a second) per item taken away.
- It will take away iron ingots even if you don't have ten. However, you can submit one, then later submit five, then submit four more later, and it will still give you the diamond. You can also submit 14 at a time and the extra 4 will be saved for later.
While you cannot use testfor to do this, you CAN use execute detect. This is most likely how it would look: /execute @a ~ ~ ~ detect ~1 ~ ~ grass 0 <command>
the execute command will detect a grass block to the left (in the X cord) of all players in the world. the command is how you would track that player if it detects the block successfully.
an example tracking command would be /execute @a ~ ~ ~ detect ~1 ~ ~ grass 0 scoreboard players set @p Sample_Obj 1
comment if you have any other questions.
Best Answer
The
SelectedItem
compound holds a copy of the player's currently-held item (minus theSlot
tag). All item data that is not the rootid
,Damage
,Count
, orSlot
, must be placed within a singletag
compound.As of 1.9 you will want to use "tags" instead of scores when labeling the player, which is more efficient and does not require an objective: