Appearance
Rotations
Display entities store orientation as a quaternion [x, y, z, w]; helix builds them at compile time so you never write one by hand.
ts
import { quatFromTo } from "helix";
const flat = quatFromTo([0, -1, 0], [0, 0, 1]); // point-down -> point forward| Function | Use it when |
|---|---|
quatFromTo(from, to) | you know where it points and where it should point |
quat(axis, degrees) | you want a turn about "x", "y" or "z" |
mulQuat(a, b) | you need two turns at once (b happens first) |
rotateVec(v, q) | you want to check a pose by rotating a direction |
rotateAboutPivot(offset, pivot, q) | you're turning one part of a multi-part model |
[0, 0, 0, 1] is no rotation. Directions are model space: +X east, +Y up, +Z forward at yaw 0; they don't need to be unit length.
Combine two turns
ts
import { mulQuat, quat, rotateVec } from "helix";
const pose = mulQuat(quat("z", 90), quat("x", 180)); // flip, then quarter turn
rotateVec([0, 1, 0], pose); // [1, 0, 0]WARNING
mulQuat(a, b) applies b first, the opposite of reading order.
Pose a display
rightRotation fixes how the model is built; leftRotation is the pose in the world and is the one animations drive.
ts
import { Datapack, v26_2, Display, Item, quat, quatFromTo, mulQuat } from "helix";
const dp = new Datapack("blade", v26_2);
dp.createFunction("summon").build((ctx) => {
Display.item(
Item.DIAMOND_SWORD,
{
rightRotation: mulQuat(quat("z", -45), quat("x", 180)),
leftRotation: quatFromTo([0, -1, 0], [0, 0, 1]),
scale: [1.4, 1.4, 1.4],
},
"none",
)
.brightness(15)
.summon(ctx);
});Compiled output - the real files helix emits for the code above:
txt
summon minecraft:item_display ~ ~ ~ {item:{id:"minecraft:diamond_sword",count:1},item_display:"none",transformation:{left_rotation:[-0.7071067811865475f,0.0f,0.0f,0.7071067811865475f],right_rotation:[0.9238795325112867f,-0.3826834323650898f,-2.3432602026631493e-17f,5.657130561438501e-17f],scale:[1.4f,1.4f,1.4f],translation:[0.0f,0.0f,0.0f]},brightness:{block:15,sky:15}}txt
{
"pack": {
"description": "blade\nCreated using Helix",
"min_format": [
107,
1
],
"max_format": [
107,
1
]
}
}TIP
Use the "none" display context. head and thirdperson add their own rotation.
Turn one part of a group
Displays don't inherit transforms. Move the part with rotateAboutPivot(offset, pivot, q) and turn it with mulQuat(q, itsLeftRotation); doing only one makes it slide or spin in place. twine's Gesture does both.
Gotchas
- Turning about the axis the model lies along does nothing visible.
quat("y", 405)equalsquat("y", 45). Spin with a sequence of poses, each under 360 deg.- Minecraft interpolates the shortest way. If a step snaps backwards, add a pose between.