diff --git a/client/rendering/animation.ts b/client/rendering/animation.ts index 5b82172..d1cc918 100644 --- a/client/rendering/animation.ts +++ b/client/rendering/animation.ts @@ -1,8 +1,11 @@ // SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later -// playing clips (see ANIMATION.md): what one does to the bones it moves at a time into it, sampled the way -// blockbench's timeline does a bedrock animation. no drawing here, so tests can use it +// playing clips (see ClipJson): what one does to the bones it moves at a time into it, sampled the way blockbench's +// timeline does a bedrock animation. what the format means comes from ports/blockbench: reading a file in +// js/formats/bedrock/bedrock_animation.js, picking and blending the keyframes around a time in +// js/animations/timeline_animators.js's interpolate(), the curves in js/animations/keyframe.js, and what that does to +// a bone in displayRotation/Position/Scale. no drawing here, so tests can use it import type { ClipJson, ClipKeyframe } from "@/common/mod_data.ts"; import { lerp } from "@/common/worldgen/noise.ts"; import type { BoneOffsets, Vec3 } from "./model_math.ts"; diff --git a/client/rendering/entity_animators.ts b/client/rendering/entity_animators.ts index d224dc2..67f7f8c 100644 --- a/client/rendering/entity_animators.ts +++ b/client/rendering/entity_animators.ts @@ -1,8 +1,9 @@ // SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later -// mods' entity animators, see ClientRender.register_entity_animator and ANIMATION.md. each entity of a type with one -// gets its own, made with the entity, which says what its model's bones do every frame it's drawn +// mods' entity animators, see ClientRender.register_entity_animator and docs/modding/entities/index.md#animators. each +// entity of a type with one gets its own, made with the entity, which says what its model's bones do every frame it's +// drawn import type { AnimatedEntity, Clip, EntityAnimator, EntityPose } from "@/common/mod_api/client.ts"; import type { ClipJson } from "@/common/mod_data.ts"; import type { EntityData } from "@/common/protocol.ts"; diff --git a/common/mod_api/client.ts b/common/mod_api/client.ts index bd95d09..5c7b66d 100644 --- a/common/mod_api/client.ts +++ b/common/mod_api/client.ts @@ -174,7 +174,7 @@ export interface ClientRender { ): void; // every entity of this type gets an animator from create while the client has it, which poses its model's bones // each frame instead of the engine's head look and humanoid swing, like a model's setupAnim. only during setup, - // and one per type. see ANIMATION.md + // and one per type. see docs/modding/entities/index.md#animations register_entity_animator(type: Id, create: (entity: AnimatedEntity) => EntityAnimator): void; // a clip, from a bedrock animation file in animations/: animation.walker.walk in animations/walker.animation.json // is my_mod:walker/walk. throws when there isn't one, so a typo shows up at setup diff --git a/common/mod_check.ts b/common/mod_check.ts index 5f5910d..ceb3015 100644 --- a/common/mod_check.ts +++ b/common/mod_check.ts @@ -68,7 +68,7 @@ export interface LoadedMod { spawns: { file: string; json: SpawnJson }[]; entities: { file: string; json: EntityJson }[]; entity_models: { file: string; json: EntityModelJson }[]; - // clips, see ANIMATION.md + // clips, see ClipJson animations: { file: string; json: ClipJson }[]; // its sounds.json, see docs/modding/resources/sounds.md sounds: { file: string; json: SoundJson }[]; diff --git a/common/mod_data.ts b/common/mod_data.ts index 51bb6d3..d5f93f7 100644 --- a/common/mod_data.ts +++ b/common/mod_data.ts @@ -595,7 +595,7 @@ const clip_channel = z.array(clip_keyframe).min(1).refine( ); // an entity model animation (one of those in animations/.animation.json) with only what the engine uses, see -// ANIMATION.md. values are as bedrock has them, mirrored on x from the engine's like models: rotation in degrees, +// docs/modding/entities/index.md#clips. values are as bedrock has them, mirrored on x from the engine's like models: rotation in degrees, // added to a bone's own, position in pixels, and scale multiplying const clip_schema = z.object({ id: z.string('must be a clip id like "my_mod:thing/walk"').regex(TAG_ID_PATTERN), diff --git a/common/mod_loader.ts b/common/mod_loader.ts index a9999fb..282ee7a 100644 --- a/common/mod_loader.ts +++ b/common/mod_loader.ts @@ -61,7 +61,7 @@ export interface ModData { spawns: SpawnJson[]; entities: EntityJson[]; entity_models: EntityModelJson[]; - // clips, see ANIMATION.md. missing from mods packed before there were any + // clips, see ClipJson. missing from mods packed before there were any animations?: ClipJson[]; // its sounds.json, see docs/modding/resources/sounds.md. the files are in the .cubi's sounds/ sounds?: SoundJson[]; diff --git a/docs/modding_plan.md b/docs/modding_plan.md index f56ed61..3478a21 100644 --- a/docs/modding_plan.md +++ b/docs/modding_plan.md @@ -68,6 +68,10 @@ plain object mods can hook. See [Engine Access](modding/misc/engine.md). The cod chestplate on other players, wide and slim, and on the first person arm with its equip and swing. - Blockbench's `mirror` isn't supported in entity models, so the giant chestplate's left sleeve has the right one's texture unflipped. +- With entity animators (see [Animations](modding/entities/index.md#animations)), switching from one state's clips to + another's is instant, where Bedrock's controllers fade over their `blend_transition`. +- Without an animator, the engine still poses bones named like a humanoid's (`head`, `right_arm`, ...). That belongs in + the mods, and moves there once mods can share code with each other. ## Planned API @@ -279,6 +283,21 @@ Worn items are drawn by `render_worn`, which puts an item's `worn` model on a pl - **Glint and glowing overlays**, as `glint` and a full bright `overlay_texture` in `worn`, once the renderer has a glint pass. +### Entity Animations + +Clips and animators are built, see [Animations](modding/entities/index.md#animations). Still to come: + +- **Events**, for one-off moments that aren't a state, like a roar. `MobRef.event(id)` sends an `entity_event` with a + mod's id, and the animator gets `on_event?(id, time)`. `EntityEvent` becomes the engine's three or an id, so + `PROTOCOL_VERSION` goes up. Nothing needs it yet. +- **Sounds**, like a Bedrock clip's `sound_effects`, once client scripts can play a sound: an animator plays one when a + state's seconds pass its time. The jester's crank, music, pop and scream are in lethal3's `jester.animation.json`. +- **An importer**, `deno task import animation`, for whole Bedrock packs. It copies each file, leaves out the channels + with Molang expressions, and lists them with a JS version for the animator: `math.cos` and `math.sin` take degrees, + `query.life_time` is `time / 20`, `query.anim_time` is the clip's seconds, `query.modified_distance_moved` is + `walk_position`, and `query.target_x_rotation` and `target_y_rotation` are `head_pitch` and `head_yaw`. It lists the + animation controllers and client entity files as left for an animator to do, with their states. + ### HUD, Keybinds and Mod Channels - `ctx.hud.register(id, { on_render(g, hud) })` draws every frame after the world, under open screens. Built, see @@ -401,8 +420,6 @@ saved before any of this plays exactly the same. waits a round trip. Components could get optional handlers that clients run to predict. - **Engine access versions.** Tying engine access mods to one minor version is simple but strict. - **Game API versions.** Only breaking with the game's major version needs deprecation warnings and a changelog. -- **Entities.** Mods can define simple animals, but there's no API for entity types with their own behavior, animations, - or natural spawning. - **Hot reload.** Restarting the server and rejoining is the answer for now. - **Biome rules or multi-noise?** Biome sources are ordered rules, which kept the old biomes exactly, but mods inserting rules can step on each other in ways that are hard to see. Minecraft's multi-noise is easier to merge but would move