Data on /give
This commit is contained in:
+33
-1
@@ -160,7 +160,39 @@ Deno.test("/give suggests item ids as they're typed", async () => {
|
||||
send(1, { type: "chat", text: "/give air" });
|
||||
assertEquals(take(1).find((m) => m.type === "chat").text, "There's no item called air");
|
||||
send(1, { type: "chat", text: "/give" });
|
||||
assertEquals(take(1).find((m) => m.type === "chat").text, "Not enough: /give <item> [<count>]");
|
||||
assertEquals(take(1).find((m) => m.type === "chat").text, "Not enough: /give <item> [<count> [fluid|<data>]]");
|
||||
});
|
||||
|
||||
Deno.test("/give gives items with data, and fluid containers full of a fluid", async () => {
|
||||
const { game, join, take, send } = await test_game("mods");
|
||||
join(1, "alice");
|
||||
take(1);
|
||||
const player = game.players()[0];
|
||||
const give = (text: string) => {
|
||||
player.inventory.clear();
|
||||
send(1, { type: "chat", text });
|
||||
return take(1).find((m) => m.type === "chat").text;
|
||||
};
|
||||
const given = () => player.inventory.to_data().filter((item) => item);
|
||||
|
||||
assertEquals(give('/give bworld:wood_pickaxe 1 {"damage": 5}'), "Gave 1 Wood Pickaxe");
|
||||
assertEquals(given(), [{ id: "bworld:wood_pickaxe", count: 1, data: { damage: 5 } }]);
|
||||
assertEquals(give("/give bworld:stone 1 {oops"), "{oops isn't JSON");
|
||||
|
||||
const juice = { fluid: { id: "bworld:juice", data: { item: "bworld:carrot" } } };
|
||||
assertEquals(
|
||||
give('/give bworld:glass_bottle 3 fluid bworld:juice {"item": "bworld:carrot"}'),
|
||||
"Gave 3 Glass Bottle of Carrot Juice",
|
||||
);
|
||||
assertEquals(given(), [{ id: "bworld:glass_bottle", count: 3, data: juice }]);
|
||||
// a full bucket stacks to 1, and the fluid can be without data
|
||||
assertEquals(give("/give bworld:bucket 2 fluid bworld:juice"), "Gave 2 Bucket of Juice");
|
||||
assertEquals(given().map((item) => item!.count), [1, 1]);
|
||||
assertEquals(give("/give bworld:stone 1 fluid bworld:juice"), "Stone doesn't hold fluids");
|
||||
|
||||
send(1, { type: "suggest", id: 4, text: "/give bworld:bucket 1 fluid bworld:ju" });
|
||||
const suggested = take(1).find((m) => m.type === "suggestions").suggestions;
|
||||
assertEquals(suggested.map((s: { text: string }) => s.text), ["bworld:juice"]);
|
||||
});
|
||||
|
||||
Deno.test("/locatebiome says where the nearest biome of a kind is", async () => {
|
||||
|
||||
Reference in New Issue
Block a user