Undergarden mod !

This commit is contained in:
2026-09-30 17:30:14 -03:00
parent cbc9edfd60
commit 0052faa24d
21 changed files with 545 additions and 46 deletions
+16 -2
View File
@@ -1,4 +1,4 @@
import type { EntityData, EntityInfo } from "$/common/protocol.ts";
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 type { ClientLevel } from "../level/client_level.ts";
@@ -9,6 +9,8 @@ const LERP_TICKS = 3;
// how long it flashes red after being hurt, and falls over after dying, like minecraft
const HURT_TICKS = 10;
const DEATH_TICKS = 20;
// how long its attack swing takes, like minecraft's mobs
const SWING_TICKS = 6;
// an entity the server simulates, like a mob. this only follows where it's told it is and keeps what it was told
// it looks like, for drawing it
@@ -24,6 +26,8 @@ export class RemoteEntity extends Entity {
dead = false;
// what's riding it, by id
passengers: string[] = [];
// ticks into its attack swing, undefined when it isn't swinging
swing_ticks: number | undefined;
#target = { x: 0, y: 0, z: 0, yaw: 0, pitch: 0, head_yaw: 0 };
#lerp_ticks = 0;
@@ -46,9 +50,12 @@ export class RemoteEntity extends Entity {
this.#lerp_ticks = LERP_TICKS;
}
on_event(event: "hurt" | "death") {
on_event(event: EntityEvent) {
if (event === "hurt") {
this.hurt_time = HURT_TICKS;
} else if (event === "swing") {
// swinging again halfway through doesn't restart it, like minecraft
if (this.swing_ticks === undefined || this.swing_ticks >= SWING_TICKS / 2) this.swing_ticks = 0;
} else {
this.dead = true;
}
@@ -69,6 +76,13 @@ export class RemoteEntity extends Entity {
this.head_yaw += wrap_angle(target.head_yaw - this.head_yaw) * t;
this.#lerp_ticks -= 1;
}
this.update_walk_animation();
if (this.swing_ticks !== undefined && ++this.swing_ticks >= SWING_TICKS) this.swing_ticks = undefined;
}
// how far through its attack swing it is, 0 to 1, like minecraft's attackTime. 0 when it isn't swinging
attack_animation(partial_tick: number) {
return this.swing_ticks === undefined ? 0 : Math.min(1, (this.swing_ticks + partial_tick) / SWING_TICKS);
}
}