Change durability from a text to a bar

This commit is contained in:
2026-09-29 23:35:58 -03:00
parent 1ac7a5c943
commit d859c6066c
3 changed files with 23 additions and 6 deletions
-3
View File
@@ -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") ?? []) {
+21 -1
View File
@@ -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
+2 -2
View File
@@ -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.