From d859c6066c1ebfe0fb92700a9a998a840dd4c491 Mon Sep 17 00:00:00 2001 From: Paula Date: Tue, 29 Sep 2026 23:35:58 -0300 Subject: [PATCH] Change durability from a text to a bar --- client/gui/tooltip.ts | 3 --- client/rendering/render_utils.ts | 22 +++++++++++++++++++++- docs/modding/items/tools.md | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/client/gui/tooltip.ts b/client/gui/tooltip.ts index 8e01f9f..fc29a60 100644 --- a/client/gui/tooltip.ts +++ b/client/gui/tooltip.ts @@ -29,9 +29,6 @@ export function item_tooltip(item: ItemStack): TooltipLine[] { if (info?.food) { lines.push({ text: `Restores ${info.food.nutrition} hunger`, color: FOOD_COLOR }); } - if (info?.tool) { - lines.push({ text: `Durability: ${item.durability()} / ${info.tool.durability}`, color: LORE_COLOR }); - } const static_lore = info?.lore; for (const lore of [static_lore, item.lore]) { for (const text of lore?.split("\n") ?? []) { diff --git a/client/rendering/render_utils.ts b/client/rendering/render_utils.ts index ed1d5f0..297cebf 100644 --- a/client/rendering/render_utils.ts +++ b/client/rendering/render_utils.ts @@ -5,7 +5,13 @@ import { AssetManager } from "$/client/assets.ts"; import { ItemStack } from "$/common/inventory.ts"; import { item_texture } from "$/common/utils.ts"; import { block_item_texture, cube_face_texture, cube_face_tint } from "$/common/block_models.ts"; -import { draw_text, draw_texture_region, draw_texture_region_skewed, Texture } from "$/client/renderer/mod.ts"; +import { + draw_rect, + draw_text, + draw_texture_region, + draw_texture_region_skewed, + Texture, +} from "$/client/renderer/mod.ts"; // the corners keep their size (times scale), the edges stretch along and the middle fills the rest, like minecraft's // nine slice gui sprites. borders are in source pixels @@ -90,6 +96,20 @@ export function draw_item(item: ItemStack, x: number, y: number) { 1, ); } + + // durability bar, only on worn tools: 13 by 2 pixels near the bottom, going from green to red + const left = item.durability(); + if (left !== undefined && item_info.tool && left < item_info.tool.durability) { + const fraction = Math.max(0, left / item_info.tool.durability); + const pixel = SLOT_SIZE / 18; + draw_rect(x + 3 * pixel, y + 14 * pixel, 13 * pixel, 2 * pixel, [0, 0, 0, 1]); + draw_rect(x + 3 * pixel, y + 14 * pixel, Math.round(13 * fraction) * pixel, pixel, [ + 1 - fraction, + fraction, + 0, + 1, + ]); + } } // ey its not a bad name diff --git a/docs/modding/items/tools.md b/docs/modding/items/tools.md index 2a11ae0..06c9cf2 100644 --- a/docs/modding/items/tools.md +++ b/docs/modding/items/tools.md @@ -47,5 +47,5 @@ Like Sunlit Valley, tools don't wear out from use. They lose durability when the carries falls out where they died, and each tool loses 1 durability first. A tool that runs out breaks instead of dropping. -The damage a tool has taken is kept in its stack's `data.damage`, and its tooltip shows what's left, like -`Durability: 4 / 5`. Upgrading a tool at the smithing table keeps its data, damage included. +The damage a tool has taken is kept in its stack's `data.damage`, and a worn tool shows a bar under it in its slot, +going from green to red as it wears down. Upgrading a tool at the smithing table keeps its data, damage included.