Minecraft Blogs / Tutorial

How To Test If A Player Is Holding A Specific Item

  • 20,257 views, 2 today
  • 9
  • 2
  • 7
TerraScript's Avatar TerraScript
Level 31 : Artisan Engineer
12
Hello there! Today I will be showing you how to test to see if a player is holding a specific item. In this demonstration, to show that it works, I will apply invisibility to myself when holding white stained glass. So let's get things started. Begin by making a fill clock:


Fill Clock
undefined

The top command block command:
/fill ~ ~-1 ~ ~9 ~-1 ~ minecraft:redstone_block

The bottom command block command:
/fill ~ ~1 ~ ~9 ~1 ~ minecraft:bedrock


After that, set up a new dummy scoreboard objective with the name "holding": /scoreboard objectives add holding dummy Holding

Hold up. We need to know in which order in a fill clock do commands get activated. Press F3 to get all of your client statistics. In the top left, look for the area that is labeled "Facing". Make sure that you're facing north (or negative Z, whichever you prefer). Commands will then activate from bottom to top, and left to right. That in mind, let us continue.



Let's set the value of "holding" to a player to 1 when they're holding a white stained glass. To do this, use this command:
/scoreboard players set @a holding 1 {SelectedItem:{id:"minecraft:stained_glass",Damage:0s}}


Placement of the First Command Block (That isn't a fill clock command)
undefined


Now, whenever a person is holding a white stained glass, their "holding" score will be set to 1.


Next, let's apply a perpetual invisibility effect to a player will a "holding" score of 1 with the command: /effect @a[score_holding_min=1] invisibility 2 0
Placement of the Second Command Block (That isn't a fill clock command)
undefined


Now, whenever a player is holding a white stained glass, they get invisiblity. But we have a problem! Whenever a player isn't holding the glass anymore, they still get the effect! To fix this, add a last command block that constantly sets the "holding" score of a player to 0. Make SURE this comes AFTER the first two, otherwise it could mess up the machine. Use this command: /scoreboard players set @a holding 0
Placement of the Third Command Block (That isn't a fill clock command)
undefined
Outcome
undefined

undefined


Things to consider: This is my single player world, and I'm on a team, hence the translucency of my invisibility effect. Also, the sidebar is displaying as "holding" as 0, even when I'm holding it. Doesn't matter, still works. >:)



If you're struggling with redstone or need help, feel free to contact me via PMC.



Remember, if you liked this tutorial feel free to  Subscribe  and diamond it. Be sure to leave a comment if you need me to make a tutorial on something else, or if you want to see different kinds of blogs.





 Too da loo!
Tags

Create an account or sign in to comment.

1
05/05/2017 12:47 pm
Level 1 : New Miner
Kalitas
Kalitas's Avatar
what version?
1
07/11/2016 11:45 am
Level 9 : Apprentice Modder
FuturisticIdiot
FuturisticIdiot's Avatar
how do u add the scoreboard holding?
1
07/14/2016 2:52 pm
Level 31 : Artisan Engineer
TerraScript
TerraScript's Avatar
"/scoreboard objectives add holding dummy Holding" in chat, not in a command block.
1
06/10/2016 11:02 pm
Level 1 : New Crafter
jzo_ThePanda
jzo_ThePanda's Avatar
how do you test for holding different kinds of glass though?
1
07/14/2016 2:49 pm
Level 31 : Artisan Engineer
TerraScript
TerraScript's Avatar
Change "/scoreboard players set @a holding 1 {SelectedItem:{id:"minecraft:stained_glass",Damage:0s}}". Instead of saying Damage:0s, change it to say Damage:xs, with x being the damage value of the kind of glass you want. For example, light gray stained glass would be Damage:8s. The ID should stay the same. Hope I helped!
1
05/26/2015 7:56 am
Level 62 : High Grandmaster Senpai
Dudamesh
Dudamesh's Avatar
some helpful tutorials you got here.
better Subscribe to keep track of it ;D
1
05/26/2015 12:48 pm
Level 31 : Artisan Engineer
TerraScript
TerraScript's Avatar
Thanks a lot! :)
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome