Presets
On this page(6)
A preset is a list of actions with params, saved in its own file and run from any enchant with one line. Write a lightning strike, a falling blade or a reward once, then reuse it everywhere with different numbers.
# In an enchant:
- preset: lightning-strike
with: { damage: '{damage} * (2 + {level} / 100)', radius: 4 }| Folder | modules/sword/presets/ (one file per preset; the file name is the id) |
| Id rules | Lowercase letters, digits and -, at most 64 characters, .yml |
| Full reference | modules/sword/presets/example.yml (it loads like any preset) |
| Apply changes | /dungeons reload |
A preset that no enchant uses is never checked.
The preset file
A preset has two keys: params (the params and their defaults) and actions (the list it runs). The actions take every action key, chance and requirement included.
modules/sword/presets/falling-blade.yml
# item: TEXT, an item material, or sword (a copy of the player's sword).
# height: NUMBER, the blocks above the mob it starts from.
# scale: NUMBER, the size of the display.
params:
item: TRIDENT
height: 7
scale: 2
actions:
- type: entity
display: { item: '{item}', billboard: fixed }
at: '{target_pos}'
offset: '{random:-1.5:1.5}, {height}, {random:-1.5:1.5}'
scale: '{scale}'
lifetime: 12
movement: { type: fall, speed: '{height} / 10' } # always lands in 10 ticks
animation:
rotation: [ { value: '0 0 0', ticks: 0 }, { value: '0 0 -540', ticks: 10 } ]Number params and text params
The value decides the kind of a param (the with value, else the default):
| Kind | Values | How it is used |
|---|---|---|
| NUMBER | A math expression: 100, 2.5, '{damage} * 2', '{random:1:5}' | Read again each time the preset uses it (a {random:a:b} rolls again each time). Works in expressions, and in texts as {name} and {name_formatted} |
| TEXT | Anything else: money, FLAME, '#FF0000', '{target_pos}', '&6Bonus', 30s | Pasted as written wherever the preset writes {name}: a particle or sound name, a currency id, a position, a color, a text, a material, a time, even an action type or the with values of a preset it calls. Never in a key, and not in the values listed below |
The plain-number keys (size, weight, fade-in, stay, fade-out, animation values) cannot take a preset param. Write the plain number in the preset itself.
A few values are read as written and never take a param. They are play-animation.animation,
proc-enchants mode and enchants, add-booster.max-multiplier, an item map's amount and
custom-model-data, and every model:. Write them plainly in the preset.
Each param value is a single value, never a list or a section. A with key that is not a param of
the preset is ignored, with a warning.
Scope
- A preset reads the variables (
{level},{max_level},{damage},{i},{random:a:b},{player},{enchant},{enchant_id}) and its own params only. - It never reads the params of the preset that called it. To pass one through, forward it:
with: { amount: '{amount}' }. - A default reads the variables only, never another param of the same preset.
- A with value reads everything the calling line can read.
- A param hides the variable of the same name inside the preset. In
lightning-strike, the paramdamagedefaults to'{damage}'(the swing), and the caller can replace it. - Flow positions pass into a preset: inside a
for-each-mob, the preset's{mob_pos}is that mob.
Nesting
# A preset that calls another preset, forwarding a text and a number param.
actions:
- preset: currency-reward
with: { currency: '{currency}', amount: '{amount}' }
requirement: '{amount} > 0'- Presets call presets up to 8 deep.
- A preset that ends up calling itself (
a -> b -> a) is skipped, with a warning. - Loops, randoms and presets nest up to 32 deep.
- One enchant runs at most 10000 actions, presets expanded.
The shipped presets
| Preset | What it does | Params (default) |
|---|---|---|
lightning-strike | A lightning, area damage, a spark ring, thunder | damage ('{damage}'), radius (3). Hits at most 5 mobs |
area-burst | A particle sphere, damage to every mob in the radius, a sound | radius (5), amount ('{damage}'), particle (FLAME), sound (ENTITY_GENERIC_EXPLODE) |
currency-reward | Pays a currency and shows it in the action bar | currency (money), amount (100) |
falling-blade | An item display that falls turning onto the mob, landing in 10 ticks | item (TRIDENT, or sword), height (7), scale (2) |
dice-roll | A title animation of a die rolling | face ('floor({random:1:7})'), color ('&7') |
dice-face | A die face title, a timed booster and a sound | face (1), target (money), percent (25), time (30s), label ('&aMoney') |
example | Shows every param kind and a nested preset | see the file |
falling-blade only shows the blade. The enchant that uses it hits 10 ticks later, in a
parallel branch, so each hit lands with its blade:
- type: loop
times: 12
every: 2
actions:
- preset: falling-blade
with: { item: sword, height: 8, scale: 1.5 }
- type: parallel
actions:
- { type: delay, ticks: 10 }
- { type: damage, amount: '{damage} * 15' }Write your own
- Create
modules/sword/presets/<id>.ymlwithparams:andactions:. - Write
{param}wherever a value should change between uses. - Give every param a sensible default, so a bare
- preset: <id>line works. - Document each param in a comment: its kind (NUMBER or TEXT) and what it is.
- Call it from an enchant, then
/dungeons reloadand test.
A preset is the right tool to show a computed number in a text. Pass
with: { shown: '{damage} * 3' } and write {shown_formatted} in the preset's message.