Water buckets

This commit is contained in:
2026-10-06 19:44:40 -03:00
parent 4524cfe960
commit 5481ec94a4
6 changed files with 86 additions and 7 deletions
+9 -2
View File
@@ -177,10 +177,17 @@ function seeded_random(seed: string) {
};
}
// the block a block's own item looks like. other items that place a block, like seeds or a water bucket, look like
// their own texture
export function placed_block(item: ItemStack): BlockRegistry | undefined {
const item_info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
if (!item_info?.block_id || item_info.block_id !== item.type_id) return undefined;
return EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id);
}
// the full block an item places, drawn as a cube. blocks that aren't cubes, like plants, are drawn as their sprite
export function item_block(item: ItemStack): BlockRegistry | undefined {
const item_info = EverythingRegistry.get<ItemRegistry>("items", item.type_id);
const block = item_info?.block_id ? EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id) : undefined;
const block = placed_block(item);
return block && block_item_texture(block) === undefined ? block : undefined;
}
+2 -4
View File
@@ -12,7 +12,7 @@ import {
ITEM_FACE_SHADE,
item_tint,
} from "$/common/block_models.ts";
import { item_model_quads, sprite_u, sprite_v } from "./item_renderer.ts";
import { item_model_quads, placed_block, sprite_u, sprite_v } from "./item_renderer.ts";
import {
draw_rect,
draw_text,
@@ -83,9 +83,7 @@ export function draw_item(item: ItemStack, x: number, y: number) {
throw Error(`Didn't find item registry for '${item.type_id}'`);
}
const block_info = item_info.block_id
? EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id)
: undefined;
const block_info = placed_block(item);
// blocks that aren't cubes, like plants, show a flat sprite
const model = block_info && item_model_quads(block_info);
if (block_info && model) {