Remove duplicate code

This commit is contained in:
2026-10-13 11:57:43 -03:00
parent dfc6a6d77b
commit 5165698fe3
50 changed files with 307 additions and 812 deletions
+3 -6
View File
@@ -7,7 +7,7 @@ import { assert, assertEquals } from "@std/assert";
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import { CYCLE_TICKS } from "$/common/time.ts";
import { get_state_value } from "$/common/utils.ts";
import { test_game } from "./helpers.ts";
import { container_items, stone_floor, test_game } from "./helpers.ts";
// deno-lint-ignore no-explicit-any
type Msg = any;
@@ -16,13 +16,10 @@ type Msg = any;
async function setup(items: string[] = []) {
const t = await test_game("mods");
t.join(1, "alice");
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) t.game.set_block(x, 99, z, "bworld:stone");
}
stone_floor(t.game);
t.send(1, { type: "move", x: 0.5, y: 100, z: 0.5, yaw: 0, pitch: 0 });
for (const item of items) t.send(1, { type: "chat", text: `/give ${item}` });
const inventory = () =>
t.take(1).filter((m) => m.type === "container" && m.container === "inventory").at(-1)?.items ?? [];
const inventory = () => container_items(t.take(1), "inventory") ?? [];
const hold = (id: string) => {
const slot = inventory_now().findIndex((i: Msg) => i?.id === id);
assert(slot >= 0 && slot < 9, `${id} isn't in the hotbar`);