Animators and coilhead animations

This commit is contained in:
2026-11-21 21:54:02 -03:00
parent 69ad4b80d0
commit 0c711b8163
21 changed files with 960 additions and 34 deletions
+14 -1
View File
@@ -5,6 +5,7 @@ import type { EntityData, EntityEvent, EntityInfo } from "@/common/protocol.ts";
import type { EntityJson } from "@/common/mod_data.ts";
import { EverythingRegistry } from "@/common/everything_registry.ts";
import { wrap_angle } from "@/common/utils.ts";
import { animation_for, type EntityAnimation } from "../rendering/entity_animators.ts";
import type { ClientLevel } from "../level/client_level.ts";
import { Entity } from "./entity.ts";
@@ -21,8 +22,12 @@ const SWING_TICKS = 6;
export class RemoteEntity extends Entity {
// the entity type, like "cubi:item"
readonly type: string;
// synced data, see EntityData
// synced data, see EntityData. set_data changes it
data: EntityData;
// ticks since this client got it
age = 0;
// its type's animator from a mod, see ClientRender.register_entity_animator
readonly animation: EntityAnimation | undefined;
head_yaw: number;
// counting down after a hurt event, and up after a death one
hurt_time = 0;
@@ -47,6 +52,13 @@ export class RemoteEntity extends Entity {
this.pitch = info.pitch;
this.head_yaw = info.head_yaw ?? info.yaw;
this.#target = { x: info.x, y: info.y, z: info.z, yaw: info.yaw, pitch: info.pitch, head_yaw: this.head_yaw };
this.animation = animation_for(this);
}
set_data(data: EntityData) {
const before = this.data;
this.data = data;
this.animation?.data_changed(before);
}
lerp_to(x: number, y: number, z: number, yaw: number, pitch: number, head_yaw = yaw) {
@@ -66,6 +78,7 @@ export class RemoteEntity extends Entity {
}
tick() {
this.age += 1;
if (this.hurt_time > 0) this.hurt_time -= 1;
if (this.dead) this.death_time = Math.min(DEATH_TICKS, this.death_time + 1);