Fill on serverworld and clear out tiles on new day

This commit is contained in:
2026-11-22 11:22:07 -03:00
parent dfb110e0f8
commit c2e885f23a
8 changed files with 64 additions and 18 deletions
+6 -2
View File
@@ -67,14 +67,18 @@ function placed(plan: InteriorPlan) {
Deno.test("an interior has as many rooms as it's asked for when there's room, starting from main", () => {
const { tiles } = plan("rooms");
assertEquals(tiles.length, 30);
assertEquals(tiles[0], { tile: "test:main", position: { x: 100, y: 50, z: -20 }, rotation: 0 });
const { tile, position, rotation } = tiles[0];
assertEquals({ tile, position, rotation }, { tile: "test:main", position: { x: 100, y: 50, z: -20 }, rotation: 0 });
assertEquals(tiles.filter((tile) => tile.tile === "test:main").length, 1);
});
Deno.test("rooms only share their outer walls", () => {
for (const seed of ["a", "b", "c", "d", "e"]) {
const tiles = placed(plan(seed));
const result = plan(seed);
const tiles = placed(result);
for (let i = 0; i < tiles.length; i++) {
// the box the plan keeps is the one its schematic covers
assertEquals(result.tiles[i].box, { min: tiles[i].min, max: tiles[i].max });
for (let j = i + 1; j < tiles.length; j++) {
const [a, b] = [tiles[i], tiles[j]];
const inside = [0, 1, 2].every((axis) => a.min[axis] < b.max[axis] && b.min[axis] < a.max[axis]);
+16 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// what machines do to the world through server phases: read which way water flows, find items lying around and
// change them, push things, break blocks over time, and use items on blocks like a player would
// change them, push things, break blocks over time, use items on blocks like a player would, and fill whole boxes
import { assert, assertEquals, assertThrows } from "@std/assert";
import type { ServerContext } from "cubi/server";
import { AIR_ID } from "@/common/protocol.ts";
@@ -144,6 +144,21 @@ Deno.test("a block breaking over time shows its cracks to players, and machines
assertEquals(ctx.world.break_block(2, 99, 0), undefined);
});
Deno.test("a script fills every block between two corners, both included, however big the box", async () => {
const { game, ctx } = await setup();
// corners in any order, and bigger than /fill takes
assertEquals(ctx.world.fill({ x: 40, y: 99, z: 40 }, { x: 0, y: 40, z: 0 }, "bworld:stone"), 41 * 60 * 41);
assertEquals(ctx.world.fill({ x: 1, y: 98, z: 3 }, { x: 0, y: 99, z: 2 }, "cubi:air"), 8);
for (const [x, y, z] of [[0, 98, 2], [1, 99, 3], [0, 99, 3]]) {
assertEquals(game.world.get_block_id(x, y, z), AIR_ID);
}
for (const [x, y, z] of [[2, 99, 3], [1, 97, 3], [1, 99, 4], [40, 40, 40]]) {
assertEquals(game.world.get_block_id(x, y, z), "bworld:stone");
}
assertThrows(() => ctx.world.fill({ x: 0, y: 99, z: 0 }, { x: 1, y: 99, z: 1 }, "bworld:nothing"));
assertEquals(game.world.get_block_id(0, 99, 0), "bworld:stone");
});
Deno.test("a machine uses items on blocks like a player holding them would", async () => {
const { game, ctx } = await setup();
// placing: the block goes in front of the face, and one fewer is left