Skip to content

Movement actions

Walk, pathfind, look, follow, ride, fight, run away and pick things up.

Sixteen actions that move the client or change what it is doing with its body.

Two of them pathfind, goto and goto_block. Reaching the destination fires goal_reached, and a path that cannot be found fires goto_failed. That is how you write "walk there, then act". The step itself also fails when the client does not arrive, so try and last_action_failed see it.

Every action that walks (goto, goto_block, follow, attack with chase, flee, collect_items and sleep) walks like a careful player. It never breaks a block, never places one to climb or bridge, and drops at most 3 blocks. Doors, trapdoors and fence gates count as walls: the client walks round them, and if one is the only way through, the path fails. Open it first with use_block.

move

Holds a direction for a fixed time. Dumb movement: no pathfinding, no obstacle avoidance.

FieldTypeRequiredNotes
directionforward | back | left | rightyesRelative to where the client faces.
msinteger, 1–60000yesHow long to hold it.
move forward for 1.5 seconds

For getting somewhere specific use goto; this is for short nudges.

jump

Jumps once.

No fields.

jump

look

Points the client in an absolute direction.

The editor's palette no longer offers this block: flows that already use it keep working, and look at covers the same need with coordinates.

FieldTypeRequiredNotes
yawnumber, −360…360yesHorizontal angle in degrees, as the F3 screen shows it: 0 faces south, 90 west, 180 north, −90 east.
pitchnumber, −90…90yesVertical angle in degrees, as F3 shows it: −90 is straight up, 0 level, 90 straight down.
look yaw 180 pitch 0

That faces north, looking level. Stand where you want the client to look, press F3 and copy the two numbers after "Facing"; the client turns the same way.

look_at

Turns to face a world coordinate. Easier than working out angles yourself.

FieldTypeRequiredNotes
xintegeryesWorld X.
yinteger, −2048…2048yesWorld Y.
zintegeryesWorld Z.
look at x 120 y 64 z -30

goto

Pathfinds to a position or to a player, then stops.

FieldTypeRequiredNotes
modecoords | playernoDefault coords.
x, y, zintegersfor coordsThe destination.
relbooleannoRead x/y/z as an offset from the client instead of world coordinates.
playerplayer namefor playerWalks to where that player currently stands.
timeoutMsinteger, 1000–600000noDefault 60000. Fail the step if the client has not arrived after this long. The editor takes a number plus a unit.
go to at coords x 100 y 64 z 100 player

mode: player walks once to where they stood. To keep up as they move, use follow.

The step fails, and the console says why, when:

  • there is no path to the destination,
  • the client is stuck: 5 seconds without moving at all, or 30 seconds without getting half a block closer,
  • timeoutMs runs out first,
  • something else stops it on the way, such as stop_moving.

goto_block

Pathfinds to the nearest block of a given kind and stops next to it. goto needs coordinates; a farm loop rarely knows them.

FieldTypeRequiredNotes
blockstring, 1–64 charsyesRegistry name, e.g. chest.
radiusinteger, 1–64noDefault 16. How far to search.
go to nearest chest within 32 blocks

Fails when there is no such block within radius, and in the same cases as goto, with a limit of 60 seconds.

follow

Keeps walking to a player, re-pathing as they move.

FieldTypeRequiredNotes
onbooleannoDefault true. false drops the follow goal.
playerplayer nameto startWho to follow.
distanceinteger, 1–16noDefault 3. How close to stay.
follow on player Alice at 3 blocks

Following continues in the background after the block finishes. To stop it, use another follow block with its first field set to off:

follow off player at blocks

or stop moving, which also clears everything else.

stop_moving

Cancels any path in flight and releases every control state.

No fields.

stop moving

The only way to interrupt a running goto or follow, or to clear a sneak or sprint that got stuck on.

A running goal is paused, not ended: it resumes after the next movement or goal step. To end it, use cancel_goal.

mount

Rides a vehicle: boat, minecart, horse, strider.

FieldTypeRequiredNotes
modenearest | namednoDefault nearest.
targetentity namefor namedThe entity's name.
radiusinteger, 1–32noDefault 8. Search radius for nearest.
ride nearest entity within 8 blocks

Fails when there is nothing to ride within radius, or when the server has not seated the client a second later. A pig or a horse needs a saddle, and a horse has to be tamed.

dismount

Leaves the current vehicle by sneaking, like a player does.

No fields.

get off the vehicle

Fails when the client is still riding a second later. With nothing to ride it does nothing.

attack

Hits something. One swing by default, or walks to the target and fights until it is dead.

