// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later // the mechanical press's cycle, like create's PressingBehaviour: the head comes down, presses at the bottom halfway // through, and goes back up. it counts CYCLE steps, more of them a tick the faster the press turns. no ctx, the server // runs the cycle and visuals draw it from the same numbers export const CYCLE = 240; // where it presses, at the bottom export const PRESS_AT = CYCLE / 2; // how often a still press looks for something to press, in ticks 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, 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; return Math.floor(1 + 59 * Math.min(1, Math.abs(speed) / 512)); } // how far down the head is that far through the cycle, 0 up to 1 at the bottom, like getRenderedHeadOffset: it // speeds up on the way down, stays down a moment after pressing, and goes up at a steady speed export function head_offset(steps: number): number { const clamp = (value: number) => Math.max(0, Math.min(1, value)); if (steps < CYCLE * 2 / 3) return clamp((steps / CYCLE * 2) ** 3); return clamp((CYCLE - steps) / CYCLE * 3); }