New hooks
This commit is contained in:
@@ -479,6 +479,19 @@ export class ModRuntime {
|
||||
}
|
||||
#ticking_components_of = new Map<string, BlockComponentOf[]>();
|
||||
|
||||
// the ones with a handler, for handlers that run often, like on_neighbor_change. cached like components_of
|
||||
components_with(block_id: string, handler: keyof BlockComponent): readonly BlockComponentOf[] {
|
||||
let of_handler = this.#components_with.get(handler);
|
||||
if (!of_handler) this.#components_with.set(handler, of_handler = new Map());
|
||||
let components = of_handler.get(block_id);
|
||||
if (!components) {
|
||||
components = this.components_of(block_id).filter(({ component }) => component[handler]);
|
||||
of_handler.set(block_id, components);
|
||||
}
|
||||
return components;
|
||||
}
|
||||
#components_with = new Map<keyof BlockComponent, Map<string, BlockComponentOf[]>>();
|
||||
|
||||
// components on an item, with their params from its json
|
||||
item_components_of(item_id: string): { mod: string; id: string; component: ItemComponent; params: unknown }[] {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", item_id);
|
||||
@@ -604,6 +617,7 @@ export class ModRuntime {
|
||||
this.block_components.set(id, { mod, component: component as BlockComponent });
|
||||
this.#components_of.clear();
|
||||
this.#ticking_components_of.clear();
|
||||
this.#components_with.clear();
|
||||
},
|
||||
register_item: (id, component) => {
|
||||
setup_only("components");
|
||||
|
||||
Reference in New Issue
Block a user