Fluid containers

This commit is contained in:
2026-10-25 15:02:31 -03:00
parent fc27771a92
commit 26b59a1899
24 changed files with 486 additions and 82 deletions
+1 -2
View File
@@ -161,8 +161,7 @@ export class ModGraphics implements Graphics {
if (!EverythingRegistry.get<ItemRegistry>("items", id)) throw new Error(`unknown item ${id}`);
const stack = new ItemStack(id, count);
// the count only shows when it's more than one
if (count === 1) stack.max_amount = 1;
draw_item(stack, this.#x(x), this.#y(y));
draw_item(stack, this.#x(x), this.#y(y), count !== 1 && stack.max_amount !== 1);
}
clip(x: number, y: number, w: number, h: number, draw: () => void) {
+11 -3
View File
@@ -1,10 +1,12 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// the box next to the mouse saying what an item is, like minecraft's: its name, what it's worth, then its lore
// the box next to the mouse saying what an item is, like minecraft's: its name, the fluid in it, what it's worth, then
// its lore
import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
import type { ItemStack } from "$/common/inventory.ts";
import { contained_fluid, type ItemStack } from "$/common/inventory.ts";
import { display_name } from "$/common/utils.ts";
import { fluid_rules } from "$/client/fluid_rules.ts";
import { canvas, draw_text, draw_texture_region, measure_text, type Texture } from "$/client/renderer/mod.ts";
import { AssetManager } from "$/client/assets.ts";
import { get_sprite_region } from "$/client/sprites.ts";
@@ -16,6 +18,7 @@ type Color = [number, number, number, number];
const NAME_COLOR: Color = [1, 1, 1, 1];
const LORE_COLOR: Color = [0.66, 0.66, 0.66, 1];
const FOOD_COLOR: Color = [0.85, 0.6, 0.35, 1];
const FLUID_COLOR: Color = [0.55, 0.75, 0.95, 1];
const VALUE_COLOR: Color = [0.95, 0.8, 0.3, 1];
// from the edge of the tooltip sprite to the text
const PADDING = 4 * GUI_SCALE;
@@ -34,10 +37,15 @@ export interface TooltipLine {
icon?: string;
}
// its name, the item's lore from its json, then what the server's scripts said about this stack
// its name, the fluid a full container holds, the item's lore from its json, then what the server's scripts said about
// this stack
export function item_tooltip(item: ItemStack): TooltipLine[] {
const lines: TooltipLine[] = [{ text: display_name(item.type_id), color: NAME_COLOR }];
const info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
const fluid = contained_fluid(item.type_id, item.data);
if (fluid) {
lines.push({ text: `${fluid_rules.name(fluid)}, ${info!.fluid_container!.capacity} mB`, color: FLUID_COLOR });
}
if (info?.food) {
lines.push({ text: `Restores ${info.food.nutrition} hunger`, color: FOOD_COLOR });
}