Implement main game as a mod
This commit is contained in:
@@ -5,6 +5,9 @@ export class EverythingRegistry {
|
||||
static #id_to_value = new Map<string, unknown[]>();
|
||||
|
||||
static register<T>(registry: string, key: string, value: T): T {
|
||||
if (this.#key_to_id.get(registry)?.has(key)) {
|
||||
throw new Error(`${key} is already registered in ${registry}`);
|
||||
}
|
||||
if (!this.#key_to_id.has(registry)) {
|
||||
this.#key_to_id.set(registry, new Map());
|
||||
this.#id_to_value.set(registry, []);
|
||||
@@ -49,6 +52,12 @@ export class EverythingRegistry {
|
||||
return this.#id_to_value.get(registry) as T[];
|
||||
}
|
||||
|
||||
// forget everything, for tests that load mods more than once
|
||||
static clear() {
|
||||
this.#key_to_id.clear();
|
||||
this.#id_to_value.clear();
|
||||
}
|
||||
|
||||
// [key, value] pairs in registration order
|
||||
static entries<T>(registry: string): [string, T][] {
|
||||
const values = this.#id_to_value.get(registry) ?? [];
|
||||
@@ -104,6 +113,8 @@ export interface BlockRegistry {
|
||||
interactive?: boolean;
|
||||
// placing a block into it replaces it, like water
|
||||
replaceable?: boolean;
|
||||
// custom components from mods and their params, the server runs them
|
||||
components?: Record<string, unknown>;
|
||||
|
||||
compiled_states?: CompiledStateDefinition[];
|
||||
}
|
||||
@@ -112,6 +123,9 @@ export interface ItemRegistry<T = unknown | undefined> {
|
||||
texture_id: string | ((item: ItemStack<T>) => string);
|
||||
block_id?: string;
|
||||
tool_type?: string;
|
||||
max_stack?: number;
|
||||
lore?: string;
|
||||
components?: Record<string, unknown>;
|
||||
|
||||
on_create?(item: ItemStack<T>): void;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user