Add all textures and models from create

This commit is contained in:
2026-10-12 18:47:41 -03:00
parent d4eff11f3e
commit 99bdcaeffc
3775 changed files with 66614 additions and 58 deletions
+28 -21
View File
@@ -22,6 +22,8 @@ import {
location_string,
parse_location,
type Remaps,
type ResourceRoot,
skips,
to_id,
write_report,
} from "./resources.ts";
@@ -57,7 +59,7 @@ const EMPTY_PARENTS = ["minecraft:block/block", "minecraft:block/air"];
// whether a model holds nothing a bworld model can use, all the way up its parents, like block/block or a mod's own
// root of display transforms. a model with one as its parent leaves it out, since it isn't written
function is_empty(location: string, read: ModelSource, seen = new Set<string>()): boolean {
export function is_empty(location: string, read: ModelSource, seen = new Set<string>()): boolean {
if (EMPTY_PARENTS.includes(location)) return true;
const json = read(location);
if (!json || seen.has(location) || json.elements !== undefined) return false;
@@ -73,27 +75,10 @@ export function import_models(input: string, options: ImportOptions = {}): Impor
const single = is_file(input);
if (!single && options.output === undefined) throw new Error("--output is needed to convert a folder");
const files = input_files(input, "models", ".json", options.namespace);
const lookup = [
const read = model_source([
...new Set(files.map(({ root }) => root)),
...(options.parents ?? []).flatMap((dir) => find_roots(dir, "models")),
];
const cache = new Map<string, Record<string, unknown> | undefined>();
const read: ModelSource = (location) => {
if (cache.has(location)) return cache.get(location);
const { namespace, path } = parse_location(location);
const file = lookup.filter((root) => root.namespace === namespace).map((root) => `${root.dir}/${path}.json`)
.find(is_file);
let json: Record<string, unknown> | undefined;
if (file) {
try {
json = JSON.parse(Deno.readTextFileSync(file));
} catch (e) {
throw new Error(`${file} isn't valid json: ${(e as Error).message}`);
}
}
cache.set(location, json);
return json;
};
]);
const several_namespaces = new Set(files.map(({ root }) => root.namespace)).size > 1;
const report = empty_report();
@@ -101,6 +86,7 @@ export function import_models(input: string, options: ImportOptions = {}): Impor
for (const { root, file } of files) {
const where = location_of(root, file, ".json");
const location = location_string(where);
if (skips(location, remaps, report)) continue;
const result = convert_model(location, read, remaps);
if (result.kind === "skipped") report.skipped.push({ location, reason: result.reason });
else if (result.kind === "error") report.errors.push({ location, problems: result.problems });
@@ -117,6 +103,27 @@ export function import_models(input: string, options: ImportOptions = {}): Impor
return report;
}
// reads java models by location from these models roots, the first that has it, each file once
export function model_source(roots: ResourceRoot[]): ModelSource {
const cache = new Map<string, Record<string, unknown> | undefined>();
return (location) => {
if (cache.has(location)) return cache.get(location);
const { namespace, path } = parse_location(location);
const file = roots.filter((root) => root.namespace === namespace).map((root) => `${root.dir}/${path}.json`)
.find(is_file);
let json: Record<string, unknown> | undefined;
if (file) {
try {
json = JSON.parse(Deno.readTextFileSync(file));
} catch (e) {
throw new Error(`${file} isn't valid json: ${(e as Error).message}`);
}
}
cache.set(location, json);
return json;
};
}
export function convert_model(location: string, read: ModelSource, remaps: Remaps): ModelResult {
const json = read(location_string(parse_location(location)));
if (!json) return { kind: "error", problems: [`${location} wasn't found`] };
@@ -171,7 +178,7 @@ export function convert_model(location: string, read: ModelSource, remaps: Remap
// why a model isn't boxes bworld can draw, going up its parents: an item sprite, or one a loader makes (obj files,
// composites). undefined for boxes, or when its parents can't be followed, which check-mods then reports
function made_by(location: string, read: ModelSource): string | undefined {
export function made_by(location: string, read: ModelSource): string | undefined {
const seen = new Set<string>();
for (let at: string | undefined = location_string(parse_location(location)); at && !seen.has(at);) {
seen.add(at);