Performance
A mod’s steps run on the server, inside its tick, 20 times a second. Most steps and values cost next to nothing. Searches cost the most, and flows that repeat run them again and again. The Problems pane warns about the patterns below.
Searches
Block is with Within above 0, Count nearby and For each nearby search a box that reaches Within blocks out from the position on every side. Within 8 is a box 17 blocks wide. The bigger the box, the more there is to look through.
Keep Within as small as the feature allows.
Flows that repeat
Every N ticks, Every N ticks for mobs and Every N ticks for blocks run once for each player, mob or placed block, every Ticks ticks. When player steps on block and When mob steps on block run every tick for each one standing on the blocks. A function runs inside the flow that calls it, so a function these events call repeats with them.
- Keep Ticks as high as the feature allows. 20 ticks is one second.
- Give an interval that searches 10 or more Ticks. Below that, the search is flagged.
- In a step-on event, check something cheap in an If before a search.
- List the Mobs of Every N ticks for mobs. Left empty, it runs for every loaded mob and animal.
- Set For players on Every N ticks when the feature needs an item held or worn. Players without one skip the flow before any step runs.
Blocks that act on players near them
For a block such as a beacon, start the steps from Every N ticks for blocks listing the block, and act on players with For each nearby players. Then only the placed blocks search. Every N ticks with an If on Block is around each player searches around every player online, near the block or not. For blocks of this mod, it is flagged.
Cheap checks first
An If skips the steps after it while its condition is false, so a search after an If on a cheap check runs only when that check passes. Cheap checks read one thing: Is holding, Is sneaking, World is, Entity is, Random chance, Health, a Counter, or Block is with Within 0.
And works out A first and skips B when A is false. Or skips B when A is true. Wire the cheap check into A and the search or Looked-at block into B. An And or Or with the search in A is flagged.
Work a value out once
A value is worked out each time a wire reads it. A search, Looked-at block, Java code value or function value that feeds three inputs runs three times. Wire it into Keep value in the flow before those steps, and feed the inputs from Keep value. In a flow that repeats, a costly value that runs more than once is flagged.
Java code
Java code runs inside the server’s tick, so the server waits for it. Keep its loops short, search as few blocks and entities as the feature needs, and never sleep or wait in it.