Flow Control
On this page(6)
These actions do nothing visible by themselves. They decide when and how often the other actions run. They are what turns a single hit into a rain of blades or a dice roll.
delay
Waits before the next action of the list.
- type: delay
ticks: 10 # half a second| Key | Default | Range |
|---|---|---|
ticks | required | 1 to 1200 |
loop
Runs its actions several times.
- type: loop
times: 3
every: 5
actions:
- type: particle
particle: HAPPY_VILLAGER
at: '{target_pos}'
offset: '0, 0.5 + {i} * 0.5, 0' # each round half a block higher
count: 5| Key | Default | Range |
|---|---|---|
times | required | 0 to 1000, an expression read once when the loop starts |
every | 0 | Ticks between rounds, 0 to 1200 |
actions | required | The list run each round |
{i} is the round, from 0. Loops nest: the inner {i} hides the outer one while it runs.
The actions after a loop run once its last round ended. A delay inside a round also holds
the next round. To start something without waiting, use parallel.
random
Runs the actions of one entry, picked by weight.
- type: random
entries:
- weight: 3 # 3 in 4
actions:
- { type: actionbar, message: '&7Nothing extra this time' }
- weight: 1 # 1 in 4
actions:
- { type: give-currency, currency: money, amount: '{random:50:150}' }
- { type: actionbar, message: '&6Lucky! &7extra money' }| Key | Default | What it does |
|---|---|---|
entries | required | A list of { weight, actions } |
entries[].weight | 1 | A plain number above 0 |
entries[].actions | required | The list run when this entry is picked |
Entries take no chance or requirement of their own: put the guard on the random line. To
leave a chance of "nothing", add an entry with an empty effect, like the action bar above.
parallel
Runs its actions as a branch of their own, beside the main list.
- type: loop
times: 3
every: 4
actions:
- type: entity # an anvil falls for 10 ticks
display: { block: ANVIL }
at: '{target_pos}'
offset: '0, 5, 0'
lifetime: 12
movement: { type: fall, speed: 0.5 }
- type: parallel # this branch waits for the anvil...
actions:
- { type: delay, ticks: 10 }
- { type: damage, amount: '{damage} * 2' }
- { type: sound, sound: BLOCK_ANVIL_PLACE, at: '{target_pos}' }
# ...while the loop goes on to its next round at once- The branch starts in the same tick, before the actions after it.
- The actions after it do not wait for it. Its delays hold only the branch.
- It copies the variables and the flow positions (
{mob_pos},{point_pos}...) where it starts. - At most 16 branches of one proc are alive at once. One more is skipped, reported once.
- It takes no
max-sequencesslot of its own: the proc keeps its one slot until its last branch ends. It shares the player's actions per tick. - A quit, a world change and
/dungeons reloadstop the branches too.
The landing pattern. An entity never makes the list wait. When each round of a loop drops
something, put the hit in a parallel branch behind a delay as long as the flight. Every hit then
lands with its own blade while the next blades keep falling. The shipped sword-storm and
spinefall work this way.
preset
Runs a preset: a reusable action list with params.
- preset: lightning-strike
with: { damage: '{damage} * (2 + {level} / 100)', radius: 4 }| Key | Default | What it does |
|---|---|---|
preset | required | The preset id (a file of modules/sword/presets/) |
with | none | Values for its params. A missing param uses its default |
A with value can read everything the line can read ({level}, {damage}, flow positions). The
line takes chance and requirement like any action, and the guard covers the whole preset.
Choosing the right tool
| You want | Use |
|---|---|
| A pause between two steps | delay |
| The same thing N times, spaced out | loop with every |
| One of several outcomes | random |
| A hit that lands together with an effect, while the list goes on | parallel + delay |
| The same block of actions in several enchants | preset |
| One thing per mob, per jump or per point | Mob Flows |