Add cooking pot from farmer's delight !
This commit is contained in:
@@ -135,6 +135,7 @@ Deno.test("/give suggests item ids as they're typed", async () => {
|
||||
assert(!all.includes("bworld:air"));
|
||||
assertEquals(suggest("/give farmersdelight:tom").suggestions.map((s: { text: string }) => s.text), [
|
||||
"farmersdelight:tomato",
|
||||
"farmersdelight:tomato_sauce",
|
||||
"farmersdelight:tomato_seeds",
|
||||
]);
|
||||
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
// farmer's delight's cooking pot: cooks its recipes over a lit furnace, and serves meals into bowls
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import { bake_model } from "$/common/block_models.ts";
|
||||
import { validate_recipe } from "$/common/mod_data.ts";
|
||||
import { get_state_value, set_state_value } from "$/common/utils.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
const POT = [0, 101, 0] as const;
|
||||
const FURNACE = [0, 100, 0] as const;
|
||||
|
||||
async function setup() {
|
||||
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: 0, pitch: 0 });
|
||||
t.game.set_block(...FURNACE, "bworld:furnace");
|
||||
t.game.set_block(...POT, "farmersdelight:cooking_pot");
|
||||
|
||||
const container = (at: readonly [number, number, number]) => {
|
||||
const id = (t.game.world.get_tile(...at)?.mod_data as { container: string }).container;
|
||||
return t.game.containers.get(id)!;
|
||||
};
|
||||
const pot = container(POT);
|
||||
const put = (slot: number, id: string, count = 1) => pot.set_item(slot, new ItemStack(id, count));
|
||||
const slot = (slot: number) => {
|
||||
const item = pot.get_item(slot);
|
||||
return item ? `${item.type_id} ${item.amount}` : "";
|
||||
};
|
||||
// something to smelt and coal, so the furnace burns
|
||||
const light_furnace = () => {
|
||||
container(FURNACE).set_item(0, new ItemStack("bworld:log", 64));
|
||||
container(FURNACE).set_item(1, new ItemStack("bworld:coal", 64));
|
||||
};
|
||||
const ticks = (n: number) => {
|
||||
for (let i = 0; i < n; i++) t.game.tick();
|
||||
};
|
||||
return { ...t, pot, put, slot, light_furnace, ticks };
|
||||
}
|
||||
|
||||
Deno.test("the pot only cooks over a lit furnace, then serves the meal into bowls", async () => {
|
||||
const t = await setup();
|
||||
t.put(0, "farmersdelight:tomato", 2);
|
||||
t.put(3, "farmersdelight:tomato", 2);
|
||||
|
||||
// cold: nothing happens
|
||||
t.ticks(150);
|
||||
assertEquals(t.slot(0), "farmersdelight:tomato 2");
|
||||
assertEquals(t.slot(6), "");
|
||||
|
||||
t.light_furnace();
|
||||
t.ticks(1);
|
||||
assertEquals(t.game.world.get_block_id(...FURNACE), "bworld:furnace");
|
||||
t.ticks(100);
|
||||
// one sauce, one tomato from each slot, waiting in the pot for a bowl
|
||||
assertEquals(t.slot(6), "farmersdelight:tomato_sauce 1");
|
||||
assertEquals(t.slot(0), "farmersdelight:tomato 1");
|
||||
assertEquals(t.slot(3), "farmersdelight:tomato 1");
|
||||
assertEquals(t.slot(8), "");
|
||||
|
||||
t.ticks(100);
|
||||
assertEquals(t.slot(6), "farmersdelight:tomato_sauce 2");
|
||||
assertEquals(t.slot(0), "");
|
||||
|
||||
// bowls take it out
|
||||
t.put(7, "bworld:bowl", 5);
|
||||
t.ticks(1);
|
||||
assertEquals(t.slot(6), "");
|
||||
assertEquals(t.slot(7), "bworld:bowl 3");
|
||||
assertEquals(t.slot(8), "farmersdelight:tomato_sauce 2");
|
||||
});
|
||||
|
||||
Deno.test("ingredients go in any slots, lists take any of their items, and meals without a container come right out", async () => {
|
||||
const t = await setup();
|
||||
t.light_furnace();
|
||||
t.put(5, "bworld:potato");
|
||||
t.put(1, "farmersdelight:cabbage");
|
||||
t.ticks(101);
|
||||
assertEquals(t.slot(8), "farmersdelight:cabbage_rolls 1");
|
||||
assertEquals(t.slot(6), "");
|
||||
|
||||
// something extra matches nothing
|
||||
t.put(0, "farmersdelight:cabbage");
|
||||
t.put(1, "farmersdelight:onion");
|
||||
t.put(2, "farmersdelight:rice");
|
||||
t.ticks(300);
|
||||
assertEquals(t.slot(8), "farmersdelight:cabbage_rolls 1");
|
||||
assertEquals(t.slot(0), "farmersdelight:cabbage 1");
|
||||
|
||||
// a different meal waits until the pot's empty of the other
|
||||
t.pot.set_item(0, undefined);
|
||||
t.pot.set_item(1, undefined);
|
||||
t.ticks(100);
|
||||
assertEquals(t.slot(6), "farmersdelight:cooked_rice 1");
|
||||
t.put(0, "farmersdelight:tomato", 2);
|
||||
t.put(1, "farmersdelight:tomato", 2);
|
||||
t.ticks(300);
|
||||
assertEquals(t.slot(6), "farmersdelight:cooked_rice 1");
|
||||
assertEquals(t.slot(0), "farmersdelight:tomato 2");
|
||||
});
|
||||
|
||||
Deno.test("holding a bowl serves the meal straight into your hand, and breaking the pot drops everything", async () => {
|
||||
const t = await setup();
|
||||
t.light_furnace();
|
||||
t.put(0, "farmersdelight:rice", 3);
|
||||
t.ticks(301);
|
||||
assertEquals(t.slot(6), "farmersdelight:cooked_rice 3");
|
||||
|
||||
t.send(1, { type: "chat", text: "/give bworld:bowl 2" });
|
||||
const inventory = () => t.game.players()[0].inventory.to_data().filter((i) => i);
|
||||
t.send(1, { type: "select_slot", slot: 0 });
|
||||
t.send(1, { type: "use_block", x: POT[0], y: POT[1], z: POT[2], face: "top" });
|
||||
assertEquals(t.slot(6), "farmersdelight:cooked_rice 2");
|
||||
assertEquals(inventory().map((i) => `${i!.id} ${i!.count}`), ["bworld:bowl 1", "farmersdelight:cooked_rice 1"]);
|
||||
|
||||
t.game.destroy_block(...POT);
|
||||
const dropped = t.game.item_entities().map((e) => `${e.item.type_id} ${e.item.amount}`);
|
||||
assert(dropped.includes("farmersdelight:cooked_rice 2"), String(dropped));
|
||||
});
|
||||
|
||||
Deno.test("mods' own recipe types are accepted, and model faces can turn their texture", () => {
|
||||
assertEquals(validate_recipe({ type: "farmersdelight:cooking", anything: 1 }), []);
|
||||
assertEquals(validate_recipe({ type: "cooking" }).length, 1);
|
||||
|
||||
const face = (rotation?: number) =>
|
||||
bake_model({
|
||||
id: "test:m",
|
||||
elements: [{
|
||||
from: [0, 0, 0],
|
||||
to: [16, 16, 16],
|
||||
faces: { top: { texture: "test:t", uv: [0, 0, 8, 4], rotation } },
|
||||
}],
|
||||
}, undefined)[0].uvs;
|
||||
assertEquals(face(), [0, 4, 8, 4, 8, 0, 0, 0]);
|
||||
// each corner gets the next corner's uv
|
||||
assertEquals(face(90), [8, 4, 8, 0, 0, 0, 0, 4]);
|
||||
assertEquals(face(180), [8, 0, 0, 0, 0, 4, 8, 4]);
|
||||
});
|
||||
|
||||
Deno.test("a stove is placed lit and heats the pot, coal relights it, and standing on it burns", async () => {
|
||||
const t = await setup();
|
||||
const info = () => t.game.world.get_block_info(...FURNACE)!;
|
||||
const lit = () => get_state_value(t.game.world.get_block_value(...FURNACE), info(), "lit");
|
||||
t.game.set_block(...FURNACE, "farmersdelight:stove");
|
||||
assertEquals(lit(), 1);
|
||||
|
||||
t.put(0, "farmersdelight:rice");
|
||||
t.ticks(101);
|
||||
assertEquals(t.slot(6), "farmersdelight:cooked_rice 1");
|
||||
|
||||
// out, it doesn't cook
|
||||
t.game.set_block_state(
|
||||
...FURNACE,
|
||||
set_state_value(t.game.world.get_block_value(...FURNACE), info(), "lit", 0)! >>> 16,
|
||||
);
|
||||
t.put(0, "farmersdelight:rice");
|
||||
t.ticks(150);
|
||||
assertEquals(t.slot(6), "farmersdelight:cooked_rice 1");
|
||||
|
||||
// coal lights it again, used up
|
||||
t.send(1, { type: "chat", text: "/give bworld:coal 2" });
|
||||
t.send(1, { type: "select_slot", slot: 0 });
|
||||
t.send(1, { type: "use_block", x: FURNACE[0], y: FURNACE[1], z: FURNACE[2], face: "north" });
|
||||
assertEquals(lit(), 1);
|
||||
assertEquals(t.game.players()[0].inventory.get_item(0)?.amount, 1);
|
||||
// already lit, coal does nothing
|
||||
t.send(1, { type: "use_block", x: FURNACE[0], y: FURNACE[1], z: FURNACE[2], face: "north" });
|
||||
assertEquals(t.game.players()[0].inventory.get_item(0)?.amount, 1);
|
||||
|
||||
// standing on it: 1 every 10 ticks
|
||||
t.game.destroy_block(...POT);
|
||||
t.send(1, { type: "move", x: 0.5, y: 101, z: 0.5, yaw: 0, pitch: 0 });
|
||||
const health = () => t.game.players()[0].vitals.health;
|
||||
// (full hunger heals some of it back meanwhile, like minecraft)
|
||||
const before = health();
|
||||
t.ticks(40);
|
||||
assert(health() < before, `${health()} of ${before}`);
|
||||
t.send(1, { type: "move", x: 2.5, y: 100, z: 2.5, yaw: 0, pitch: 0 });
|
||||
const off = health();
|
||||
t.ticks(40);
|
||||
assert(health() >= off);
|
||||
});
|
||||
@@ -25,9 +25,10 @@ Deno.test("the base game loads from mods/bworld", async () => {
|
||||
const { game } = await test_game("mods");
|
||||
const bworld = (entries: [string, unknown][]) => entries.filter(([id]) => id.startsWith("bworld:")).length;
|
||||
assertEquals(bworld(EverythingRegistry.entries("blocks")), 23);
|
||||
// 17 items plus the item forms of the 18 blocks that have one
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 35);
|
||||
assertEquals(game.recipes.shaped.length, 5);
|
||||
// 18 items plus the item forms of the 18 blocks that have one
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 36);
|
||||
// the bowl is bworld's 6th, the cooking pot and stove are farmersdelight's
|
||||
assertEquals(game.recipes.shaped.length, 8);
|
||||
assertEquals(game.recipes.furnace.size, 6);
|
||||
assertEquals(game.recipes.fuel.size, 2);
|
||||
assertEquals(EverythingRegistry.get<BlockRegistry>("blocks", "bworld:water")?.replaceable, true);
|
||||
|
||||
Reference in New Issue
Block a user