Skip to content

Vectors

For: advanced users doing 3D math.

3D math on location primitives: distances, directions, and shifts. The one-line forms live in the cheatsheet.

Every vec. op reads its vectors from 3-element lists or 6-element location primitives (first three indices); anything else warns and yields null. The 2d variants instead take [x, z] pairs, or 6-element primitives read at indices 0 and 2, so a 3-element triple is rejected as ambiguous there. <pdir:player> is the player's unit look direction, y-up (straight up is [0, 1, 0]); offline or unknown players resolve null silently. Normalizing the zero vector yields [0, 0, 0] silently, never a warning.

Tag Meaning
<vec.add:a,b> [a0+b0, a1+b1, a2+b2].
<vec.sub:a,b> A minus B: the direction from B to A.
<vec.mult:vec,scalar> [v0*s, v1*s, v2*s]; a non-numeric scalar warns plus null.
<vec.normalize:vec> The unit vector ([0, 0, 0] for zero).
<vec.sqrdist:a,b> Squared distance.
<vec.dist:a,b> Euclidean distance.
<vec.sqrdist2d:a,b> Squared distance over X and Z.
<vec.dist2d:a,b> Euclidean distance over X and Z.
<vec.dot:a,b> Dot product scalar.
<vec.cross:a,b> Cross product vector.
<loc.shift:loc,dir,dist> Base plus direction times distance, as [x, y, z, world, pitch, yaw].
<ploc:player> Alias of <plocation:player>.
<pdir:player> Unit look direction, y-up, else null.
<raycast:point,dir,reach,mask> True when the ray hits an included layer.

<loc.shift:location,direction,distance> needs a full 6-element base and uses the direction as given, so callers normalize first when they need unit steps; world, pitch, and yaw carry over verbatim from the base. Aim from yourself at Alex, then spawn five blocks ahead of yourself:

- '<gflag:aim,<vec.normalize:<vec.sub:<ploc:Alex>,<ploc:<p>>>>>'
- '<gflag:ahead,<loc.shift:<plocation:<p>>,<pdir:<p>>,5>>'
- 'summon minecraft:armor_stand <list.get:<gflag:ahead>,0> <list.get:<gflag:ahead>,1> <list.get:<gflag:ahead>,2>'

<raycast:point,dir,reach,mask> casts from a located 6-element point [x, y, z, world, pitch, yaw] along a direction up to reach blocks (clamped to 1000): true when an included layer hits, false on a clean miss, null on misuse or an unknown world. The direction is normalized for you, so [2, 0, 0] still aims east. The mask defaults to block+player; write block, player, liquid, all, or +-joined combos like block+liquid. Blocks are occluding cubes, liquids are water and lava, players are body boxes; unloaded chunks never block. Shout when a wall is ahead:

- '<if:"<raycast:<plocation:<p>>,<pdir:<p>>,30,block> == true","<pmsg:<p>,Wall ahead!>" />'

Next Steps