This commit is contained in:
2026-10-22 19:55:59 -03:00
parent 1b30d71a47
commit 4cd29a17b3
37 changed files with 427 additions and 155 deletions
+7 -2
View File
@@ -25,7 +25,7 @@ import { back_to_title } from "./gui/title_screen.ts";
import { TICK_DELTA } from "$/common/constants.ts";
import { Container } from "$/common/inventory.ts";
import { PLAYER_MENU } from "$/common/protocol.ts";
import { EverythingRegistry } from "$/common/everything_registry.ts";
import { type BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import type { EntityJson } from "$/common/mod_data.ts";
import { tick_texture_animations } from "./texture_animations.ts";
@@ -365,7 +365,12 @@ export class Client {
const previous = inventories.hotbar_selected;
const scroll = InputManager.get_wheel_delta();
if (scroll > 0) {
// at a block that takes the mouse wheel, like a pulse repeater's delay, it goes to the block instead
const hit = this.hit_result;
if (scroll !== 0 && hit && EverythingRegistry.get_by_id<BlockRegistry>("blocks", hit.block)?.scrollable) {
const { x, y, z, face } = hit;
this.connection.send({ type: "scroll_block", x, y, z, face, hit: hit.hit, amount: scroll < 0 ? 1 : -1 });
} else if (scroll > 0) {
inventories.hotbar_selected = Math.min(8, inventories.hotbar_selected + 1);
} else if (scroll < 0) {
inventories.hotbar_selected = Math.max(0, inventories.hotbar_selected - 1);
+30 -6
View File
@@ -33,6 +33,10 @@ const AIR_ROW_SPACING = 10;
const HELD_NAME_MS = 2000;
const HELD_NAME_FADE_MS = 500;
const HELD_NAME_GAP = 12;
// a server's overlay message, see MessageOptions.overlay: above the held item's name, for as long as minecraft's
const OVERLAY_MS = 3000;
const OVERLAY_FADE_MS = 500;
const OVERLAY_GAP = 4;
const CROSSHAIR_SIZE = 15;
// under the crosshair so it shows on bright sky and snow, minecraft inverts the colors behind it instead
const CROSSHAIR_SHADOW: [number, number, number, number] = [0, 0, 0, 0.4];
@@ -53,12 +57,21 @@ export class Hud {
// what was held last frame, as slot and item id, and when the held item last changed
#held = "";
#held_since = -Infinity;
#overlay = "";
#overlay_since = -Infinity;
// shows text above the hotbar for a moment, see MessageOptions.overlay
show_overlay(text: string) {
this.#overlay = text;
this.#overlay_since = performance.now();
}
render(client: Client) {
this.#render_hotbar(client.player.inventories);
this.#render_vitals(client);
const top = Math.min(icons_y() - heart_rows_height(client.player.max_health), air_y(client.player));
this.#render_held_name(client.player.inventories, top);
this.#render_overlay(top);
this.#render_crosshair(client);
this.#render_info(client);
client.chat.render(false, top - HELD_NAME_GAP);
@@ -97,12 +110,16 @@ export class Hud {
return;
}
const alpha = Math.min(1, (HELD_NAME_MS - shown_for) / HELD_NAME_FADE_MS);
const name = display_name(item.type_id);
const x = (canvas.width - measure_text(name, TEXT_SCALE)) / 2;
const y = top - HELD_NAME_GAP - TEXT_HEIGHT * TEXT_SCALE;
// a shadow so it reads over bright sky and snow
draw_text(name, x + TEXT_SCALE, y + TEXT_SCALE, TEXT_SCALE, [0.15, 0.15, 0.15, alpha]);
draw_text(name, x, y, TEXT_SCALE, [1, 1, 1, alpha]);
draw_centered(display_name(item.type_id), top - HELD_NAME_GAP - TEXT_HEIGHT * TEXT_SCALE, alpha);
}
// top is the top of the hearts, like for the held item's name, which it goes above
#render_overlay(top: number) {
const shown_for = performance.now() - this.#overlay_since;
if (shown_for > OVERLAY_MS) return;
const alpha = Math.min(1, (OVERLAY_MS - shown_for) / OVERLAY_FADE_MS);
const y = top - HELD_NAME_GAP - OVERLAY_GAP * GUI_SCALE - TEXT_HEIGHT * TEXT_SCALE * 2;
draw_centered(this.#overlay, y, alpha);
}
// hearts on the left and hunger on the right like minecraft, each icon 2 points. saturation is appleskin's outline
@@ -193,6 +210,13 @@ export class Hud {
}
}
// text across the middle of the screen at y, with a shadow so it reads over bright sky and snow
function draw_centered(text: string, y: number, alpha: number) {
const x = (canvas.width - measure_text(text, TEXT_SCALE)) / 2;
draw_text(text, x + TEXT_SCALE, y + TEXT_SCALE, TEXT_SCALE, [0.15, 0.15, 0.15, alpha]);
draw_text(text, x, y, TEXT_SCALE, [1, 1, 1, alpha]);
}
function hotbar_position() {
return {
x: Math.round((canvas.width - HOTBAR_WIDTH * GUI_SCALE) / 2),
+2 -1
View File
@@ -223,7 +223,8 @@ export class ClientPacketListener {
level.set_center(message.x, message.z);
break;
case "chat":
client.chat.add(message.from ? `<${message.from}> ${message.text}` : message.text);
if (message.overlay) client.game_renderer.hud.show_overlay(message.text);
else client.chat.add(message.from ? `<${message.from}> ${message.text}` : message.text);
break;
case "suggestions":
if (client.screen instanceof GuiChat) {