Stress for create networks

This commit is contained in:
2026-10-28 21:28:36 -03:00
parent a70375c9ad
commit 507e9aab24
10 changed files with 276 additions and 46 deletions
@@ -7,6 +7,7 @@
import type { Face } from "bworld/shared";
export type Axis = "x" | "y" | "z";
export type Pos = readonly [number, number, number];
// the create:kinetic component's params, from a block's json
export interface KineticParams {
@@ -157,3 +158,22 @@ export function neighbour_positions(block: Kinetic): [number, number, number][]
];
return offsets.map(([dx, dy, dz]) => [block.x + dx, block.y + dy, block.z + dz]);
}
// the kinetic blocks next to node that turn it or that it turns, like getConnectedNeighbours. get is undefined where
// what's there isn't kinetic
export function connected<T extends Kinetic>(
get: (x: number, y: number, z: number) => T | undefined,
node: Kinetic,
): T[] {
return neighbour_positions(node).flatMap(([x, y, z]) => {
const neighbour = get(x, y, z);
const turns = neighbour && (speed_ratio(node, neighbour) !== 0 || speed_ratio(neighbour, node) !== 0);
return turns ? [neighbour] : [];
});
}
// how fast a block acts and is drawn turning, from its client data: its speed, or still while its network is
// overstressed, like KineticBlockEntity.getSpeed
export function actual_speed(block: { get_client_data<T>(field: string): T | undefined }): number {
return block.get_client_data<boolean>("overstressed") ? 0 : block.get_client_data<number>("speed") ?? 0;
}