Juices on the mechanical press !

This commit is contained in:
2026-10-31 00:03:03 -03:00
parent 3734f5707a
commit 23d02c5229
11 changed files with 381 additions and 62 deletions
+46
View File
@@ -66,3 +66,49 @@ function canonical(value: unknown): string {
}
return JSON.stringify(value) ?? "";
}
// what's in a basin: its input items, the items recipes made, which recipes don't take again, and its tanks, like
// BasinBlockEntity's input and output inventories and its tanks. both inventories are BASIN_SLOTS kinds each
export interface BasinContents {
items: readonly ItemStack[];
outputs: readonly ItemStack[];
tanks: readonly BasinTank[];
}
// what a basin recipe needs: one item for each ingredient, and what it makes
export interface BasinRecipe {
// each ingredient as every item that fits it
ingredients: readonly (readonly string[])[];
results: readonly ItemStack[];
fluid_results: readonly BasinTank[];
}
// the basin once recipe has been made in it, or undefined when it can't be: an item for each ingredient comes out of
// its input items, the first stack that fits each, and the results have to fit in its outputs and tanks, like
// BasinRecipe.apply. max_stack is how many of an item a stack holds
export function apply_basin_recipe(
basin: BasinContents,
recipe: BasinRecipe,
max_stack: (item: ItemStack) => number,
same: (a: FluidVariant, b: FluidVariant) => boolean,
): BasinContents | undefined {
const items = basin.items.map((item) => ({ ...item }));
for (const ingredient of recipe.ingredients) {
const from = items.find((item) => item.count > 0 && ingredient.includes(item.id));
if (!from) return undefined;
from.count--;
}
let outputs = basin.outputs;
for (const result of recipe.results) {
const into = insert_item(outputs, result, max_stack(result));
if (into.inserted < result.count) return undefined;
outputs = into.items;
}
let tanks: readonly BasinTank[] = basin.tanks;
for (const { fluid, amount } of recipe.fluid_results) {
const filled = fill(tanks, fluid, amount, same);
if (!filled) return undefined;
tanks = filled;
}
return { items: items.filter((item) => item.count > 0), outputs, tanks };
}
+7 -1
View File
@@ -12,12 +12,18 @@ export const PRESS_AT = CYCLE / 2;
export const SCAN_TICKS = 10;
// a pressing press's "press" client data, what its visual moves the head by: the step of the cycle it was at when this
// was set, and how many steps a tick it's going
// was set, how many steps a tick it's going, and whether it's pressing into a basin, which its head goes further down
// into, by BASIN_TRAVEL
export interface PressShown {
steps: number;
rate: number;
basin?: boolean;
}
// how far down the head goes into a basin two blocks under it, in blocks, like PressingBehaviour.Mode.BASIN's
// headOffset. on the ground it's one
export const BASIN_TRAVEL = 22 / 16;
// steps of the cycle a tick at a speed in rpm, like getRunningTickSpeed: 1 almost still, up to 60 at 512 rpm
export function cycle_rate(speed: number): number {
if (speed === 0) return 0;