More pathing

This commit is contained in:
2026-11-21 14:21:02 -03:00
parent 0f58a9cbfe
commit 357f8f2bd4
8 changed files with 314 additions and 24 deletions
+37 -2
View File
@@ -6,9 +6,9 @@
// down. the death block, and the coilhead
import { assert, assertAlmostEquals, assertEquals, assertNotEquals } from "@std/assert";
import { ItemStack } from "@/common/inventory.ts";
import { get_state_value } from "@/common/utils.ts";
import { get_state_value, set_state_value } from "@/common/utils.ts";
import { create_entity } from "@/server/game/entity/entity_types.ts";
import { copy_dir, test_game } from "./helpers.ts";
import { copy_dir, test_game, test_mob } from "./helpers.ts";
const HALF = "dangerous_business:concrete_wall_slab";
const CONNECTS = "dangerous_business:floor_grate";
@@ -17,6 +17,7 @@ const FLOOR = "dangerous_business:concrete_floor";
const DEATH = "dangerous_business:death";
const PIPE = "dangerous_business:double_steel_pipes";
const COILHEAD = "dangerous_business:coilhead";
const FACTORY_DOOR = "dangerous_business:factory_door";
// 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
@@ -157,3 +158,37 @@ Deno.test("a player can't stop a coilhead through a wall", async () => {
// up against the wall, still on its way to her
assert(coilhead.z > -1.5, `it only got to z ${coilhead.z}`);
});
Deno.test("a mob's path goes through a closed factory door, and it waits there until the door opens", async () => {
const { t } = await setup();
const world = t.game.world;
const set_state = (x: number, y: number, z: number, name: string, value: number) =>
t.game.set_block_state(
x,
y,
z,
set_state_value(world.get_block_value(x, y, z), world.get_block_info(x, y, z)!, name, value)! >>> 16,
);
// a wall along z 0 with a closed factory door at x 0, facing so it's across the way
for (let x = -3; x <= 3; x++) {
for (let y = 100; y < 103; y++) t.game.set_block(x, y, 0, FLOOR);
}
for (const [y, half] of [[100, 0], [101, 1]]) {
t.game.set_block(0, y, 0, FACTORY_DOOR);
set_state(0, y, 0, "facing", 0);
set_state(0, y, 0, "half", half);
}
// thin enough to get past the door once it's open
const mob = test_mob(t.game, {}, 0.5, 100, -2.5);
assert(mob.navigation.move_to(0.5, 100, 2.5));
for (let i = 0; i < 60; i++) t.game.tick();
assertEquals(mob.navigation.blocked_by, { x: 0, y: 100, z: 0, id: FACTORY_DOOR });
assert(mob.z < 1);
for (const y of [100, 101]) set_state(0, y, 0, "open", 1);
for (let i = 0; i < 200 && mob.navigation.moving; i++) t.game.tick();
assert(!mob.navigation.moving);
assert(mob.z > 1.5, `it only got to z ${mob.z}`);
assertEquals(mob.navigation.blocked_by, undefined);
});