Death
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// dangerous business's placement components: slabs and other blocks that go in the top or bottom half, blocks that
|
||||
// join the same block beside them, and blocks that pick some of their looks when placed
|
||||
import { assertEquals } from "@std/assert";
|
||||
// join the same block beside them, and blocks that pick some of their looks when placed. and the death block
|
||||
import { assert, assertEquals, assertNotEquals } from "@std/assert";
|
||||
import { ItemStack } from "@/common/inventory.ts";
|
||||
import { get_state_value } from "@/common/utils.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
@@ -11,6 +12,7 @@ const HALF = "dangerous_business:concrete_wall_slab";
|
||||
const CONNECTS = "dangerous_business:floor_grate";
|
||||
const RANDOM_LOOK = "dangerous_business:water_puddle";
|
||||
const FLOOR = "dangerous_business:concrete_floor";
|
||||
const DEATH = "dangerous_business:death";
|
||||
|
||||
// alice on a concrete floor at y 100, south of 0 100 0 and looking north, holding each of the blocks. it's a game of
|
||||
// its own, which tests playing mods/ leave out
|
||||
@@ -81,3 +83,26 @@ Deno.test("a block with a random look picks the same one wherever it's placed ag
|
||||
for (const look of first) assertEquals(Number(look.split(" ")[0]) < 3, true);
|
||||
assertEquals(new Set(first).size > 1, true);
|
||||
});
|
||||
|
||||
Deno.test("the death block kills a player who walks into it, but not one just beside it", async () => {
|
||||
const { t } = await setup();
|
||||
t.game.set_block(0, 101, 1, DEATH);
|
||||
// touching its side isn't being in it
|
||||
t.send(1, { type: "move", x: 0.5, y: 100, z: 2.3, yaw: 0, pitch: 0 });
|
||||
assert(!t.take(1).some((m) => m.type === "chat" && m.text === "alice died"));
|
||||
|
||||
// its head goes into it
|
||||
t.send(1, { type: "move", x: 0.5, y: 100, z: 1.9, yaw: 0, pitch: 0 });
|
||||
assert(t.take(1).some((m) => m.type === "chat" && m.text === "alice died"));
|
||||
const player = t.game.players().find((p) => p.name === "alice")!;
|
||||
assertEquals(player.health, player.max_health);
|
||||
assertNotEquals([player.x, player.y, player.z], [0.5, 100, 1.9]);
|
||||
});
|
||||
|
||||
Deno.test("the death block takes away an item falling into it", async () => {
|
||||
const { t } = await setup();
|
||||
t.game.set_block(2, 100, 0, DEATH);
|
||||
const item = t.game.spawn_item(2.5, 101.5, 0.5, new ItemStack(FLOOR));
|
||||
for (let i = 0; i < 40 && !item.removed; i++) t.game.tick();
|
||||
assert(item.removed);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user