Skip to content

A custom enchantment

Status: Implemented for enchantments written as data with vanilla’s effect components. Effect components defined in code (for example a chain-lightning effect) are Planned.

Goal: Ember Edge, a sword enchantment that sets the target on fire and deals extra damage to targets that aren’t burning yet. Data only.

APIs: Enchantments, damage types, effects and attributes.

1. The enchantment

datapack/my_mod/enchantment/ember_edge.json:

{
  "description": { "translate": "enchantment.my_mod.ember_edge" },
  "supported_items": "#minecraft:enchantable/sword",
  "weight": 2,
  "max_level": 3,
  "min_cost": { "base": 10, "per_level_above_first": 10 },
  "max_cost": { "base": 60, "per_level_above_first": 10 },
  "anvil_cost": 4,
  "slots": ["mainhand"],
  "effects": {
    "minecraft:post_attack": [{
      "enchanted": "attacker", "affected": "victim",
      "effect": { "type": "minecraft:ignite", "duration": { "type": "minecraft:linear", "base": 3, "per_level_above_first": 2 } }
    }],
    "minecraft:damage": [{
      "requirements": { "condition": "minecraft:entity_properties", "entity": "this", "predicate": { "flags": { "is_on_fire": false } } },
      "effect": { "type": "minecraft:add", "value": { "type": "minecraft:linear", "base": 1.5, "per_level_above_first": 1.0 } }
    }]
  }
}

2. Make it appear in enchanting tables

datapack/minecraft/tags/enchantment/in_enchanting_table.json and non_treasure.json:

{ "replace": false, "values": ["my_mod:ember_edge"] }

3. The name

assets/my_mod/lang/en_us.json:

{ "enchantment.my_mod.ember_edge": "Ember Edge" }

4. What vanilla clients see

Enchantments are a data-pack registry, which the server sends to every client, so the enchantment works for vanilla clients too. Its name needs the translation: Celestial clients with the mod have it; vanilla clients show the key unless they have the mod’s resource pack.

5. Testing

/enchant @s my_mod:ember_edge 3

Hit a mob: it catches fire, and the first hit does extra damage.

Planned

Effect components from code, so an enchantment can run your own logic (my_mod:chain_lightning), and server-side translation for vanilla clients.