Updated:
1. Count right-clicks
/scoreboard objectives add click minecraft.used:minecraft.carrot_on_a_stick
2. Give the wand
/give @s minecraft:carrot_on_a_stick[custom_name="Thunder Wand",unbreakable={}]
3. Lightning on right-click
Use a repeating, always active block followed by a chain, always active block:
/execute as @a[scores={click=1..}] at @s anchored eyes run summon lightning_bolt ^ ^ ^10
/scoreboard players reset @a[scores={click=1..}] click
Lightning strikes ten blocks ahead of where the player looks, then the count resets. See ~ and ^ coordinates.
4. Other effects
/execute as @a[scores={click=1..}] at @s run tp @s ^ ^ ^5
/execute as @a[scores={click=1..}] run effect give @s minecraft:levitation 1 5 true
The first is a blink stick that moves you five blocks forward; the second lifts you briefly.
5. Tell wands apart and add a cooldown
/give @s minecraft:carrot_on_a_stick[custom_name="Thunder Wand",custom_data={wand:"thunder"},use_cooldown={seconds:3}]
/execute as @a[scores={click=1..}] if items entity @s weapon.mainhand minecraft:carrot_on_a_stick[custom_data~{wand:"thunder"}] at @s anchored eyes run summon lightning_bolt ^ ^ ^10
use_cooldown needs Java 1.21.2 or later.
6. Spend XP levels like mana
# repeating, always active
execute as @a[scores={click=1..},level=1..] at @s anchored eyes run summon lightning_bolt ^ ^ ^10
# chain 1
xp add @a[scores={click=1..},level=1..] -1 levels
# chain 2
scoreboard players reset @a[scores={click=1..}] click
Only players with at least one level cast the spell, and each cast costs one level. At level 0 nothing happens. Keep the chain order: resetting first would skip the cost. See the xp command.
Troubleshooting
- Nothing happens: check the reset chain block is attached behind the repeating block.
- Lightning hits you: target a point ahead, such as
^ ^ ^10. - Other items: swords and bows have their own right-click actions; use a carrot or warped fungus on a stick.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.