Proper cutting board
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
// farmer's delight's cutting board: holds a stack of anything, shows it on top, and a knife cuts it one at a time
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { get_state_value } from "$/common/utils.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
const BOARD = [0, 100, 0] as const;
|
||||
|
||||
async function setup(yaw = 0) {
|
||||
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");
|
||||
}
|
||||
t.send(1, { type: "move", x: 2.5, y: 100, z: 2.5, yaw, pitch: 0 });
|
||||
t.send(1, { type: "chat", text: "/give farmersdelight:cutting_board" });
|
||||
t.send(1, { type: "select_slot", slot: 0 });
|
||||
t.send(1, { type: "use_block", x: BOARD[0], y: BOARD[1] - 1, z: BOARD[2], face: "top" });
|
||||
assertEquals(t.game.world.get_block_id(...BOARD), "farmersdelight:cutting_board");
|
||||
|
||||
const use = (slot: number) => {
|
||||
t.send(1, { type: "select_slot", slot });
|
||||
t.send(1, { type: "use_block", x: BOARD[0], y: BOARD[1], z: BOARD[2], face: "top" });
|
||||
};
|
||||
const inventory = () => t.game.players()[0].inventory.to_data().filter((i) => i).map((i) => `${i!.id} ${i!.count}`);
|
||||
const state = (name: string) =>
|
||||
get_state_value(t.game.world.get_block_value(...BOARD), t.game.world.get_block_info(...BOARD)!, name);
|
||||
const on_board = () => {
|
||||
const item = t.game.world.get_tile(...BOARD)?.item;
|
||||
return item ? `${item.id} ${item.count}` : "";
|
||||
};
|
||||
const dropped = () => t.game.item_entities().map((e) => `${e.item.type_id} ${e.item.amount}`).sort();
|
||||
return { ...t, use, inventory, state, on_board, dropped };
|
||||
}
|
||||
|
||||
Deno.test("the board faces whoever placed it", async () => {
|
||||
// looking north it faces south, back at them
|
||||
assertEquals((await setup(0)).state("facing"), 2);
|
||||
// looking west it faces east
|
||||
assertEquals((await setup(Math.PI / 2)).state("facing"), 1);
|
||||
assertEquals((await setup(Math.PI)).state("facing"), 0);
|
||||
assertEquals((await setup(-Math.PI / 2)).state("facing"), 3);
|
||||
});
|
||||
|
||||
Deno.test("a stack goes on the board, and a knife cuts one at a time by its recipe", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "chat", text: "/give bworld:cod 3" });
|
||||
t.send(1, { type: "chat", text: "/give farmersdelight:iron_knife" });
|
||||
|
||||
t.use(0);
|
||||
assertEquals(t.on_board(), "bworld:cod 3");
|
||||
assertEquals(t.inventory(), ["farmersdelight:iron_knife 1"]);
|
||||
|
||||
t.use(1);
|
||||
assertEquals(t.on_board(), "bworld:cod 2");
|
||||
assertEquals(t.dropped(), ["bworld:bone_meal 1", "farmersdelight:cod_slice 2"]);
|
||||
t.use(1);
|
||||
t.use(1);
|
||||
assertEquals(t.on_board(), "");
|
||||
assertEquals(t.dropped().length, 6);
|
||||
|
||||
// on an empty board the knife goes on it, like the java mod, and cutting nothing does nothing
|
||||
t.use(1);
|
||||
assertEquals(t.on_board(), "farmersdelight:iron_knife 1");
|
||||
t.send(1, { type: "chat", text: "/give farmersdelight:stone_knife" });
|
||||
t.use(0);
|
||||
assertEquals(t.on_board(), "farmersdelight:iron_knife 1");
|
||||
assertEquals(t.inventory(), ["farmersdelight:stone_knife 1"]);
|
||||
});
|
||||
|
||||
Deno.test("an empty hand takes it all back, and breaking the board drops it", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "chat", text: "/give farmersdelight:cabbage 5" });
|
||||
t.use(0);
|
||||
assertEquals(t.on_board(), "farmersdelight:cabbage 5");
|
||||
t.use(1);
|
||||
assertEquals(t.on_board(), "");
|
||||
assertEquals(t.inventory(), ["farmersdelight:cabbage 5"]);
|
||||
|
||||
t.use(0);
|
||||
t.game.destroy_block(...BOARD);
|
||||
assertEquals(t.dropped(), ["farmersdelight:cabbage 5", "farmersdelight:cutting_board 1"]);
|
||||
assertEquals(t.game.world.get_tile(...BOARD), undefined);
|
||||
});
|
||||
|
||||
Deno.test("what a block shows goes to players with its chunk and when it changes, and is saved", async () => {
|
||||
const t = await setup();
|
||||
t.send(1, { type: "chat", text: "/give bworld:salmon 2" });
|
||||
// players only hear about blocks in chunks they have
|
||||
for (let i = 0; i < 5; i++) t.game.tick();
|
||||
t.take(1);
|
||||
t.use(0);
|
||||
const shown = (conn: number) =>
|
||||
t.take(conn).filter((m) => m.type === "set_block_item").map((m) => m.item && `${m.item.id} ${m.item.count}`);
|
||||
assertEquals(shown(1), ["bworld:salmon 2"]);
|
||||
|
||||
// someone joining gets it with the chunk
|
||||
t.join(2, "bob");
|
||||
for (let i = 0; i < 5; i++) t.game.tick();
|
||||
assert(shown(2).includes("bworld:salmon 2"));
|
||||
|
||||
const loaded = await test_game("mods", t.game.save());
|
||||
assertEquals(loaded.game.world.get_tile(...BOARD)?.item, { id: "bworld:salmon", count: 2 });
|
||||
|
||||
// breaking it takes it away for everyone
|
||||
t.game.destroy_block(...BOARD);
|
||||
assertEquals(shown(1), [null]);
|
||||
assertEquals(shown(2), [null]);
|
||||
});
|
||||
@@ -29,8 +29,9 @@ Deno.test("the base game loads from mods/bworld", async () => {
|
||||
assertEquals(bworld(EverythingRegistry.entries("blocks")), 42);
|
||||
// 38 items (20 of them tools) plus the item forms of the 37 blocks that have one
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 75);
|
||||
// bworld's 16 (4 wood tools, 7 planks, the fishing rod), the cooking pot and stove are farmersdelight's
|
||||
assertEquals(game.recipes.shaped.length, 18);
|
||||
// bworld's 16 (4 wood tools, 7 planks, the fishing rod), the cooking pot, stove, cutting board and wood knife are
|
||||
// farmersdelight's
|
||||
assertEquals(game.recipes.shaped.length, 20);
|
||||
// every log and fish smelts, every log burns
|
||||
assertEquals(game.recipes.furnace.size, 14);
|
||||
assertEquals(game.recipes.fuel.size, 8);
|
||||
|
||||
Reference in New Issue
Block a user