How to Make a Vampire Sword in Minecraft (Lifesteal Sword)
Minecraft Java Edition 1.21+ and 26+ – Lifesteal Weapon Using Scoreboard and Custom Data
In this tutorial, you will learn how to create a Vampire Sword (lifesteal sword) in Minecraft, allowing the player to heal when dealing damage to mobs or other players.
This system works in Minecraft Java Edition 1.21+ and 26+ and uses custom_data to identify the weapon and a scoreboard objective to detect damage dealt.
Whenever the player hits an enemy using the custom sword, the game will automatically give regeneration, creating a lifesteal ability perfect for RPG servers, custom survival worlds, and adventure maps.
Let's get an iron sword with the following tag
give @p minecraft:iron_sword[minecraft:custom_data={espada:vampira}]
And create the scoreboard that will detect the damage we deal to a mob
scoreboard objectives add danoCausado custom:damage_dealt
Get a command block, set it to Repeat and Always Active
Now enter the command below to run the following function
execute as @a run function comandos:vampire_sword
The goal of this function is to detect if a player dealt damage using the vampire sword
If the player does, they will receive the regeneration effect and their scoreboard score will be reset
If you don't know how to create a function, check out this tutorial with the full step-by-step guide here on the site
You can download the function I used by clicking here
Here are the function commands in case you want to place them directly into the command block
execute if entity @s[scores={danoCausado=1..}] run execute if items entity @s weapon.mainhand minecraft:iron_sword[minecraft:custom_data={espada:vampira}] run effect give @s regeneration 3 1 true
scoreboard players reset @s danoCausado