Skip to content

How to make a sword that sets targets on fire (Minecraft mod)

A sword’s hurtEnemy(stack, target, attacker) runs on the server after a hit lands, with the mob that was hit. Set the target on fire there (target.igniteForSeconds(n) on 1.20.5 and newer, setSecondsOnFire before), then return super.hurtEnemy so the sword still loses durability. The same method works for any on-hit effect: slowness, lightning, knockback. The sword is a SwordItem up to 1.21.4; from 1.21.5 it is a plain Item that is made a sword through its properties.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Make a sword class with your tier and attributes (extend SwordItem, or a plain Item on 1.21.5 and newer).
  2. Override hurtEnemy and set the target on fire.
  3. Return super.hurtEnemy(…) so the sword still wears down.
  4. Register the item, use the item/handheld model and add it to the #minecraft:swords tag (not on 1.16.5 and older).

The example uses these values. Change them in the code.

Setting In the example What it does
seconds 5 How long the target burns, in seconds.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric and NeoForge 1.20.1 to 1.20.4, Fabric 1.16.5 to 1.20, Forge 1.17.1 to 1.20.1

Section titled “Fabric and NeoForge 1.20.1 to 1.20.4, Fabric 1.16.5 to 1.20, Forge 1.17.1 to 1.20.1”

Uses:

  • SwordItem.hurtEnemy
  • Entity.setSecondsOnFire
  • Tiers

src/main/java/com/example/examplemod/item/EmberBladeItem.java

package com.example.examplemod.item;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
// Ember Blade: an iron sword that sets what it hits on fire for 5 seconds. hurtEnemy runs on the server after a hit lands.
public class EmberBladeItem extends SwordItem {
public EmberBladeItem(Item.Properties properties) {
super(Tiers.IRON, 3, -2.4F, properties);
}
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.setSecondsOnFire(5);
return super.hurtEnemy(stack, target, attacker);
}
}

In src/main/resources/data/minecraft/tags/items/swords.json, add this to the list at /values:

"examplemod:ember_blade"

It’s registered like any other item, as EmberBladeItem: see a new item.

Uses:

  • SwordItem.hurtEnemy
  • Entity.igniteForSeconds
  • SwordItem.createAttributes
  • Tiers

src/main/java/com/example/examplemod/item/EmberBladeItem.java

package com.example.examplemod.item;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
// Ember Blade: an iron sword that sets what it hits on fire for 5 seconds. hurtEnemy runs on the server after a hit lands.
public class EmberBladeItem extends SwordItem {
public EmberBladeItem(Item.Properties properties) {
super(Tiers.IRON, properties.attributes(SwordItem.createAttributes(Tiers.IRON, 3, -2.4F)));
}
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.igniteForSeconds(5);
return super.hurtEnemy(stack, target, attacker);
}
}

In src/main/resources/data/minecraft/tags/items/swords.json, add this to the list at /values:

"examplemod:ember_blade"

It’s registered like any other item, as EmberBladeItem: see a new item.

Uses:

  • SwordItem.hurtEnemy
  • Entity.igniteForSeconds
  • SwordItem.createAttributes
  • Tiers

src/main/java/com/example/examplemod/item/EmberBladeItem.java

package com.example.examplemod.item;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
// Ember Blade: an iron sword that sets what it hits on fire for 5 seconds. hurtEnemy runs on the server after a hit lands.
public class EmberBladeItem extends SwordItem {
public EmberBladeItem(Item.Properties properties) {
super(Tiers.IRON, properties.attributes(SwordItem.createAttributes(Tiers.IRON, 3, -2.4F)));
}
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.igniteForSeconds(5);
return super.hurtEnemy(stack, target, attacker);
}
}

In src/main/resources/data/minecraft/tags/item/swords.json, add this to the list at /values:

"examplemod:ember_blade"

It’s registered like any other item, as EmberBladeItem: see a new item.

Uses:

  • SwordItem.hurtEnemy
  • Entity.igniteForSeconds
  • ToolMaterial

src/main/java/com/example/examplemod/item/EmberBladeItem.java

package com.example.examplemod.item;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.ToolMaterial;
// Ember Blade: an iron sword that sets what it hits on fire for 5 seconds. hurtEnemy runs on the server after a hit lands.
public class EmberBladeItem extends SwordItem {
public EmberBladeItem(Item.Properties properties) {
super(ToolMaterial.IRON, 3, -2.4F, properties);
}
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.igniteForSeconds(5);
return super.hurtEnemy(stack, target, attacker);
}
}

In src/main/resources/data/minecraft/tags/item/swords.json, add this to the list at /values:

"examplemod:ember_blade"

It’s registered like any other item, as EmberBladeItem: see a new item.

Uses:

  • Item.hurtEnemy
  • Entity.igniteForSeconds
  • Item.Properties.sword
  • ToolMaterial

Since 1.21.5 there is no SwordItem: Item.Properties#sword(material, damage, speed) makes a plain Item a sword, and hurtEnemy is overridden on Item.

src/main/java/com/example/examplemod/item/EmberBladeItem.java

package com.example.examplemod.item;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial;
// Ember Blade: an iron sword that sets what it hits on fire for 5 seconds. hurtEnemy runs on the server after a hit lands.
public class EmberBladeItem extends Item {
public EmberBladeItem(Item.Properties properties) {
super(properties.sword(ToolMaterial.IRON, 3, -2.4F));
}
@Override
public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.igniteForSeconds(5);
super.hurtEnemy(stack, target, attacker);
}
}

In src/main/resources/data/minecraft/tags/item/swords.json, add this to the list at /values:

"examplemod:ember_blade"

It’s registered like any other item, as EmberBladeItem: see a new item.

Uses:

  • SwordItem.hurtEnemy
  • LivingEntity.setSecondsOnFire
  • ItemTier

The minecraft:swords and minecraft:pickaxes item tags do not exist in 1.16.5: the item class (SwordItem, PickaxeItem) decides what it can do.

src/main/java/com/example/examplemod/item/EmberBladeItem.java

package com.example.examplemod.item;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ItemTier;
// Ember Blade: an iron sword that sets what it hits on fire for 5 seconds. hurtEnemy runs on the server after a hit lands.
public class EmberBladeItem extends SwordItem {
public EmberBladeItem(Item.Properties properties) {
super(ItemTier.IRON, 3, -2.4F, properties);
}
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
target.setSecondsOnFire(5);
return super.hurtEnemy(stack, target, attacker);
}
}

It’s registered like any other item, as EmberBladeItem: see a new item.

Uses:

  • ItemSword.hurtEnemy
  • EntityLivingBase.setSecondsOnFire
  • ToolMaterial

In 1.12.2 the class extends ItemSword and the fire is target.setFire(seconds).

src/main/java/com/example/examplemod/item/EmberBladeItem.java

package com.example.examplemod.item;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
// Ember Blade: an iron sword that sets what it hits on fire for 5 seconds. hitEntity runs on the server after a hit lands.
public class EmberBladeItem extends ItemSword {
public EmberBladeItem() {
super(Item.ToolMaterial.IRON);
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
target.setFire(5);
return super.hitEntity(stack, target, attacker);
}
}

It’s registered like any other item, as EmberBladeItem: see a new item.

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.