Change durability from a text to a bar
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user