Every recipe type registered from shared scripts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-01 21:00:44 -03:00
co-authored by Claude Opus 5.5
parent 65113862f7
commit a7e81b9944
25 changed files with 334 additions and 371 deletions
+7 -20
View File
@@ -19,14 +19,7 @@ import {
} from "./kinetics/connections.ts";
import { flow_score, motor_step } from "./kinetics/generators.ts";
import { handle_added, handle_removed, type KineticWorld, update_generated } from "./kinetics/spreading.ts";
import {
COMPACTING,
PRESSING,
processing_for,
processing_recipes,
type ProcessingRecipe,
roll_results,
} from "./recipes/processing.ts";
import { COMPACTING, PRESSING, type ProcessingRecipe, roll_results } from "./recipes/processing.ts";
import { CYCLE, cycle_rate, PRESS_AT, type PressShown, SCAN_TICKS } from "./processing/press.ts";
import {
apply_basin_recipe,
@@ -90,16 +83,9 @@ 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
const lookup = {
expand: (choice: Id | Id[]) => ctx.tags.expand(choice),
item_exists: (id: Id) => ctx.items.exists(id),
fluid_exists: (id: Id) => ctx.fluids.exists(id),
};
const pressing = processing_recipes(ctx.recipes.list(PRESSING.id), PRESSING, lookup);
// the ones that take more ingredients first, so a recipe isn't beaten by one that takes part of what it does, like
// BasinOperatingBlockEntity.getMatchingRecipes
const compacting = processing_recipes(ctx.recipes.list(COMPACTING.id), COMPACTING, lookup)
const compacting = [...ctx.recipes.all<ProcessingRecipe>(COMPACTING.id)]
.sort((a, b) => b.ingredients.length - a.ingredients.length);
ctx.components.register_block<KineticParams>("create:kinetic", {
@@ -209,7 +195,7 @@ export function setup(ctx: ServerContext) {
on_second: update_flow,
});
register_press(ctx, pressing, compacting);
register_press(ctx, compacting);
register_basin(ctx);
}
@@ -280,7 +266,8 @@ function set_basin(block: BlockRef, contents: Partial<BasinContents>) {
// lone item turns into what it's pressed into, and from a stack one at a time is, landing beside the rest. with a
// basin two blocks under it, it presses into that instead, making a compacting recipe in it each time, like
// MechanicalPressBlockEntity as a BasinOperatingBlockEntity. it only ticks while it turns
function register_press(ctx: ServerContext, recipes: ProcessingRecipe[], compacting: ProcessingRecipe[]) {
function register_press(ctx: ServerContext, compacting: ProcessingRecipe[]) {
const pressing_for = (item: Id) => ctx.recipes.find<ProcessingRecipe>(PRESSING.id, item);
// the basin two blocks under it, with a block between for the head to come down through, like
// BasinOperatingBlockEntity.getBasin
const basin_under = (block: BlockRef) => {
@@ -308,11 +295,11 @@ function register_press(ctx: ServerContext, recipes: ProcessingRecipe[], compact
{ x: block.x + inset, y: block.y - 1 + inset, z: block.z + inset },
{ x: block.x + 1 - inset, y: block.y - inset, z: block.z + 1 - inset },
"bworld:item",
).filter((item) => item.on_ground && processing_for(recipes, item.get_item()!.id));
).filter((item) => item.on_ground && pressing_for(item.get_item()!.id));
const press = (item: EntityRef) => {
const stack = item.get_item()!;
const results = roll_results(processing_for(recipes, stack.id)!);
const results = roll_results(pressing_for(stack.id)!);
const { x, y, z } = item.position;
if (stack.count === 1) {
const [first, ...rest] = results;