Register items for blocks

This commit is contained in:
2026-03-26 11:07:41 -03:00
parent 6e6dd08af7
commit 188b7a4372
15 changed files with 71 additions and 100 deletions
+4 -1
View File
@@ -5,7 +5,7 @@ export class EverythingRegistry {
static #key_to_id = new Map<string, Map<string, number>>();
static #id_to_value = new Map<string, unknown[]>();
static register<T>(registry: string, key: string, value: T) {
static register<T>(registry: string, key: string, value: T): T {
if (!this.#key_to_id.has(registry)) {
this.#key_to_id.set(registry, new Map());
this.#id_to_value.set(registry, []);
@@ -18,6 +18,8 @@ export class EverythingRegistry {
key_map.set(key, id);
values[id] = value;
return value;
}
static get<T>(registry: string, key: string): T | undefined {
@@ -61,6 +63,7 @@ interface TextureFront {
}
export interface BlockRegistry<T = unknown | undefined> {
id: string;
textures: string | TextureSideTopBottom | TextureFront;
transparent?: boolean;
alpha?: number;
+11
View File
@@ -1,5 +1,6 @@
import { AssetManager } from "../client/assets.ts";
import { SpriteRegion } from "./constants.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_registry.ts";
export function point_inside_rec(
point_x: number,
@@ -43,3 +44,13 @@ export function distance_point_point(ax: number, ay: number, az: number, bx: num
const dz = az - bz;
return dx * dx + dy * dy + dz * dz;
}
export function register_block_item(block: BlockRegistry) {
let texture_id = "bworld:missing";
if (typeof block.textures === "string") {
texture_id = block.textures;
}
EverythingRegistry.register<ItemRegistry>("items", block.id, {
texture_id,
});
}