Fill command

This commit is contained in:
2026-11-15 20:56:40 -03:00
parent b4adf85f03
commit 17f39bfa4d
3 changed files with 110 additions and 9 deletions
+32
View File
@@ -209,3 +209,35 @@ Deno.test("/locatebiome says where the nearest biome of a kind is", async () =>
assertEquals(game.world.locate_biome("bworld:plains", x, z), y);
assert(say("/locatebiome bworld:nowhere").includes("There's no biome bworld:nowhere"));
});
Deno.test("/fill replaces every block between two corners, both included", async () => {
const { game, join, take, send } = await test_game("mods");
join(1, "alice");
take(1);
const say = (text: string) => {
send(1, { type: "chat", text });
return take(1).filter((m) => m.type === "chat").map((m) => m.text).join("\n");
};
const ids = (x0: number, y0: number, z0: number, x1: number, y1: number, z1: number) => {
const found = new Set<string>();
for (let x = x0; x <= x1; x++) {
for (let y = y0; y <= y1; y++) {
for (let z = z0; z <= z1; z++) found.add(game.world.get_block_id(x, y, z));
}
}
return [...found];
};
// corners in any order
assertEquals(say("/fill 12 101 21 10 100 20 stone"), "Filled 12 blocks with Stone");
assertEquals(ids(10, 100, 20, 12, 101, 21), ["bworld:stone"]);
assert(!ids(9, 100, 20, 9, 101, 21).includes("bworld:stone"));
assert(!ids(10, 102, 20, 12, 102, 21).includes("bworld:stone"));
assertEquals(say("/fill 10 100 20 12 101 21 cubi:air"), "Filled 12 blocks with Air");
assertEquals(ids(10, 100, 20, 12, 101, 21), ["cubi:air"]);
assert(say("/fill 0 0 0 100 100 100 stone").startsWith("Couldn't fill it"));
assertEquals(game.world.get_block_id(50, 120, 50), "cubi:air");
assertEquals(say("/fill 0 0 0 1 1 1 bworld:nothing"), "There's no block bworld:nothing");
});