Pressing recipes

This commit is contained in:
2026-10-15 12:32:16 -03:00
parent 74c315bdfc
commit 7faa070d83
15 changed files with 335 additions and 35 deletions
+3 -2
View File
@@ -32,8 +32,9 @@ kinds:
item item models to items, for the items that aren't a block's
tag tags (data/<namespace>/tags) to tags/, entries that don't exist in the mods next to --output
made optional
recipe recipes to recipes/, for the types bworld has: stonecutting. ones naming items or tags that
don't exist in the mods next to --output are left out
recipe recipes to recipes/, for the types bworld has: stonecutting, and create's pressing in its own
shape with bworld's item choices. ones naming items or tags that don't exist in the mods next
to --output are left out
options:
--output PATH the file (for one input file) or the folder to write. one model without it is printed
+36 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// java recipes (data/<namespace>/recipe/**.json, recipes/ before 1.21) to bworld's recipes/, keeping their folders.
// each type bworld has an equivalent for is converted, the rest are reported. a recipe naming an item or tag that
// each type bworld or a ported mod has an equivalent for is converted, the rest are reported. a recipe naming an item or tag that
// doesn't exist here is left out, since bworld's recipes have to be complete
import { join } from "@std/path";
import { FORMAT_VERSION } from "$/common/mod_data.ts";
@@ -44,8 +44,43 @@ const CONVERTERS: Record<string, (json: Json, context: Context) => Converted> =
if ("skipped" in output || "error" in output) return output;
return { recipe: { type: "bworld:stonecutting", input: input.choice, output: output.stack } };
},
"create:pressing": processing,
};
// create's processing recipes keep their shape, with bworld's item choices as ingredients, results as { id, count } and
// their chance when it isn't certain, and processing_time and heat_requirement under 6.0's names. like
// ProcessingRecipeParams' codec
function processing(json: Json, context: Context): Converted {
if (!Array.isArray(json.ingredients) || !Array.isArray(json.results)) {
return { error: "it needs lists of ingredients and results" };
}
const ingredients: (string | string[])[] = [];
for (const ingredient of json.ingredients) {
const converted = choice(ingredient, context);
if (!("choice" in converted)) return converted;
ingredients.push(converted.choice);
}
const results: Record<string, unknown>[] = [];
for (const result of json.results) {
const converted = stack(result, undefined, context);
if (!("stack" in converted)) return converted;
const chance = result.chance ?? 1;
results.push(chance < 1 ? { ...converted.stack, chance } : converted.stack);
}
// 0.5 called them processingTime and heatRequirement
const time = json.processing_time ?? json.processingTime;
const heat = json.heat_requirement ?? json.heatRequirement;
return {
recipe: {
type: json.type,
ingredients,
results,
...(time !== undefined && { processing_time: time }),
...(heat !== undefined && { heat_requirement: heat }),
},
};
}
export function import_recipes(input: string, options: ImportOptions = {}): 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) };