make a datapack that adds an explosive sword enchant, the enchant should make every mob hit with the sword that has this enchant explode.
I’ll create the ExplosiveSword data pack with a custom enchantment that makes hit mobs explode.
Done. The Explosive Sword data pack adds a custom enchantment:
How it works:
The
Explosiveenchantment (gold, level 1) is available on swords via enchanting tables, villager trades, and loot chestsWhen a player hits any mob while holding a sword with this enchantment, the nearest non-player entity within 3 blocks (the mob they just hit) explodes
The explosion is a real TNT blast — damages the mob, nearby entities, and the terrain
To use:
Extract the folder into
world/datapacks/Run
/reloadEnchant a sword with Explosive (via enchanting table, anvil with enchanted book, or
/enchant @s explosive_sword:explosive)Hit any mob — it explodes on contact
how do i download it?
I don’t have a built-in download/export button in this chat — you’ll need to create the files manually from the content I already displayed above. Here’s the quickest way:
1. Copy the folder structure:
Create these files in a folder called explosive_sword_datapack:
explosive_sword_datapack/
├── pack.mcmeta
└── data/
├── explosive_sword/
│ ├── enchantment/
│ │ └── explosive.json
│ ├── advancement/
│ │ └── explosive_hit.json
│ └── function/
│ ├── trigger_explosion.mcfunction
│ └── load.mcfunction
└── minecraft/
└── tag/
├── enchantment/
│ ├── in_enchanting_table.json
│ ├── tradeable.json
│ └── on_random_loot.json
└── function/
└── load.json
2. Copy the file contents from my previous message — each <create> block shows the full content for that file.
3. Place it in your world:
Navigate to
saves/<YourWorld>/datapacks/Drop the
explosive_sword_datapackfolder in thereLaunch Minecraft and run
/reload
If you want, I can simplify this — I can remake the pack with fewer files (combining everything into fewer files) to make manual copying easier. Just say the word.
add a function for /enchant
Now run /function explosive_sword:enchant while holding a sword to add the Explosive enchantment.
doesn't work
Looking at all the files, I see several issues. Let me fix the whole system:
The advancement conditions are too strict/complex
The function needs to check the enchantment itself
No repeatability (advancement fires once)
What changed:
Advancement now triggers on any hit (no conditions) — the enchantment check moved to the function
New predicate (
has_explosive.json) checks if the player’s mainhand has the Explosive enchantmentFunction uses the predicate, summons TNT at the nearest mob, then revokes the advancement so it can fire again on the next hit
Give it a try with /reload!
# Check if player has Explosive enchantment on mainhand
execute if predicate explosive_sword:has_explosive as @e[type=!player,distance=..5,limit=1,sort=nearest] at @s run summon minecraft:tnt ~ ~ ~ {Fuse:0}
# Allow repeat triggering
advancement revoke @s only explosive_sword:explosive_hit