FieldTypeRequiredNotes
modenearest | named | hostile | attacker | mobnoDefault nearest. hostile is the nearest hostile mob; neutral mobs such as endermen, piglins and zombified piglins are left alone. attacker is whatever hit the client in the last 10 seconds, mob or player, if it is within radius. mob is the nearest living mob of any kind, hostile, neutral or passive.
targetentity namefor namedA player or mob name.
excludearray of entity names, max 16noNever target these, for example villager and iron_golem.
chasebooleannoDefault off. Walk to the target and keep fighting it until it is dead or gone.
radiusinteger, 1–32noDefault 16. Only pick a target this close. With chase, give up when it gets further than 1.5 times this, or when the client is more than 32 blocks from where the chase started.
timeoutMsinteger, 1000–120000noDefault 30000. chase only: fail the step if the client has not landed a hit for this long. Every hit starts the count again, so a long fight that keeps landing hits goes on. The editor takes a number plus a unit.
spreadbooleannoDefault off. chase only: share the targets out across the group instead of all going for the nearest one.
attack nearest hostile mob
attack nearest mob

Every swing, with or without chase, is one a player could land. Only living things are ever targeted, never a dropped item, an arrow or an armour stand. The client turns its head at a human pace and swings only when it faces the target (within 15 degrees), the target is within 3 blocks and nothing solid is between its eyes and the target. Swings follow the pace of the weapon in its hand, a little under a second for an axe and about two thirds of a second for a sword or an empty hand, with a small random wobble so ten clients do not swing in step. A plain attack asked for before the weapon is ready waits for it, up to a second, instead of swinging early. Out of reach or out of sight it does nothing for that swing. That is not a failure, so a plain attack aimed at something too far away is quietly skipped. Plain attack is one swing per action; for sustained combat without chase, put it in a repeat or a while.

With chase the client picks one target when the step starts and fights it like a player:

  • It walks after the target (sprinting when it can) until it is within swing reach, then stands and fights.
  • When something else hits it, or a hostile mob gets within 2.5 blocks, while the target is out of reach, it turns and fights that mob first. Once that mob is more than 6 blocks away, it goes back to the target. When it kills that mob and the mob fits the chase (any hostile mob for hostile), the chase ends there as a kill, so every kill is counted once.
  • With two or more hostile mobs within 3 blocks, it steps 2 blocks away from them after each hit, so the knockback keeps them off, then goes back in.
  • Against heavy mobs that shrug off knockback (ravager, warden, iron golem, hoglin, zoglin, piglin brute, elder guardian) it hits and runs: it goes in only when its weapon is ready, swings once and sprints back to 8 blocks, going in again once the weapon is ready and the mob is 8 blocks off, within reach, or 2.5 seconds have passed. Below half health it stops fighting a heavy mob and backs away until it is 12 blocks clear; the step then fails with "backed away from ravager with health below half". Players are never fought this way.
  • It backs off from a creeper whose fuse is lit and goes back in once the fuse is out.
  • It stays within 32 blocks of where the chase started. A mob that hits and runs cannot drag the client, or a whole group, across the map: past 32 blocks the chase gives up as lost.

A chase only picks living things, and mob also skips tamed animals and anything with a custom name, because that is someone's pet.

With spread, each client picks the nearest target that is not already covered. A mob with up to 20 health needs one fighter, and every further 20 health asks for one more, up to four: an iron golem gets four clients, a zombie gets one. Clients that CubeMind runs side by side share a list of who is chasing what, so they never pick the same zombie, even when they start from the same spot. Any other player, which can include one of your clients that CubeMind runs elsewhere, covers a target when it is closer to it than this client is. If every target is covered, the client goes for the nearest one anyway. A stranger standing next to a zombie makes your clients leave it to them.

Fighting in a group, list your other clients in exclude. A sword's sweep can hit a client standing next to the target, and with attacker the client that was hit would otherwise turn on the one that hit it.

A chase succeeds only on a kill. When several of your clients that CubeMind runs side by side fight one mob, the kill goes to the client that landed the last hit before it died, and to no other. Otherwise the kill counts when this client hit the target in the last 5 seconds before it died. When someone else lands the killing blow, or the sun or lava finishes it, the step fails quietly, without a warning in the console. The target despawning, getting too far away, the client getting more than 32 blocks from where it started or timeoutMs passing without a hit also fail the step, and so does having no target at all when it starts. That makes a kill counter a two-block job: right after the chase, check last_action_failed and add inc_var only when it is not set. Inside a try a failed chase also stops the body, so a step after it in the body runs only after a kill.

attack nearest hostile mob · chase on within 16 blocks
if test not last action failed
add 1 to variable kills
else
wait 250 milliseconds

A chase is a mover: only one of attack with chase, flee, collect_items and sleep (while it walks to the bed) runs per client at a time. Starting one ends the older one, which finishes as done, not failed, and the newest wins. A second chase on the target the client is already chasing does not restart anything; it waits for the running chase and reports the same result. stop_moving also ends a running mover, and fails a running chase, since it did not kill.

Known limits:

  • Before game version 1.20 the server does not say who hurt the client. attacker falls back to the nearest mob or player within 5 blocks at that moment, and arrows from a skeleton stay unknown on those versions, so attacker finds nothing for them.
  • This is melee only. No bows, shield blocking, critical-hit jumps or strafing.

