Keg
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import type { FermentableRecipe } from "$/mods/bworld/scripts/fermenting.ts";
|
||||
import { opened_menu, test_game } from "./helpers.ts";
|
||||
|
||||
const JUICE = { id: "bworld:juice" };
|
||||
@@ -111,3 +112,52 @@ Deno.test("the keg's fluid handler only fills its input and only drains its outp
|
||||
assertEquals(handler().drain(40, "execute"), { fluid: JUICE, amount: 40 });
|
||||
assertEquals(keg().output, { fluid: JUICE, amount: 60 });
|
||||
});
|
||||
|
||||
Deno.test("a keg ferments 1 mB each time its progress reaches the recipe's ticks, a recipe's worth into all its output", async () => {
|
||||
const { t } = await setup();
|
||||
const [recipe] = t.game.recipes.by_type.get("bworld:fermentable") as unknown as FermentableRecipe[];
|
||||
const handler = () => t.game.mods.block_fluid_handler(0, 100, 0, "top")!;
|
||||
const tile = () => t.game.world.get_tile(0, 100, 0)!;
|
||||
const tanks = () => [handler().fluid_in_tank(0), handler().fluid_in_tank(1)];
|
||||
const ticks = (n: number) => {
|
||||
for (let i = 0; i < n; i++) t.game.tick();
|
||||
};
|
||||
// what the first mb of a recipe's worth make
|
||||
const made = (mb: number) => Math.floor(mb * recipe.output.amount / recipe.input.amount);
|
||||
const input = (amount: number) => amount > 0 ? { fluid: recipe.input.fluid, amount } : undefined;
|
||||
const output = (amount: number) => amount > 0 ? { fluid: recipe.output.fluid, amount } : undefined;
|
||||
|
||||
const amount = recipe.input.amount;
|
||||
handler().fill({ fluid: recipe.input.fluid, amount: amount + 10 }, "execute");
|
||||
ticks(recipe.ticks - 1);
|
||||
assertEquals(tanks(), [input(amount + 10), undefined]);
|
||||
ticks(1);
|
||||
assertEquals(tanks(), [input(amount + 9), output(made(1))]);
|
||||
// a recipe's worth makes all of its output
|
||||
ticks(recipe.ticks * (amount - 1));
|
||||
assertEquals(tanks(), [input(10), output(recipe.output.amount)]);
|
||||
ticks(recipe.ticks * 10 + 1);
|
||||
assertEquals(tanks(), [undefined, output(recipe.output.amount + made(10))]);
|
||||
|
||||
// with nothing it can ferment, it stops ticking, and filling it wakes it
|
||||
assertEquals(tile().ticking, false);
|
||||
handler().fill({ fluid: recipe.input.fluid, amount: 1 }, "execute");
|
||||
assertEquals(tile().ticking, undefined);
|
||||
|
||||
// something without a recipe stays as it is
|
||||
ticks(recipe.ticks + 1);
|
||||
handler().fill({ fluid: { id: "bworld:wine" }, amount: 100 }, "execute");
|
||||
ticks(recipe.ticks * 2);
|
||||
assertEquals(tanks()[0], { fluid: { id: "bworld:wine" }, amount: 100 });
|
||||
});
|
||||
|
||||
Deno.test("a keg doesn't ferment into an output with another fluid in it", async () => {
|
||||
const { t } = await setup();
|
||||
const [recipe] = t.game.recipes.by_type.get("bworld:fermentable") as unknown as FermentableRecipe[];
|
||||
const other = { fluid: { id: "bworld:juice" }, amount: 100 };
|
||||
t.game.mods.block_ref(0, 100, 0, "bworld:keg").data = { output: other };
|
||||
t.game.mods.block_fluid_handler(0, 100, 0, "top")!.fill(recipe.input, "execute");
|
||||
for (let i = 0; i < recipe.ticks * 2; i++) t.game.tick();
|
||||
const keg = t.game.world.get_tile(0, 100, 0)!.mod_data as { input?: unknown; output?: unknown };
|
||||
assertEquals([keg.input, keg.output], [recipe.input, other]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user