All the stone cutter recipes
This commit is contained in:
+55
-13
@@ -4,7 +4,9 @@
|
||||
// where things are in a java mod's resources, and what they're called in bworld. a resource location like
|
||||
// "create:block/cogwheel" (or "block/stone", which is minecraft's) becomes the id "create:block_cogwheel": bworld ids
|
||||
// have no folders, so the path's folders are joined with _, the same way check_mods names textures in subfolders
|
||||
import { ID_PATTERN } from "$/common/mod_data.ts";
|
||||
import { ID_PATTERN, type TagRegistry } from "$/common/mod_data.ts";
|
||||
import { registered_ids } from "$/common/mod_check.ts";
|
||||
import { load_and_check } from "$/tools/check_mods.ts";
|
||||
import { dirname, relative, resolve, SEPARATOR } from "@std/path";
|
||||
|
||||
export interface Location {
|
||||
@@ -32,6 +34,9 @@ export type Remap = Record<string, string>;
|
||||
export interface Remaps {
|
||||
textures: Remap;
|
||||
models: Remap;
|
||||
// blocks, items, entities and biomes, where tags and recipes name them
|
||||
ids: Remap;
|
||||
tags: Remap;
|
||||
// patterns (regular expressions) for locations to leave out of every kind, like a mod's blocks for content bworld
|
||||
// doesn't have: "crimson" leaves out create:crimson_window, its models and its textures
|
||||
skip?: string[];
|
||||
@@ -40,6 +45,10 @@ export interface Remaps {
|
||||
export const DEFAULT_REMAPS: Remaps = {
|
||||
textures: { "minecraft:block/": "bworld:", "minecraft:item/": "bworld:" },
|
||||
models: template_remaps(),
|
||||
// the base game's blocks and items are named like minecraft's, and its tags too. forge's shared tags were renamed
|
||||
// c, which is what bworld calls them
|
||||
ids: { "minecraft:": "bworld:" },
|
||||
tags: { "minecraft:": "bworld:", "forge:": "c:" },
|
||||
};
|
||||
|
||||
// minecraft's template models (cube_all, stairs, walls, panes, ...) are the base game's in models/templates, which are
|
||||
@@ -74,7 +83,12 @@ export function is_valid_id(id: string): boolean {
|
||||
return ID_PATTERN.test(id);
|
||||
}
|
||||
|
||||
// a folder of one kind of resource (models, textures, ...) for one namespace: assets/<namespace>/<kind>
|
||||
// what a mod's resources are in: assets/ for what clients draw, data/ for tags, recipes and the rest
|
||||
const TOPS = ["assets", "data"];
|
||||
|
||||
// a folder of one kind of resource (models, textures, ...) for one namespace: assets/<namespace>/<kind>, or
|
||||
// data/<namespace>/<kind>. some kinds' folder was renamed between versions, like recipes to recipe, so a kind can be
|
||||
// several names
|
||||
export interface ResourceRoot {
|
||||
namespace: string;
|
||||
dir: string;
|
||||
@@ -85,15 +99,17 @@ export interface ResourceRoot {
|
||||
|
||||
// the roots of a kind inside a folder: every assets/<namespace>/<kind> under it (only namespace's, when it's given), or
|
||||
// the folder itself when it's one or is inside one. a folder that's none of those is a root of the given namespace
|
||||
export function find_roots(input: string, kind: string, namespace?: string): ResourceRoot[] {
|
||||
export function find_roots(input: string, kind: string | string[], namespace?: string): ResourceRoot[] {
|
||||
const dir = resolve(input);
|
||||
const enclosing = enclosing_root(dir, kind);
|
||||
if (enclosing) return [enclosing];
|
||||
const roots: ResourceRoot[] = [];
|
||||
for (const assets of find_dirs(dir, "assets")) {
|
||||
for (const entry of read_dir(assets)) {
|
||||
if (entry.isDirectory && is_dir(`${assets}/${entry.name}/${kind}`)) {
|
||||
roots.push({ namespace: entry.name, dir: `${assets}/${entry.name}/${kind}` });
|
||||
for (const top of TOPS.flatMap((name) => find_dirs(dir, name))) {
|
||||
for (const entry of read_dir(top)) {
|
||||
for (const name of [kind].flat()) {
|
||||
if (entry.isDirectory && is_dir(`${top}/${entry.name}/${name}`)) {
|
||||
roots.push({ namespace: entry.name, dir: `${top}/${entry.name}/${name}` });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +127,7 @@ export interface InputFile {
|
||||
// assets/ folder is the namespace's, or the mod's that output is in
|
||||
export function input_files(
|
||||
input: string,
|
||||
kind: string,
|
||||
kind: string | string[],
|
||||
extension: string,
|
||||
namespace?: string,
|
||||
output?: string,
|
||||
@@ -125,7 +141,8 @@ export function input_files(
|
||||
}
|
||||
const roots = find_roots(input, kind, namespace);
|
||||
if (roots.length === 0) {
|
||||
throw new Error(`no ${kind} in ${input}: pass --namespace when it isn't inside assets/<namespace>/${kind}`);
|
||||
const name = [kind].flat()[0];
|
||||
throw new Error(`no ${name} in ${input}: pass --namespace when it isn't inside assets/<namespace>/${name}`);
|
||||
}
|
||||
const full = resolve(input);
|
||||
return roots.flatMap((root) => {
|
||||
@@ -135,10 +152,10 @@ export function input_files(
|
||||
}
|
||||
|
||||
// the assets/<namespace>/<kind> folder a path is in, if it's in one
|
||||
export function enclosing_root(path: string, kind: string): ResourceRoot | undefined {
|
||||
export function enclosing_root(path: string, kind: string | string[]): ResourceRoot | undefined {
|
||||
const parts = resolve(path).split(SEPARATOR);
|
||||
for (let i = parts.length - 1; i >= 2; i--) {
|
||||
if (parts[i] === kind && parts[i - 2] === "assets") {
|
||||
if ([kind].flat().includes(parts[i]) && TOPS.includes(parts[i - 2])) {
|
||||
return { namespace: parts[i - 1], dir: parts.slice(0, i + 1).join(SEPARATOR) };
|
||||
}
|
||||
}
|
||||
@@ -184,14 +201,34 @@ function read_dir(dir: string): Deno.DirEntry[] {
|
||||
|
||||
// the id of the mod a path is in, from the manifest.json of the nearest folder up that has one
|
||||
export function mod_namespace(path: string): string | undefined {
|
||||
return mod_of(path)?.id;
|
||||
}
|
||||
|
||||
function mod_of(path: string): { id: string; dir: string } | undefined {
|
||||
for (let dir = dirname(resolve(path)); dir !== dirname(dir); dir = dirname(dir)) {
|
||||
if (!is_file(`${dir}/manifest.json`)) continue;
|
||||
const id = JSON.parse(Deno.readTextFileSync(`${dir}/manifest.json`)).id;
|
||||
return typeof id === "string" ? id : undefined;
|
||||
return typeof id === "string" ? { id, dir } : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// what the mods next to the one output is in have, by registry: their blocks, items, entities and biomes, and the
|
||||
// tags their files define. undefined when output isn't in a mod
|
||||
export interface Known {
|
||||
ids: Record<TagRegistry, Set<string>>;
|
||||
tags: Record<TagRegistry, Set<string>>;
|
||||
}
|
||||
|
||||
export function known_in(output: string): Known | undefined {
|
||||
const mod = mod_of(`${output}/x`);
|
||||
if (!mod) return undefined;
|
||||
const mods = 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 };
|
||||
}
|
||||
|
||||
export function is_file(path: string): boolean {
|
||||
try {
|
||||
return Deno.statSync(path).isFile;
|
||||
@@ -237,11 +274,16 @@ export interface ImportReport {
|
||||
|
||||
// whether the remaps leave a location out, which is reported as skipped
|
||||
export function skips(location: string, remaps: Remaps, report: ImportReport): boolean {
|
||||
const pattern = remaps.skip?.find((pattern) => new RegExp(pattern).test(location));
|
||||
const pattern = skip_pattern(location, remaps);
|
||||
if (pattern !== undefined) report.skipped.push({ location, reason: `the remaps skip "${pattern}"` });
|
||||
return pattern !== undefined;
|
||||
}
|
||||
|
||||
// the skip pattern a location matches, if any
|
||||
export function skip_pattern(location: string, remaps: Remaps): string | undefined {
|
||||
return remaps.skip?.find((pattern) => new RegExp(pattern).test(location));
|
||||
}
|
||||
|
||||
export function empty_report(): ImportReport {
|
||||
return { written: [], skipped: [], errors: [], warnings: [] };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user