Pressing recipes
This commit is contained in:
@@ -5,9 +5,9 @@ redstone, contraptions, trains, equipment, decoration and schematics. It aims to
|
||||
possible, and to stay fast on both the server and the client when a world has thousands of moving parts.
|
||||
|
||||
Built so far: the importer and Create's imported blocks and items, R1, R2, R3 (`transformed` and `rotating`), R4, R5,
|
||||
R8, S0, S7, S12, stonecutting from S9, and the start of P1's kinetics: shafts and cogwheels turned by a hand crank.
|
||||
Facts about Create come from reading `ports/create1.21.1` and `ports/create1.19.3`, and facts about bworld from its
|
||||
source.
|
||||
R8, S0, S7, S12, stonecutting from S9, the start of P1's kinetics (shafts and cogwheels turned by a hand crank), and
|
||||
Create's pressing recipes. Facts about Create come from reading `ports/create1.21.1` and `ports/create1.19.3`, and facts
|
||||
about bworld from its source.
|
||||
|
||||
## Sources
|
||||
|
||||
@@ -108,19 +108,19 @@ shared tags to `c`, which is what bworld calls them. A mod's remap file is where
|
||||
|
||||
**Kinds:**
|
||||
|
||||
| Kind | Java | bworld | Status |
|
||||
| ------------ | -------------------------------------------- | ---------------------------------------------------------------------- | ------ |
|
||||
| `model` | `assets/*/models/**.json` | `models/`, parents kept, faces renamed, Blockbench extras dropped | Built |
|
||||
| `texture` | `assets/*/textures/**.png` and `.png.mcmeta` | `textures/`, with animations | Built |
|
||||
| `blockstate` | `assets/*/blockstates/*.json` | `blocks/*.json` with `variants` or `parts`, string states made numeric | Built |
|
||||
| `item` | `assets/*/models/item/*.json` | `items/*.json` for items that aren't a block's, with their sprite | Built |
|
||||
| `lang` | `assets/*/lang/en_us.json` | item and block names | |
|
||||
| `recipe` | `data/*/recipe(s)/**.json` | `recipes/`: vanilla types to bworld's. Stonecutting so far | Built |
|
||||
| `tag` | `data/*/tags/**.json` | `tags/`, Forge's shared tags as `c:`, missing entries optional | Built |
|
||||
| `loot` | `data/*/loot_table(s)/**.json` | `drops`, or loot tables | |
|
||||
| `worldgen` | `data/*/worldgen/**.json` | `worldgen/`: ores, and features where bworld has them | |
|
||||
| `sound` | `assets/*/sounds.json`, `sounds/**.ogg` | sounds, once the engine has them (S8) | |
|
||||
| `mod` | all of the above | a whole mod folder with a manifest, and one report | |
|
||||
| Kind | Java | bworld | Status |
|
||||
| ------------ | -------------------------------------------- | ----------------------------------------------------------------------- | ------ |
|
||||
| `model` | `assets/*/models/**.json` | `models/`, parents kept, faces renamed, Blockbench extras dropped | Built |
|
||||
| `texture` | `assets/*/textures/**.png` and `.png.mcmeta` | `textures/`, with animations | Built |
|
||||
| `blockstate` | `assets/*/blockstates/*.json` | `blocks/*.json` with `variants` or `parts`, string states made numeric | Built |
|
||||
| `item` | `assets/*/models/item/*.json` | `items/*.json` for items that aren't a block's, with their sprite | Built |
|
||||
| `lang` | `assets/*/lang/en_us.json` | item and block names | |
|
||||
| `recipe` | `data/*/recipe(s)/**.json` | `recipes/`: vanilla types to bworld's. Stonecutting and pressing so far | Built |
|
||||
| `tag` | `data/*/tags/**.json` | `tags/`, Forge's shared tags as `c:`, missing entries optional | Built |
|
||||
| `loot` | `data/*/loot_table(s)/**.json` | `drops`, or loot tables | |
|
||||
| `worldgen` | `data/*/worldgen/**.json` | `worldgen/`: ores, and features where bworld has them | |
|
||||
| `sound` | `assets/*/sounds.json`, `sounds/**.ogg` | sounds, once the engine has them (S8) | |
|
||||
| `mod` | all of the above | a whole mod folder with a manifest, and one report | |
|
||||
|
||||
Block properties (shape, tool, toughness) aren't in any data file: Java mods set them in code. `mod` writes a block for
|
||||
each blockstate with placeholder properties, and a per-mod table fills them in. For Create that table is
|
||||
@@ -170,12 +170,14 @@ about 31 vanilla textures bworld doesn't have yet. The 132 blockstates that use
|
||||
keeping folders in tag ids. An entry that doesn't exist here becomes optional (`required: false`), so the tag loads now
|
||||
and picks it up once it's added, and what the remaps skip is left out. `recipe` converts each type bworld has an
|
||||
equivalent for and reports the rest by type. A recipe naming an item or tag that doesn't exist here, or that only loads
|
||||
under a condition (another mod installed), is skipped, since bworld's recipes have to be complete. Only
|
||||
`minecraft:stonecutting` is converted so far, to `bworld:stonecutting`.
|
||||
under a condition (another mod installed), is skipped, since bworld's recipes have to be complete. So far
|
||||
`minecraft:stonecutting` is converted to `bworld:stonecutting`, and `create:pressing` keeps its type in the shape in
|
||||
[Recipes](#recipes), from 0.5's and 6.0's JSON alike.
|
||||
|
||||
Create 0.5.0.j's data gives 89 tags: 45 of Create's and 44 of Forge's shared ones, which are `c:` here. Fluid tags are
|
||||
skipped. Of its 531 stonecutting recipes, 423 are converted. The other 108 cut granite, diorite, deepslate, calcite,
|
||||
tuff and dripstone, which bworld doesn't have yet. Re-importing once it does brings them in.
|
||||
tuff and dripstone, which bworld doesn't have yet. Re-importing once it does brings them in. Of its 6 pressing recipes,
|
||||
4 are converted, ingots into sheets. Sugar cane into paper and grass into dirt paths wait for those items.
|
||||
|
||||
**For Create**, `mods/create/import/` keeps the remap file, the block table and the commands. Re-running the import is
|
||||
one command, and hand-written files are never in the folders it writes.
|
||||
@@ -408,22 +410,24 @@ All 19 of Create's types, plus the vanilla types its data uses:
|
||||
| `filling`, `emptying` | 24 | spout, item drain | P5 |
|
||||
| `toolbox_dyeing`, `item_copying`, `conversion` | — | built-in, special | P9 |
|
||||
|
||||
Create's own types stay in Create's format inside bworld's envelope:
|
||||
Create's own types keep Create's shape inside bworld's envelope, but with bworld's item choices (an id, a `#tag`, or a
|
||||
list of those any of which fits) in place of Java's `{ item }` and `{ tag }`, like every other recipe here:
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "create:pressing",
|
||||
"ingredients": [{ "tag": "c:ingots/iron" }],
|
||||
"results": [{ "id": "create:iron_sheet" }]
|
||||
"ingredients": ["#c:ingots/iron"],
|
||||
"results": [{ "id": "create:iron_sheet", "count": 1 }]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`scripts/recipes/` parses all of them in one place: ingredients as `{ item }`, `{ tag }`, lists of those, or sized fluid
|
||||
ingredients; results as `{ id, count, chance }` or fluid stacks; `processing_time` and `heat_requirement`. It checks
|
||||
each type's input and output limits, which come from each recipe class's `getMaxInputCount` and `getMaxOutputCount`. The
|
||||
`scripts/recipes/` parses all of them in one place: ingredients as item choices, or sized fluid ingredients; results as
|
||||
`{ id, count, chance }` or fluid stacks; `processing_time` and `heat_requirement`. Built for pressing, without fluids,
|
||||
durations or heat yet, in `scripts/recipes/processing.ts`, which the server script runs in `setup`. It checks each
|
||||
type's input and output limits, which come from each recipe class's `getMaxInputCount` and `getMaxOutputCount`. The
|
||||
recipe viewer gets one reader for this shape, so every Create type shows with no per-type code, and animated categories
|
||||
(R11) are added per machine on top.
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ deno task check-mods
|
||||
|
||||
The order matters: tags and recipes are checked against what's already in the mods folder, so blocks and items go first,
|
||||
then tags, then recipes. Forge's shared tags, like `forge:ingots/brass`, become bworld's `c:` ones. Recipes are only
|
||||
Create's stonecutting ones so far, and the ones that cut a stone bworld doesn't have yet (granite, diorite, deepslate,
|
||||
calcite, tuff, dripstone) are left out until it does.
|
||||
Create's stonecutting and pressing ones so far. The stonecutting ones that cut a stone bworld doesn't have yet (granite,
|
||||
diorite, deepslate, calcite, tuff, dripstone) are left out until it does, and so is pressing paper and dirt paths.
|
||||
|
||||
Java sets what blocks do in code, so every block gets placeholders (a second to mine with anything, dropping itself).
|
||||
`blocks.json` gives blocks what they have instead, by id, like the components that make a shaft turn and a hand crank
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "create:pressing",
|
||||
"ingredients": ["#c:ingots/brass"],
|
||||
"results": [
|
||||
{ "id": "create:brass_sheet", "count": 1 }
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "create:pressing",
|
||||
"ingredients": ["bworld:copper_ingot"],
|
||||
"results": [
|
||||
{ "id": "create:copper_sheet", "count": 1 }
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "create:pressing",
|
||||
"ingredients": ["#c:ingots/gold"],
|
||||
"results": [
|
||||
{ "id": "create:golden_sheet", "count": 1 }
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "create:pressing",
|
||||
"ingredients": ["#c:ingots/iron"],
|
||||
"results": [
|
||||
{ "id": "create:iron_sheet", "count": 1 }
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// create's processing recipes, the shape its machines' recipe types share, like ProcessingRecipe: item choices in, and
|
||||
// stacks out, each with a chance. read and checked when the server starts, so a broken one stops it there instead of
|
||||
// in a machine. no ctx, tests give what it needs
|
||||
import type { Id } from "bworld/shared";
|
||||
|
||||
// how many ingredients and results a type takes at most, like getMaxInputCount and getMaxOutputCount
|
||||
export interface ProcessingType {
|
||||
readonly id: Id;
|
||||
readonly inputs: number;
|
||||
readonly outputs: number;
|
||||
}
|
||||
|
||||
export const PRESSING: ProcessingType = { id: "create:pressing", inputs: 1, outputs: 2 };
|
||||
|
||||
export interface ProcessingResult {
|
||||
id: Id;
|
||||
count: number;
|
||||
// how likely each of count is to come out, 1 for always, like ProcessingOutput's
|
||||
chance: number;
|
||||
}
|
||||
|
||||
export interface ProcessingRecipe {
|
||||
// each ingredient as every item that fits it
|
||||
ingredients: Id[][];
|
||||
results: ProcessingResult[];
|
||||
}
|
||||
|
||||
// what reading recipes needs from the game
|
||||
export interface RecipeLookup {
|
||||
// an item choice as its items, like ctx.tags.expand
|
||||
expand(choice: Id | Id[]): Id[];
|
||||
item_exists(id: Id): boolean;
|
||||
}
|
||||
|
||||
// every recipe of type, from their json, or an error saying what's wrong with each broken one
|
||||
export function processing_recipes(jsons: unknown[], type: ProcessingType, lookup: RecipeLookup): ProcessingRecipe[] {
|
||||
const parsed = jsons.map((json) => parse_processing(json, type, lookup));
|
||||
const problems = parsed.flatMap((recipe, i) =>
|
||||
"problems" in recipe ? [`${type.id} recipe ${JSON.stringify(jsons[i])}: ${recipe.problems.join("; ")}`] : []
|
||||
);
|
||||
if (problems.length > 0) throw new Error(problems.join("\n"));
|
||||
return parsed as ProcessingRecipe[];
|
||||
}
|
||||
|
||||
// one recipe, or what's wrong with it, like ProcessingRecipe.validate
|
||||
export function parse_processing(
|
||||
// deno-lint-ignore no-explicit-any
|
||||
json: any,
|
||||
type: ProcessingType,
|
||||
lookup: RecipeLookup,
|
||||
): ProcessingRecipe | { problems: string[] } {
|
||||
const problems: string[] = [];
|
||||
const ingredients: Id[][] = [];
|
||||
const results: ProcessingResult[] = [];
|
||||
if (!Array.isArray(json?.ingredients) || json.ingredients.length === 0) {
|
||||
problems.push("ingredients must be a list of item choices");
|
||||
} else {
|
||||
if (json.ingredients.length > type.inputs) {
|
||||
problems.push(`it takes ${json.ingredients.length} ingredients, and ${type.id} takes ${type.inputs}`);
|
||||
}
|
||||
for (const choice of json.ingredients) {
|
||||
const choices = [choice].flat();
|
||||
const valid = choices.length > 0 && choices.every((id) => typeof id === "string");
|
||||
const unknown = valid ? choices.filter((id: string) => !id.startsWith("#") && !lookup.item_exists(id)) : [];
|
||||
if (!valid) problems.push(`${JSON.stringify(choice)} isn't an item, a #tag or a list of them`);
|
||||
else if (unknown.length > 0) problems.push(`it takes ${unknown.join(", ")}, which doesn't exist`);
|
||||
else ingredients.push(lookup.expand(choice));
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(json?.results) || json.results.length === 0) {
|
||||
problems.push("results must be a list of { id, count, chance }");
|
||||
} else {
|
||||
if (json.results.length > type.outputs) {
|
||||
problems.push(`it makes ${json.results.length} results, and ${type.id} makes ${type.outputs}`);
|
||||
}
|
||||
for (const result of json.results) {
|
||||
const { id, count = 1, chance = 1 } = result ?? {};
|
||||
if (typeof id !== "string" || !lookup.item_exists(id)) problems.push(`it makes ${id}, which doesn't exist`);
|
||||
else if (!Number.isInteger(count) || count < 1 || count > 99) {
|
||||
problems.push(`${id}'s count must be 1 to 99`);
|
||||
} else if (typeof chance !== "number" || chance <= 0 || chance > 1) {
|
||||
problems.push(`${id}'s chance must be above 0 and at most 1`);
|
||||
} else results.push({ id, count, chance });
|
||||
}
|
||||
}
|
||||
// none of the types so far can say how long they take or how hot they have to be, like canSpecifyDuration and
|
||||
// canRequireHeat
|
||||
if (json?.processing_time !== undefined) problems.push(`${type.id} can't have a processing_time`);
|
||||
if (json?.heat_requirement !== undefined) problems.push(`${type.id} can't have a heat_requirement`);
|
||||
return problems.length > 0 ? { problems } : { ingredients, results };
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// create's blocks that do something: so far what turns (create:kinetic) and the hand crank that turns it
|
||||
// create's blocks that do something: so far what turns (create:kinetic) and the hand crank that turns it. and its
|
||||
// recipe types' checks
|
||||
import type { BlockRef, Id, ServerContext } from "bworld/server";
|
||||
import { along, kinetic_shape, type KineticParams } from "./kinetics/connections.ts";
|
||||
import { handle_added, handle_removed, type KineticWorld, type Pos, update_generated } from "./kinetics/spreading.ts";
|
||||
import { PRESSING, processing_recipes } from "./recipes/processing.ts";
|
||||
|
||||
interface Config {
|
||||
max_speed: number;
|
||||
@@ -36,6 +38,12 @@ export function setup(ctx: ServerContext) {
|
||||
const config: Config = ctx.config;
|
||||
const world = kinetic_world(ctx, config);
|
||||
|
||||
// checked now, so a broken recipe stops the server rather than a press later
|
||||
processing_recipes(ctx.recipes.list(PRESSING.id), PRESSING, {
|
||||
expand: (choice) => ctx.tags.expand(choice),
|
||||
item_exists: (id) => ctx.items.exists(id),
|
||||
});
|
||||
|
||||
ctx.components.register_block<KineticParams>("create:kinetic", {
|
||||
on_create(block) {
|
||||
handle_added(world, [block.x, block.y, block.z]);
|
||||
|
||||
@@ -19,6 +19,7 @@ likely each is, read with `ctx.blocks.components` and `ctx.loot.table`.
|
||||
|
||||
- `scripts/categories.ts` has a category for each recipe type, like JEI's `IRecipeCategory`: its title, size, where it's
|
||||
made (`MOD_CATALYSTS` for mods' types) and where its items go. Types without one are drawn from their JSON: the items
|
||||
in their lists as ingredients, a single item (like the cooking pot's bowl) under the arrow, and their `result`.
|
||||
in their lists as ingredients, a single item (like the cooking pot's bowl) under the arrow, and their `result`,
|
||||
`output` or `results`.
|
||||
- `scripts/recipes.ts` reads what any recipe makes and takes.
|
||||
- `scripts/item_list.ts` is the item list, `scripts/recipes_screen.ts` the recipes screen.
|
||||
|
||||
@@ -35,6 +35,7 @@ export interface RecipeCategory {
|
||||
const MOD_CATALYSTS: Record<string, string[]> = {
|
||||
"farmersdelight:cooking": ["farmersdelight:cooking_pot"],
|
||||
"farmersdelight:cutting": ["farmersdelight:cutting_board"],
|
||||
"create:pressing": ["create:mechanical_press"],
|
||||
};
|
||||
|
||||
// the base game's, in the order their tabs go, like jei's vanilla plugin
|
||||
|
||||
@@ -22,8 +22,8 @@ export function outputs(recipe: Recipe): Ingredient[] {
|
||||
case "smithing":
|
||||
return [{ ids: [recipe.result], count: 1 }];
|
||||
default: {
|
||||
// one item or stack, or a list of them, like what a cutting board cuts something into
|
||||
const output = recipe.result ?? recipe.output;
|
||||
// one item or stack, or a list of them, like what a cutting board cuts something into or a press presses
|
||||
const output = recipe.result ?? recipe.output ?? recipe.results;
|
||||
return [output].flat().flatMap((output): Ingredient[] => {
|
||||
if (typeof output === "string") return [{ ids: [output], count: 1 }];
|
||||
if (output && typeof output.id === "string") return [stack(output)];
|
||||
@@ -56,7 +56,7 @@ export function inputs(recipe: Recipe, tags: TagApi): Ingredient[] {
|
||||
}
|
||||
}
|
||||
|
||||
// the items in a mod recipe's fields besides its type and result: each item or #tag in a list is an ingredient (a list
|
||||
// the items in a mod recipe's fields besides its type and results: each item or #tag in a list is an ingredient (a list
|
||||
// in a list is one ingredient any of whose items fit), and a field that's one item is an extra, like a container
|
||||
export function mod_recipe_inputs(recipe: Recipe, tags: TagApi): { grid: Ingredient[]; extras: Ingredient[] } {
|
||||
const grid: Ingredient[] = [];
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// create's recipe types: read and checked when the server starts, and shown by the recipe viewer
|
||||
import { assert, assertEquals, assertThrows } from "@std/assert";
|
||||
import { EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { tag_api } from "$/common/tags.ts";
|
||||
import type { ClientContext } from "$/common/mod_api/client.ts";
|
||||
import { parse_processing, PRESSING, processing_recipes } from "$/mods/create/scripts/recipes/processing.ts";
|
||||
import { inputs, outputs } from "$/mods/recipe_viewer/scripts/recipes.ts";
|
||||
import { RecipeIndex } from "$/mods/recipe_viewer/scripts/recipes_screen.ts";
|
||||
import { test_game } from "../helpers.ts";
|
||||
|
||||
const lookup = () => ({
|
||||
expand: (choice: string | string[]) => tag_api().expand(choice),
|
||||
item_exists: (id: string) => EverythingRegistry.get("items", id) !== undefined,
|
||||
});
|
||||
|
||||
Deno.test("create's pressing recipes are read with every item each ingredient stands for", async () => {
|
||||
const { game } = await test_game("mods");
|
||||
const recipes = processing_recipes(game.recipes.by_type.get(PRESSING.id) ?? [], PRESSING, lookup());
|
||||
const sheet = recipes.find((recipe) => recipe.results[0].id === "create:iron_sheet");
|
||||
assert(sheet, "iron is pressed into sheets");
|
||||
assert(sheet.ingredients[0].includes("bworld:iron_ingot"));
|
||||
assertEquals(sheet.results, [{ id: "create:iron_sheet", count: 1, chance: 1 }]);
|
||||
});
|
||||
|
||||
Deno.test("a pressing recipe that a press couldn't make says what's wrong with it", async () => {
|
||||
await test_game("mods");
|
||||
const problems = (json: unknown) => {
|
||||
const parsed = parse_processing(json, PRESSING, lookup());
|
||||
return "problems" in parsed ? parsed.problems : [];
|
||||
};
|
||||
const sheet = { id: "create:iron_sheet" };
|
||||
assertEquals(problems({ ingredients: ["bworld:iron_ingot"], results: [sheet] }), []);
|
||||
// a press takes one item, and makes up to two
|
||||
assertEquals(problems({ ingredients: ["bworld:iron_ingot", "bworld:gold_ingot"], results: [sheet] }).length, 1);
|
||||
assertEquals(problems({ ingredients: ["bworld:iron_ingot"], results: [sheet, sheet, sheet] }).length, 1);
|
||||
assertEquals(problems({ ingredients: ["bworld:no_such_ingot"], results: [sheet] }).length, 1);
|
||||
assertEquals(
|
||||
problems({ ingredients: ["bworld:iron_ingot"], results: [{ id: "create:iron_sheet", chance: 2 }] }).length,
|
||||
1,
|
||||
);
|
||||
assertEquals(problems({ ingredients: ["bworld:iron_ingot"], results: [sheet], processing_time: 100 }).length, 1);
|
||||
assertEquals(problems({ results: [sheet] }).length, 1);
|
||||
|
||||
// the server doesn't start with one, and says which
|
||||
assertThrows(
|
||||
() => processing_recipes([{ ingredients: ["bworld:no_such_ingot"], results: [sheet] }], PRESSING, lookup()),
|
||||
Error,
|
||||
"bworld:no_such_ingot",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("the recipe viewer shows pressing recipes under the press, with what they take and make", async () => {
|
||||
const { game } = await test_game("mods");
|
||||
const pressing = game.recipes.all.filter((recipe) => recipe.type === PRESSING.id);
|
||||
const sheet = pressing.find((recipe) => outputs(recipe)[0]?.ids[0] === "create:iron_sheet");
|
||||
assert(sheet);
|
||||
assert(inputs(sheet, tag_api())[0].ids.includes("bworld:iron_ingot"));
|
||||
|
||||
const ctx = {
|
||||
recipes: { list: () => game.recipes.all },
|
||||
tags: tag_api(),
|
||||
items: {
|
||||
exists: (id: string) => EverythingRegistry.get("items", id) !== undefined,
|
||||
ids: () => EverythingRegistry.entries("items").map(([id]) => id),
|
||||
components: () => ({}),
|
||||
},
|
||||
blocks: { exists: () => false, components: () => ({}) },
|
||||
loot: { table: () => undefined },
|
||||
} as unknown as ClientContext;
|
||||
const category = new RecipeIndex(ctx).categories.find((category) => category.type === PRESSING.id);
|
||||
assertEquals([category?.title, category?.catalysts], ["Pressing", ["create:mechanical_press"]]);
|
||||
});
|
||||
@@ -531,6 +531,47 @@ Deno.test("tags keep their entries, renamed, and ones that don't exist here beco
|
||||
assertStringIncludes(report.warnings[0].warning, "bworld:stone");
|
||||
});
|
||||
|
||||
Deno.test("create's pressing recipes keep their shape, with bworld's item choices, from 0.5's and 6.0's json", () => {
|
||||
const mod = gears_mod();
|
||||
const report = import_recipes(
|
||||
data({
|
||||
// 0.5 named results' items "item", and an ingredient that's a list is one any of whose items fit
|
||||
"gears/recipes/pressing/teeth": {
|
||||
type: "create:pressing",
|
||||
ingredients: [[{ tag: "gears:teeth" }, { item: "gears:gear" }]],
|
||||
results: [{ item: "gears:gear", count: 2 }],
|
||||
processingTime: 100,
|
||||
},
|
||||
"gears/recipe/pressing/gear": {
|
||||
type: "create:pressing",
|
||||
ingredients: [{ item: "gears:gear" }],
|
||||
results: [{ id: "gears:gear" }, { id: "gears:gear", chance: 0.5 }, { id: "gears:gear", chance: 1 }],
|
||||
},
|
||||
"gears/recipe/pressing/granite": {
|
||||
type: "create:pressing",
|
||||
ingredients: [{ item: "minecraft:granite" }],
|
||||
results: [{ id: "gears:gear" }],
|
||||
},
|
||||
}),
|
||||
{ output: `${mod}/recipes` },
|
||||
);
|
||||
assertEquals(report.errors, []);
|
||||
const read = (path: string) => JSON.parse(Deno.readTextFileSync(`${mod}/recipes/${path}.json`)).recipe;
|
||||
assertEquals(read("pressing/teeth"), {
|
||||
type: "create:pressing",
|
||||
ingredients: [["#gears:teeth", "gears:gear"]],
|
||||
results: [{ id: "gears:gear", count: 2 }],
|
||||
processing_time: 100,
|
||||
});
|
||||
// a chance is only kept when it isn't certain
|
||||
assertEquals(read("pressing/gear").results, [
|
||||
{ id: "gears:gear", count: 1 },
|
||||
{ id: "gears:gear", count: 1, chance: 0.5 },
|
||||
{ id: "gears:gear", count: 1 },
|
||||
]);
|
||||
assertEquals(report.skipped.map(({ location }) => location), ["gears:pressing/granite"]);
|
||||
});
|
||||
|
||||
Deno.test("stonecutting recipes become bworld's, and ones it can't use are reported", () => {
|
||||
const mod = gears_mod();
|
||||
const cut = (ingredient: unknown, result: unknown, extra = {}) => ({
|
||||
|
||||
+3
-2
@@ -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
|
||||
|
||||
@@ -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) };
|
||||
|
||||
Reference in New Issue
Block a user