Block registry api

This commit is contained in:
2026-11-12 20:41:13 -03:00
parent e7fe663746
commit 76802ed430
39 changed files with 499 additions and 100 deletions
+2 -2
View File
@@ -81,9 +81,9 @@ function processing(json: Json, context: Context): Converted {
};
}
export function import_recipes(input: string, options: ImportOptions = {}): ImportReport {
export async function import_recipes(input: string, options: ImportOptions = {}): Promise<ImportReport> {
if (options.output === undefined) throw new Error("--output is needed for recipes");
const context = { remaps: options.remaps ?? DEFAULT_REMAPS, known: known_in(options.output) };
const context = { remaps: options.remaps ?? DEFAULT_REMAPS, known: await known_in(options.output) };
const report = empty_report();
if (context.known === undefined) {
report.warnings.push({
+2 -2
View File
@@ -221,10 +221,10 @@ export interface Known {
tags: Record<TagRegistry, Set<string>>;
}
export function known_in(output: string): Known | undefined {
export async function known_in(output: string): Promise<Known | undefined> {
const mod = mod_of(`${output}/x`);
if (!mod) return undefined;
const mods = load_and_check(dirname(mod.dir));
const mods = await load_and_check(dirname(mod.dir));
const tags: Known["tags"] = { blocks: new Set(), items: new Set(), entities: new Set(), biomes: new Set() };
for (const { json } of mods.flatMap((mod) => mod.tags)) tags[json.registry].add(json.id);
return { ids: registered_ids(mods), tags };
+2 -2
View File
@@ -47,7 +47,7 @@ export function tag_id(location: string, remaps: Remaps): string {
return `${namespace}:${path}`;
}
export function import_tags(input: string, options: ImportOptions = {}): ImportReport {
export async function import_tags(input: string, options: ImportOptions = {}): Promise<ImportReport> {
if (options.output === undefined) throw new Error("--output is needed for tags");
const remaps = options.remaps ?? DEFAULT_REMAPS;
const report = empty_report();
@@ -68,7 +68,7 @@ export function import_tags(input: string, options: ImportOptions = {}): ImportR
return [{ location, registry, id, json: JSON.parse(Deno.readTextFileSync(file)) }];
});
const known = known_in(options.output);
const known = await known_in(options.output);
const own = new Set(tags.map(({ registry, id }) => `${registry} ${id}`));
for (const { location, registry, id, json } of tags) {
if (!TAG_ID_PATTERN.test(id)) {