Glass bottle, buckets and juice !
This commit is contained in:
@@ -361,6 +361,24 @@ Deno.test("a bucket picks up a water source but not flowing water, and a water b
|
||||
assertEquals(t.game.world.get_block_value(-2, 100, 0) >>> 16, 0);
|
||||
});
|
||||
|
||||
Deno.test("only an empty bucket picks up water, and from a stack the water bucket goes in the inventory", async () => {
|
||||
const t = await setup();
|
||||
const player = t.game.players()[0];
|
||||
const slots = () => player.inventory.to_data().flatMap((item) => item ? [[item.id, item.count]] : []);
|
||||
t.game.set_block(1, 100, 0, "bworld:water");
|
||||
|
||||
t.game.give(player, "bworld:bucket", 1, { fluid: { id: "bworld:juice" } });
|
||||
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
|
||||
assertEquals(t.game.world.get_block_id(1, 100, 0), "bworld:water");
|
||||
assertEquals(slots(), [["bworld:bucket", 1]]);
|
||||
|
||||
player.inventory.set_item(0, undefined);
|
||||
t.game.give(player, "bworld:bucket", 3);
|
||||
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
|
||||
assertEquals(t.game.world.get_block_id(1, 100, 0), "bworld:air");
|
||||
assertEquals(slots(), [["bworld:bucket", 2], ["bworld:water_bucket", 1]]);
|
||||
});
|
||||
|
||||
Deno.test("a bucket picks up a lava source too, and a lava bucket puts one back", async () => {
|
||||
const t = await setup([["bworld:bucket", 1]]);
|
||||
const held = () => t.game.players()[0].held_item?.type_id;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// juice: one fluid named and colored after the bworld:juiceable item in its data
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import type { FluidJson } from "$/common/mod_data.ts";
|
||||
import { display_name } from "$/common/utils.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
// mods/bworld and another mod with a juiceable berry, so there's always one whatever bworld's items have
|
||||
async function setup() {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_juice_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
const write = (path: string, json: unknown) => {
|
||||
Deno.mkdirSync(`${dir}/testberries/${path.split("/").slice(0, -1).join("/")}`, { recursive: true });
|
||||
Deno.writeTextFileSync(`${dir}/testberries/${path}`, JSON.stringify(json));
|
||||
};
|
||||
write("manifest.json", {
|
||||
format_version: 1,
|
||||
id: "testberries",
|
||||
name: "Test Berries",
|
||||
version: "1.0.0",
|
||||
dependencies: [{ id: "bworld", version: "*" }],
|
||||
});
|
||||
write("items/cloudberry.json", {
|
||||
format_version: 1,
|
||||
item: {
|
||||
id: "testberries:cloudberry",
|
||||
texture: "engine:missing",
|
||||
components: { "bworld:juiceable": { juice: 100, color: "#e0a030" } },
|
||||
},
|
||||
});
|
||||
const { game } = await test_game(dir);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
return game.mods.fluid_rules.api();
|
||||
}
|
||||
|
||||
Deno.test("juice made from any item with bworld:juiceable is named after it, in the component's color", async () => {
|
||||
const fluids = await setup();
|
||||
const juiceable = EverythingRegistry.entries<ItemRegistry>("items")
|
||||
.filter(([, item]) => item.components?.["bworld:juiceable"]);
|
||||
assert(juiceable.length > 0);
|
||||
for (const [id, item] of juiceable) {
|
||||
const juice = { id: "bworld:juice", data: { item: id } };
|
||||
assertEquals(fluids.name(juice), `${display_name(id)} Juice`);
|
||||
assertEquals(fluids.color(juice), (item.components!["bworld:juiceable"] as { color: string }).color);
|
||||
}
|
||||
|
||||
// juice that isn't from an item is plain juice
|
||||
const plain = EverythingRegistry.get<FluidJson>("fluids", "bworld:juice")!;
|
||||
assertEquals([fluids.name({ id: "bworld:juice" }), fluids.color({ id: "bworld:juice" })], [
|
||||
plain.name,
|
||||
plain.color,
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user