Stress for create networks
This commit is contained in:
@@ -32,6 +32,8 @@ export async function setup(config: Record<string, unknown> = {}) {
|
||||
game.set_block(x, y, z, id, undefined, state ? set_state_value(0, info, state, value)! >>> 16 : 0);
|
||||
};
|
||||
const speed = (x: number, y: number, z: number) => game.world.get_tile(x, y, z)?.client_data?.speed as number ?? 0;
|
||||
const overstressed = (x: number, y: number, z: number) =>
|
||||
game.world.get_tile(x, y, z)?.client_data?.overstressed === true;
|
||||
const state = (x: number, y: number, z: number, name: string) =>
|
||||
get_state_value(game.world.get_block_value(x, y, z), game.world.get_block_info(x, y, z)!, name);
|
||||
const use = (x: number, y: number, z: number, face: Face = "south") =>
|
||||
@@ -44,7 +46,7 @@ export async function setup(config: Record<string, unknown> = {}) {
|
||||
(EverythingRegistry.get<BlockRegistry>("blocks", "create:hand_crank")!.components!["create:hand_crank"] as {
|
||||
speed: number;
|
||||
}).speed;
|
||||
return { ...t, move, place, speed, state, use, ticks, crank };
|
||||
return { ...t, move, place, speed, overstressed, state, use, ticks, crank };
|
||||
}
|
||||
|
||||
// create's client script with only what its visuals need, and a block for one to draw that records what its instances
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// create's kinetics: shafts take the speed of what turns them, a hand crank turns them while it's being clicked, and a
|
||||
// block that would turn two ways at once breaks
|
||||
// create's kinetics: shafts take the speed of what turns them, a hand crank turns them while it's being clicked, a
|
||||
// block that would turn two ways at once breaks, and a network that takes more than its generators make stops
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { AIR_ID } from "$/common/protocol.ts";
|
||||
import { test_game } from "../helpers.ts";
|
||||
@@ -132,6 +132,76 @@ Deno.test("speeds are saved, and a crank still stops after the world is loaded",
|
||||
assertEquals(speed(3), 0);
|
||||
});
|
||||
|
||||
// a crank making capacity per rpm, and presses taking impact per rpm
|
||||
const stress = (capacity: number, impact: number) => ({
|
||||
stress: { capacity: { "create:hand_crank": capacity }, impact: { "create:mechanical_press": impact } },
|
||||
});
|
||||
|
||||
Deno.test("a network whose blocks take more than its generators make is overstressed, all of it", async () => {
|
||||
// each press takes half of what the crank makes, at any speed
|
||||
const t = await setup(stress(8, 4));
|
||||
const over = t.overstressed;
|
||||
t.place(0, 100, 0, "create:hand_crank", "facing", FACING.west);
|
||||
t.place(1, 100, 0, "create:mechanical_press", "facing", FACING.east);
|
||||
t.place(2, 100, 0, "create:mechanical_press", "facing", FACING.east);
|
||||
t.place(3, 100, 0, "create:shaft", "axis", AXIS.x);
|
||||
t.use(0, 100, 0);
|
||||
assertEquals([0, 1, 2, 3].map((x) => over(x, 100, 0)), [false, false, false, false]);
|
||||
|
||||
// a third is too many, and every block in the network stops, though its speed is kept
|
||||
t.place(4, 100, 0, "create:mechanical_press", "facing", FACING.east);
|
||||
assertEquals([0, 1, 2, 3, 4].map((x) => over(x, 100, 0)), [true, true, true, true, true]);
|
||||
assertEquals(line(t, 0, 4), [-t.crank, -t.crank, -t.crank, -t.crank, -t.crank]);
|
||||
|
||||
// taking it away again is enough
|
||||
t.game.destroy_block(4, 100, 0);
|
||||
assertEquals([0, 1, 2, 3].map((x) => over(x, 100, 0)), [false, false, false, false]);
|
||||
|
||||
// and blocks that stop turning aren't overstressed any more
|
||||
t.place(4, 100, 0, "create:mechanical_press", "facing", FACING.east);
|
||||
t.ticks(40);
|
||||
assertEquals([0, 1, 2, 3, 4].map((x) => over(x, 100, 0)), [false, false, false, false, false]);
|
||||
});
|
||||
|
||||
Deno.test("a second generator turning a network adds what it makes", async () => {
|
||||
const t = await setup(stress(8, 6));
|
||||
const over = t.overstressed;
|
||||
t.place(0, 100, 0, "create:hand_crank", "facing", FACING.west);
|
||||
for (let x = 1; x <= 2; x++) t.place(x, 100, 0, "create:mechanical_press", "facing", FACING.east);
|
||||
t.place(3, 100, 0, "create:hand_crank", "facing", FACING.east);
|
||||
t.use(0, 100, 0);
|
||||
assert(over(1, 100, 0));
|
||||
// sneaking turns this one the same way around x as the first
|
||||
t.move(true);
|
||||
t.use(3, 100, 0);
|
||||
assertEquals([0, 1, 2, 3].map((x) => over(x, 100, 0)), [false, false, false, false]);
|
||||
|
||||
// let go, it's overstressed again
|
||||
for (let i = 0; i < 10; i++) {
|
||||
t.ticks(4);
|
||||
t.use(0, 100, 0);
|
||||
}
|
||||
assert(over(1, 100, 0));
|
||||
});
|
||||
|
||||
Deno.test("a block takes more the faster it turns", async () => {
|
||||
// on its own the press takes 3/4 of what the crank makes
|
||||
const press_behind = async (cog: "create:cogwheel" | "create:large_cogwheel") => {
|
||||
const t = await setup(stress(8, 6));
|
||||
t.place(0, 100, 0, "create:hand_crank", "facing", FACING.west);
|
||||
t.place(1, 100, 0, "create:large_cogwheel", "axis", AXIS.x);
|
||||
t.place(1, 101, 1, "create:cogwheel", "axis", AXIS.x);
|
||||
// behind the large cog at the crank's speed, or the small one at twice that
|
||||
const [y, z] = cog === "create:large_cogwheel" ? [100, 0] : [101, 1];
|
||||
t.place(2, y, z, "create:mechanical_press", "facing", FACING.east);
|
||||
t.use(0, 100, 0);
|
||||
assertEquals(Math.abs(t.speed(2, y, z)), cog === "create:large_cogwheel" ? t.crank : 2 * t.crank);
|
||||
return t.overstressed(2, y, z);
|
||||
};
|
||||
assertEquals(await press_behind("create:large_cogwheel"), false);
|
||||
assertEquals(await press_behind("create:cogwheel"), true);
|
||||
});
|
||||
|
||||
Deno.test("a shaft lines up with the axle it's placed against, and otherwise points the way the player looks", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "chat", text: "/give create:shaft 64" });
|
||||
@@ -254,6 +324,17 @@ Deno.test("a shaft is drawn turning around its axis at the speed its client data
|
||||
assertEquals(turns.get("own")!.slice(0, 2), ["z", -64]);
|
||||
});
|
||||
|
||||
Deno.test("a block in an overstressed network is drawn still", async () => {
|
||||
const { visual, turns, data } = await visual_for("create:shaft", { axis: AXIS.z }, {
|
||||
speed: 16,
|
||||
overstressed: true,
|
||||
});
|
||||
assertEquals(turns.get("own")![1], 0);
|
||||
data.overstressed = undefined;
|
||||
visual.update!();
|
||||
assertEquals(turns.get("own")![1], 16);
|
||||
});
|
||||
|
||||
Deno.test("a crank's handle catches up with the speed it turns at, and slows to a stop", async () => {
|
||||
const { visual, turns, data } = await visual_for("create:hand_crank", { facing: FACING.west }, { speed: -32 });
|
||||
assertEquals(turns.get("own")!.slice(0, 2), ["x", -32]);
|
||||
|
||||
@@ -8,8 +8,8 @@ import { ItemStack } from "$/common/inventory.ts";
|
||||
import { FACING, setup, visual_for } from "./helpers.ts";
|
||||
|
||||
// a press at 1 101 0 along x, turned by a crank on its west side, with the floor two blocks under it
|
||||
async function press_with_crank() {
|
||||
const t = await setup();
|
||||
async function press_with_crank(config?: Record<string, unknown>) {
|
||||
const t = await setup(config);
|
||||
t.place(0, 101, 0, "create:hand_crank", "facing", FACING.west);
|
||||
t.place(1, 101, 0, "create:mechanical_press", "facing", FACING.east);
|
||||
// holding use on the crank, which clicks it every 4 ticks
|
||||
@@ -40,6 +40,16 @@ Deno.test("a turning press slams down on an ingot lying under it and presses it
|
||||
assertEquals(t.lying(), { "create:iron_sheet": 1 });
|
||||
});
|
||||
|
||||
Deno.test("an overstressed press doesn't press", async () => {
|
||||
// it takes more than the crank makes
|
||||
const t = await press_with_crank({
|
||||
stress: { capacity: { "create:hand_crank": 1 }, impact: { "create:mechanical_press": 2 } },
|
||||
});
|
||||
t.ingots(1);
|
||||
t.crank(200);
|
||||
assertEquals(t.lying(), { "bworld:iron_ingot": 1 });
|
||||
});
|
||||
|
||||
Deno.test("from a stack, a press presses one at a time, and each lands beside the rest", async () => {
|
||||
const t = await press_with_crank();
|
||||
t.ingots(3);
|
||||
|
||||
Reference in New Issue
Block a user