How to Create an Axe that Summons Lightning on Hit in Minecraft
Minecraft Java Edition 1.21+ and 26+ – Lightning Hit using Scoreboard and Functions
Want to add amazing powers to your axe in Minecraft?
In this tutorial, you'll learn how to create a special axe that summons lightning whenever you hit a mob.
Using scoreboards, Repeat Command Blocks, and functions, you can create custom hit effects without hurting yourself.
Perfect for minigames, custom maps, or just for fun in your world!
Before we start, let's get a special diamond axe with the supermachado tag, use this command:
give @p minecraft:diamond_axe[minecraft:custom_data={supermachado:1b},minecraft:rarity=rare,minecraft:enchantment_glint_override=true]
And create the scoreboard that will detect damage dealt by ourselves
scoreboard objectives add dano minecraft.custom:minecraft.damage_dealt
After that, place a Repeat command block set to Always Active with this command:
execute as @a if score @s dano matches 1.. run function comandos:summon_lightning
Whenever a player deals damage, the commands in the function will execute from their position
Download the ready and complete function by clicking here and place it inside the datapacks folder
If you've never created a function and don't know what it is, check this tutorial to understand and do this process
Here are the commands from the function I created to summon lightning whenever a mob takes damage
effect give @s minecraft:resistance 1 4 true
execute if items entity @s weapon.* minecraft:diamond_axe[minecraft:custom_data={supermachado:1b}] run execute at @e[type=!player,limit=1,sort=nearest] run summon minecraft:lightning_bolt ~ ~ ~
scoreboard players set @s dano 0
In short, the effect command is to minimize the lightning damage to ourselves
The second command detects if we're holding the diamond axe with the supermachado tag and then summons lightning on the nearest mob to us
The last command resets the score gained from dealing a hit, preventing the command from running infinitely
Test it out and have fun!