HyperScript
Docs

← All of the Docs Items

Enchantments of your own

structureenchantment <name>:since 1.7.17

At the left margin. One to four plain words, not the name of one of the game's enchantments

enchantment lifesteal:
    max level: 3
    on hit:
        add {_level} to health of player
Try it
expressionmax level: <n>since 1.7.17

The highest level that counts, 5 unless you say otherwise; an item with more acts as if it had this many

enchantment thorns of fire:
    max level: 2
    on hurt:
        ignite attacker for 3 seconds
Try it
eventon hit:since 1.7.17

Runs when a player hits something with the item in their main hand. victim, damage and the rest are there as in on hit:

enchantment lightning:
    on hit:
        if chance of 20%:
            strike lightning at victim
Try it

What this event gives a script

PlaceholderShort formTypeMeaning
%event.attacker%attackertextWho dealt the damage: a player's name or a mob type such as zombie. For an arrow or other projectile this is whoever shot it. Unset for damage with no attacker, such as falling
%event.victim%victimtextWho was hurt: a player's name or a mob type
%event.damage%damagenumberDamage actually taken, after armour and effects; 2 is one heart
%event.cause%causetextWhy: FALL, FIRE, ENTITY_ATTACK, PROJECTILE, DROWNING, VOID and so on
%event.entity%entitytextThe victim's entity type, e.g. player or zombie
%event.location%locationWhere the victim is
x of event's locationnumberThe x of %event.location%, as a number
y of event's locationnumberThe y of %event.location%, as a number: how high it is
z of event's locationnumberThe z of %event.location%, as a number
  • Can be cancelled: Yes
  • player is: The victim if a player was hurt; otherwise the attacker if a player dealt the damage; otherwise nobody

More about on entity damage:, with a box to try it in

eventon hurt:since 1.7.17

Runs when a player is hurt by someone while wearing the item, or holding it in either hand

enchantment dodge:
    on hurt:
        if chance of 10%:
            cancel event
            send "&7Dodged!"
Try it
eventon block break:

Runs when a player breaks a block with the item in their main hand

enchantment prospector:
    on block break:
        if event.block is "stone":
            if chance of 5%:
                give player 1 gold nugget
Try it

What this event gives a script

PlaceholderShort formTypeMeaning
%player%playerplayerThe player the event is about; use it wherever a player is expected
%event.block%blocktextThe block type, e.g. diamond_ore
%event.location%locationWhere the block is
%event.drops%listThe items the block will drop with the tool in the player's hand
x of event's locationnumberThe x of %event.location%, as a number
y of event's locationnumberThe y of %event.location%, as a number: how high it is
z of event's locationnumberThe z of %event.location%, as a number
  • Can be cancelled: Yes
  • player is: The player breaking the block

More about on block break:, with a box to try it in

Guide and examples

A script can make up an enchantment: a name, and what happens when an item that carries it is used.

enchantment lifesteal:
    max level: 3
    on hit:
        add {_level} to health of player

command /vampire:
    trigger:
        give player 1 iron sword enchanted with lifesteal 2
LineMeaning
enchantment <name>:At the left margin. One to four plain words, not the name of one of the game's enchantments
max level: <n>The highest level that counts, 5 unless you say otherwise; an item with more acts as if it had this many
on hit:Runs when a player hits something with the item in their main hand. victim, damage and the rest are there as in on hit:
on hurt:Runs when a player is hurt by someone while wearing the item, or holding it in either hand
on block break:Runs when a player breaks a block with the item in their main hand
  • Inside those blocks {_level} is the level on the item, and player is whoever holds it.
  • An item gets it the way it gets any other: enchanted with lifesteal 2, alone or among the game's own (enchanted with sharpness 5, lifesteal 1), in give, in an item <name>:, or with enchant tool of player with .... Any script can use an enchantment another file defines.
  • The game does not know these enchantments. An item shows one as a grey line at the top of its description (Lifesteal II) and has no enchantment shimmer because of it; add glowing for that. They cannot be had from an enchanting table or combined on an anvil.