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
+2 -2
View File
@@ -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 }
]
}
}
+94
View File
@@ -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 };
}
+9 -1
View File
@@ -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]);
+2 -1
View File
@@ -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.
+1
View File
@@ -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
+3 -3
View File
@@ -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[] = [];