Fishing !
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ID_MASK, STATE_SHIFT } from "./constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_registry.ts";
|
||||
import { block_item_texture, cube_face_texture } from "./block_models.ts";
|
||||
import type { ItemStack } from "./inventory.ts";
|
||||
|
||||
export function point_inside_rec(
|
||||
point_x: number,
|
||||
@@ -46,6 +47,19 @@ export function register_block_item(block: BlockRegistry) {
|
||||
EverythingRegistry.register<ItemRegistry>("items", block.id, item);
|
||||
}
|
||||
|
||||
// the texture a stack is drawn with: one of its data_textures when its data has that key set, or its texture
|
||||
export function item_texture(
|
||||
item: ItemStack,
|
||||
info = EverythingRegistry.get<ItemRegistry>("items", item.type_id),
|
||||
): string {
|
||||
if (!info) return "engine:missing";
|
||||
const data = item.data as Record<string, unknown> | undefined;
|
||||
for (const [key, texture] of Object.entries(info.data_textures ?? {})) {
|
||||
if (data?.[key]) return texture;
|
||||
}
|
||||
return typeof info.texture_id === "function" ? info.texture_id(item) : info.texture_id;
|
||||
}
|
||||
|
||||
// what players see an item called: its name, or one made from its id, so bworld:iron_ingot is "Iron Ingot"
|
||||
export function display_name(item_id: string): string {
|
||||
const name = EverythingRegistry.get<ItemRegistry>("items", item_id)?.name;
|
||||
|
||||
Reference in New Issue
Block a user