Skip to main content

Enchantment Mechanic

Type: EnchantmentMechanic (data class) Mechanics define modular behaviors attached to custom_enchantment_definition. Each mechanic listens for a specific game event and executes actions when criteria are met.

Fields

FieldTypeDefaultDescription
eventEnchantmentEventPLAYER_ATTACKGame event that triggers this mechanic
criteriaList<Criteria>[]Conditions that must be met for the actions to execute
actionsList<Ref<TriggerableEntry>>[]Actions executed when criteria are met
clientSideEffectsList<Ref<TriggerableEntry>>[]Client-side only effects (particles, sounds) via packets
runOnLevelInt0Enchantment level required to run this mechanic. 0 means all levels
chanceInt100Chance to trigger this mechanic (0-100%)

Available Events

See Enchantment Events for the full list of supported game events.

Example

{
  "id": "custom_fire_sword",
  "name": "Inferno Blade",
  "displayName": "<red>Inferno Blade",
  "supportedItems": ["DIAMOND_SWORD", "NETHERITE_SWORD"],
  "maxLevel": 3,
  "mechanics": [
    {
      "event": "PLAYER_ATTACK",
      "criteria": [],
      "actions": ["enchantment_creator:lifesteal_action"],
      "runOnLevel": 0,
      "chance": 100
    },
    {
      "event": "BLOCK_BREAK",
      "criteria": [],
      "actions": ["enchantment_creator:haste_action"],
      "runOnLevel": 2,
      "chance": 50
    }
  ]
}
This example creates an enchantment that heals on attack at all levels, and has a 50% chance to activate haste when mining at level 2+.