Hitting !!

This commit is contained in:
2026-09-30 15:41:30 -03:00
parent 3af5f6e54b
commit 5e2b415f5c
9 changed files with 82 additions and 7 deletions
+10
View File
@@ -60,6 +60,9 @@ export class LocalPlayer extends Player {
health = 20;
food = 20;
saturation = 5;
// the attack speed attribute the server sent, and when they last attacked or switched slots, for the indicator
attack_speed = 4;
last_attack = -Infinity;
// blocks per second, peaks about 1.25 blocks up with the entity's gravity and drag
jump_force = 9.23;
@@ -81,6 +84,13 @@ export class LocalPlayer extends Player {
this.client = client;
}
// like the server's ServerPlayer.attack_strength, from real time so the indicator fills smoothly: 0 right after
// attacking, 1 after 20 / attack_speed ticks
attack_strength(): number {
const ticks = (performance.now() - this.last_attack) / 50;
return Math.min(1, Math.max(0, (ticks + 0.5) / (20 / this.attack_speed)));
}
tick() {
this.#apply_input(this.client.screen ? NO_INPUT : this.#read_input());
this.#prev_eye_height = this.eye_height;