flee

Runs away from danger until it is far enough.

FieldTypeRequiredNotes
modehostile | attackernoDefault hostile: the nearest hostile mob. attacker runs from whatever hit the client last.
distanceinteger, 4–32noDefault 12. Done once the threat is at least this far away.
timeoutMsinteger, 1000–60000noDefault 15000. Fail the step if the client is still not clear after this long.
strikeBackbooleannoDefault on. While running, swing at a hostile mob within reach whenever the weapon is ready, then keep running. Turn it off for a pure retreat.
run from nearest hostile mob until 16 blocks away

The client pathfinds away, sprinting when it can (the game stops sprinting at 6 food or less, so it just runs slower then), and checks again for the nearest threat as it goes, so a second mob in the way is accounted for. With strikeBack on, a hostile mob that is already within reach and in front, or any hostile mob within 2.5 blocks even behind the client, gets a swing first: the client stops for at most half a second to turn and hit it, with the same face, reach and sight rules as attack, then runs on. A swing that does not land waits 2 seconds before the next try. That way it does not turn its back on a mob as fast as it is. With nothing to run from, the step is done at once and counts as a success.

flee is a mover; see attack for the one-mover rule. If a trigger can start both a flee and a chase, set a variable first and check it in the fight loop, then call stop_moving. The fight loop reference flow below does exactly that, and the order matters.

collect_items

Walks over dropped items to pick them up.

FieldTypeRequiredNotes
radiusinteger, 1–16noDefault 8. Pick up dropped items this close.
itemstring, 1–64 charsnoOnly this item. Leave out for anything.
matchByname | display_name | lorenoDefault name.
timeoutMsinteger, 1000–60000noDefault 15000. Stop after this long.
pick up dropped items within 6 blocks

Goes to the nearest item first, then the next, until none are left or the time is up. Both count as success. It fails when the inventory is full while items are still lying there, when an item it walked onto was never picked up three times in a row, which usually means it cannot be reached, or when the client gets stuck on the way, as in goto. It is a mover.

sneak

Holds or releases sneak.

FieldTypeRequiredNotes
onbooleanyestrue holds it down, false releases.
sneak on

It stays held until something turns it off: this action with on: false, or stop_moving.

sprint

Holds or releases sprint.

FieldTypeRequiredNotes
onbooleanyestrue holds it down, false releases.
sprint on

activate_item

Uses the held item (right-click, in effect). Eating, drinking, throwing, activating.

No fields.

use held item

Example: a fight loop

A client that fights mobs like a player: hits back at whatever hit it first, otherwise takes the nearest mob, counts kills, picks up drops and wears better gear, and runs away to heal when its health gets low, eating back up so it heals. It is built from the blocks above, not one built-in fight block.

on join
set variable state to fight
set variable kills to 0
equip best weapon and armour
on hostile mob within 20 blocks
while test hostile mob near 20 (max 1000x)
if test variable equals text fight — variable state
try
try
attack whoever hit me · chase on within 16 blocks
else on failure
if test variable equals text fight — variable state
attack nearest mob · chase on within 20 blocks · never attack villager, iron_golem
if all of
test variable equals text fight — variable state
test not last action failed
then
add 1 to variable kills
pick up dropped items within 6 blocks
else on failure
wait 250 milliseconds
else
wait 500 milliseconds
on item picked up
equip best weapon and armour
on damage taken
if all of
test variable equals text fight — variable state
test not hostile mob near 20
then
attack whoever hit me · chase on within 16 blocks
on health below 8
set variable state to flee
stop moving
run from nearest hostile mob until 16 blocks away
if test health below 10
use healing potion
while test not food above 17 (max 10x)
eat by name
if test last action failed
break out of loop
wait until test health above 13 give up after 20 seconds
set variable state to fight
on food below 10
if test variable equals text fight — variable state
eat by name

Five things make it work.

  • set state comes before stop_moving. The fight loop checks state at the top of each pass. Stop first and it can start a new chase in the gap before the flag changes.
  • Every step after the first chase checks state again. stop_moving ends the chase as a failure, so the loop lands in else on failure while the client is already running away. An unchecked fallback chase or pick-up would start a new move and cancel the run away, since the newest move wins. Checked, the pass ends quietly and the loop waits until state is fight again.
  • Count only after a clean chase. A chase only succeeds on a kill. When the fallback chase fails too, the inner try fails, which stops the outer body before the count and the pick-up, and the outer try waits and picks the next target. The not last action failed test keeps the count honest if you take the inner try out.
  • Heal by eating, and keep the potion for real danger. Health only comes back by itself while food is 18 or more, so after running away the client eats until food above 17 and then waits for its health. The healing potion is drunk only below half health (10); above that, food is enough. Without food the loop stops at the first failed eat instead of trying ten times.
  • The damage trigger hits back when no mob is around, which is how a player attacker gets answered. Mobs are handled by the fight loop.
Movement actions · CubeMind docs