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
+33 -16
View File
@@ -15,7 +15,15 @@ import {
ITEM_FACE_SHADE,
item_tint,
} from "$/common/block_models.ts";
import { display_matrix, item_block, item_model_of, type ItemModel, sprite_u, sprite_v } from "./item_renderer.ts";
import {
display_matrix,
item_block,
item_layers,
item_model_of,
type ItemModel,
sprite_u,
sprite_v,
} from "./item_renderer.ts";
import {
draw_rect,
draw_text,
@@ -77,7 +85,8 @@ export function draw_nine_slice(
}
}
export function draw_item(item: ItemStack, x: number, y: number) {
// show_count is for drawing an item where its count means nothing, like one shown on a screen
export function draw_item(item: ItemStack, x: number, y: number, show_count = item.max_amount !== 1) {
const item_info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
if (!item_info) {
@@ -95,7 +104,7 @@ export function draw_item(item: ItemStack, x: number, y: number) {
draw_item_item(item, item_info, x, y);
}
if (item.max_amount !== 1) {
if (show_count) {
draw_text(
String(item.amount),
x + SLOT_SIZE + 2 - 11 * 2,
@@ -128,19 +137,27 @@ export function draw_item(item: ItemStack, x: number, y: number) {
// ey its not a bad name
function draw_item_item(item: ItemStack, item_info: ItemRegistry, x: number, y: number) {
const texture_id = item_texture(item, item_info);
const sprite_region = get_sprite_region(texture_id);
draw_texture_region(
AssetManager.instance.get("bworld:textures"),
sprite_region.x,
sprite_region.y,
sprite_region.width,
sprite_region.height,
x + 3,
y + 3,
SLOT_SIZE - 6,
SLOT_SIZE - 6,
);
const draw = (texture_id: string, [r, g, b] = [1, 1, 1]) => {
const sprite_region = get_sprite_region(texture_id);
draw_texture_region(
AssetManager.instance.get("bworld:textures"),
sprite_region.x,
sprite_region.y,
sprite_region.width,
sprite_region.height,
x + 3,
y + 3,
SLOT_SIZE - 6,
SLOT_SIZE - 6,
false,
false,
r,
g,
b,
);
};
draw(item_texture(item, item_info));
for (const layer of item_layers(item)) draw(layer.texture, layer.color);
}
// from a model's points to a slot, as screen x and y and depth toward the viewer. with a gui transform, the transform