Detect if player clicks with item such as stick or blaze rod?

Detect if player clicks with item such as stick or blaze rod? - Closeup of burning fire on match head among pile of black matches in jar on blurred background

how would I detect if player clicks with item such as stick or blaze rod?

I suppose this would use scoreboards?

I also can not use comparators or such, it will all be hooked up to a clock, although there can be commands which are only commenced once at the beginning.

the reason I cant use comparators is because I am creating a one command creation in a generator.

so far I have stared at a wall and tried to think of something.



Best Answer

You can do right click and left click detection, luckily, and 1.9 makes this easier than ever!

Prerequisites:

/scoreboard objectives add rClick stat.talkedToVillager
/scoreboard objectives add holdingBlazeRod dummy
/summon Villager ~ ~ ~ {CustomName:"ClickNpc",ActiveEffects:[{id:14b,Duration:10000,Amplifier:0}],Silent:1b,Offers:{}}

Put this in a clock:

/tp @e[type=Villager,name=ClickNpc] @p
/scoreboard players set @a holdingBlazeRod 0
/scoreboad players set @a holdingBlazeRod 1 {SelectedItem:{id:minecraft:blaze_rod}}

Type this in front of the command you want to execute when blaze rod is right clicked:

/execute @a[score_holdingBlazeRod_min=1,score_rClick_min=1] ~ ~ ~ ...

Done!




Pictures about "Detect if player clicks with item such as stick or blaze rod?"

Detect if player clicks with item such as stick or blaze rod? - Glass pipette with aromatic oil in plate near rosemary branches
Detect if player clicks with item such as stick or blaze rod? - Selective Focus Photography of Two Men Playing American Football
Detect if player clicks with item such as stick or blaze rod? - Back View of Person in Blue Vest Wearing Red Beanie Hat Standing on Curling Rink





Detect Right Clicks Minecraft [1.16]




More answers regarding detect if player clicks with item such as stick or blaze rod?

Answer 2

The closest you could get would be the useItem statistic, but this only works for items that have a valid "use" action such as tools, weapons, placeable items/blocks, etc. Scoreboards is not currently possible for items without a "use" action (would be really nice for Mojang to add this in the future). A possible alternative (assuming the right click action is supposed to be a "1-time-use" action and not a continuous action would be to drop a named item on the ground and use the execute command (or similar) to check for a specific item type with a specific name.

Answer 3

You could get selected item by using a command like this with a command-block and a comparator :

/testfor @p {SelectedItem:{id:"minecraft:diamond_sword"}

And then you could use a right-click detector. See this video :

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Wendelin Jacober, Monstera, Pixabay, SHVETS production