This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/scriptcraft/src/main/ts/src/minecraft/registry.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-04-26 18:09:31 +00:00
import { Identifier, SimpleRegistry } from './core';
2020-04-28 00:15:24 +00:00
import { BlockRegistry, CustomBlock } from './block';
import { ItemRegistry, CustomItem, BlockItem } from './item';
2020-04-25 13:33:17 +00:00
/**
* Registry
*/
export abstract class Registry {
/**
* Block Registry
*/
2020-04-28 00:15:24 +00:00
static BLOCK: SimpleRegistry<CustomBlock> = BlockRegistry.INSTANCE;
2020-04-25 13:33:17 +00:00
/**
* Item Registry
*/
2020-04-28 00:15:24 +00:00
static ITEM: SimpleRegistry<CustomItem | BlockItem> = ItemRegistry.INSTANCE;
2020-04-25 13:33:17 +00:00
/**
* Register Object
* @param registry Target Registry
* @param id ID
* @param obj Object
*/
2020-04-26 18:09:31 +00:00
static register<T>(registry: SimpleRegistry<T>, id: Identifier, obj: T): T {
2020-04-25 13:33:17 +00:00
registry.register(id, obj);
return obj;
}
/**
* Get Object From Registry
* @param registry Target Registry
* @param id ID
2020-04-26 18:09:31 +00:00
* @returns Object
2020-04-25 13:33:17 +00:00
*/
2020-04-26 18:09:31 +00:00
static get<T>(registry: SimpleRegistry<T>, id: Identifier): T {
2020-04-25 13:33:17 +00:00
return registry.get(id);
}
2020-04-26 18:09:31 +00:00
/**
* Get ID Of Object From Registry
* @param registry Target Registry
* @param obj Object
* @returns ID
*/
static getID<T>(registry: SimpleRegistry<T>, obj: T): Identifier {
return registry.getID(obj);
}
}