From 9e48a42c1f743daebd2f9e4f6eaa9168c4919837 Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 1 Nov 2026 22:48:49 -0300 Subject: [PATCH] Make tool upgrades cost money --- docs/modding/resources/recipes.md | 6 +-- mods/bworld/recipes/smithing_cobalt_axe.json | 4 ++ mods/bworld/recipes/smithing_cobalt_hoe.json | 4 ++ .../bworld/recipes/smithing_cobalt_knife.json | 4 ++ .../recipes/smithing_cobalt_pickaxe.json | 4 ++ .../recipes/smithing_cobalt_shovel.json | 4 ++ .../recipes/smithing_cobalt_watering_can.json | 4 ++ mods/bworld/recipes/smithing_copper_axe.json | 4 ++ mods/bworld/recipes/smithing_copper_hoe.json | 4 ++ .../bworld/recipes/smithing_copper_knife.json | 4 ++ .../recipes/smithing_copper_pickaxe.json | 4 ++ .../recipes/smithing_copper_shovel.json | 4 ++ .../recipes/smithing_copper_watering_can.json | 4 ++ mods/bworld/recipes/smithing_gold_axe.json | 4 ++ mods/bworld/recipes/smithing_gold_hoe.json | 4 ++ mods/bworld/recipes/smithing_gold_knife.json | 4 ++ .../bworld/recipes/smithing_gold_pickaxe.json | 4 ++ mods/bworld/recipes/smithing_gold_shovel.json | 4 ++ .../recipes/smithing_gold_watering_can.json | 4 ++ mods/bworld/recipes/smithing_iron_axe.json | 4 ++ mods/bworld/recipes/smithing_iron_hoe.json | 4 ++ mods/bworld/recipes/smithing_iron_knife.json | 4 ++ .../bworld/recipes/smithing_iron_pickaxe.json | 4 ++ mods/bworld/recipes/smithing_iron_shovel.json | 4 ++ .../recipes/smithing_iron_watering_can.json | 4 ++ mods/bworld/recipes/smithing_stone_axe.json | 4 ++ mods/bworld/recipes/smithing_stone_hoe.json | 4 ++ mods/bworld/recipes/smithing_stone_knife.json | 4 ++ .../recipes/smithing_stone_pickaxe.json | 4 ++ .../bworld/recipes/smithing_stone_shovel.json | 4 ++ .../recipes/smithing_stone_watering_can.json | 4 ++ mods/bworld/scripts/server.ts | 13 ++++-- mods/bworld/scripts/smithing.ts | 15 ++++--- mods/recipe_viewer/scripts/categories.ts | 2 +- mods/recipe_viewer/scripts/recipes.ts | 2 +- tests/base_game_test.ts | 44 ++++++++++++++++--- tests/recipe_viewer_test.ts | 6 ++- 37 files changed, 185 insertions(+), 23 deletions(-) diff --git a/docs/modding/resources/recipes.md b/docs/modding/resources/recipes.md index bf947f7..c73d534 100644 --- a/docs/modding/resources/recipes.md +++ b/docs/modding/resources/recipes.md @@ -68,9 +68,9 @@ For the smithing table, which upgrades a tool. It's the base game's own type, re } ``` -An optional `addition` is a third item it also takes. Upgrading uses up the tool, `count` of the material and the -addition, and the result keeps the tool's `data`, like its [durability](../items/tools.md#durability). Two smithing -recipes with the same tool, material and addition are an error. +An optional `addition` is a third item it also takes, as `{ "id", "count" }` like the material. Upgrading uses up the +tool and `count` of the material and the addition, and the result keeps the tool's `data`, like its +[durability](../items/tools.md#durability). Two smithing recipes with the same tool, material and addition are an error. ## Stonecutting: `bworld:stonecutting` diff --git a/mods/bworld/recipes/smithing_cobalt_axe.json b/mods/bworld/recipes/smithing_cobalt_axe.json index 7065dde..e42acec 100644 --- a/mods/bworld/recipes/smithing_cobalt_axe.json +++ b/mods/bworld/recipes/smithing_cobalt_axe.json @@ -7,6 +7,10 @@ "id": "bworld:cobalt_ingot", "count": 5 }, + "addition": { + "id": "bworld:cobalt_coin", + "count": 2 + }, "result": "bworld:cobalt_axe" } } diff --git a/mods/bworld/recipes/smithing_cobalt_hoe.json b/mods/bworld/recipes/smithing_cobalt_hoe.json index 09c8bd0..af95b4c 100644 --- a/mods/bworld/recipes/smithing_cobalt_hoe.json +++ b/mods/bworld/recipes/smithing_cobalt_hoe.json @@ -7,6 +7,10 @@ "id": "bworld:cobalt_ingot", "count": 5 }, + "addition": { + "id": "bworld:cobalt_coin", + "count": 2 + }, "result": "bworld:cobalt_hoe" } } diff --git a/mods/bworld/recipes/smithing_cobalt_knife.json b/mods/bworld/recipes/smithing_cobalt_knife.json index 97b1e61..3ed1643 100644 --- a/mods/bworld/recipes/smithing_cobalt_knife.json +++ b/mods/bworld/recipes/smithing_cobalt_knife.json @@ -7,6 +7,10 @@ "id": "bworld:cobalt_ingot", "count": 5 }, + "addition": { + "id": "bworld:cobalt_coin", + "count": 2 + }, "result": "bworld:cobalt_knife" } } diff --git a/mods/bworld/recipes/smithing_cobalt_pickaxe.json b/mods/bworld/recipes/smithing_cobalt_pickaxe.json index 897f034..b5d49a4 100644 --- a/mods/bworld/recipes/smithing_cobalt_pickaxe.json +++ b/mods/bworld/recipes/smithing_cobalt_pickaxe.json @@ -7,6 +7,10 @@ "id": "bworld:cobalt_ingot", "count": 5 }, + "addition": { + "id": "bworld:cobalt_coin", + "count": 2 + }, "result": "bworld:cobalt_pickaxe" } } diff --git a/mods/bworld/recipes/smithing_cobalt_shovel.json b/mods/bworld/recipes/smithing_cobalt_shovel.json index 5582bad..2dc2a76 100644 --- a/mods/bworld/recipes/smithing_cobalt_shovel.json +++ b/mods/bworld/recipes/smithing_cobalt_shovel.json @@ -7,6 +7,10 @@ "id": "bworld:cobalt_ingot", "count": 5 }, + "addition": { + "id": "bworld:cobalt_coin", + "count": 2 + }, "result": "bworld:cobalt_shovel" } } diff --git a/mods/bworld/recipes/smithing_cobalt_watering_can.json b/mods/bworld/recipes/smithing_cobalt_watering_can.json index 8fc4c4e..5da1d88 100644 --- a/mods/bworld/recipes/smithing_cobalt_watering_can.json +++ b/mods/bworld/recipes/smithing_cobalt_watering_can.json @@ -7,6 +7,10 @@ "id": "bworld:cobalt_ingot", "count": 5 }, + "addition": { + "id": "bworld:cobalt_coin", + "count": 2 + }, "result": "bworld:cobalt_watering_can" } } diff --git a/mods/bworld/recipes/smithing_copper_axe.json b/mods/bworld/recipes/smithing_copper_axe.json index d713ffd..f5e0364 100644 --- a/mods/bworld/recipes/smithing_copper_axe.json +++ b/mods/bworld/recipes/smithing_copper_axe.json @@ -7,6 +7,10 @@ "id": "bworld:copper_ingot", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 5 + }, "result": "bworld:copper_axe" } } diff --git a/mods/bworld/recipes/smithing_copper_hoe.json b/mods/bworld/recipes/smithing_copper_hoe.json index 6397daa..bd132d5 100644 --- a/mods/bworld/recipes/smithing_copper_hoe.json +++ b/mods/bworld/recipes/smithing_copper_hoe.json @@ -7,6 +7,10 @@ "id": "bworld:copper_ingot", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 5 + }, "result": "bworld:copper_hoe" } } diff --git a/mods/bworld/recipes/smithing_copper_knife.json b/mods/bworld/recipes/smithing_copper_knife.json index 5f1c245..3603221 100644 --- a/mods/bworld/recipes/smithing_copper_knife.json +++ b/mods/bworld/recipes/smithing_copper_knife.json @@ -7,6 +7,10 @@ "id": "bworld:copper_ingot", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 5 + }, "result": "bworld:copper_knife" } } diff --git a/mods/bworld/recipes/smithing_copper_pickaxe.json b/mods/bworld/recipes/smithing_copper_pickaxe.json index c19a098..744e4d7 100644 --- a/mods/bworld/recipes/smithing_copper_pickaxe.json +++ b/mods/bworld/recipes/smithing_copper_pickaxe.json @@ -7,6 +7,10 @@ "id": "bworld:copper_ingot", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 5 + }, "result": "bworld:copper_pickaxe" } } diff --git a/mods/bworld/recipes/smithing_copper_shovel.json b/mods/bworld/recipes/smithing_copper_shovel.json index 5e9b4de..caac14b 100644 --- a/mods/bworld/recipes/smithing_copper_shovel.json +++ b/mods/bworld/recipes/smithing_copper_shovel.json @@ -7,6 +7,10 @@ "id": "bworld:copper_ingot", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 5 + }, "result": "bworld:copper_shovel" } } diff --git a/mods/bworld/recipes/smithing_copper_watering_can.json b/mods/bworld/recipes/smithing_copper_watering_can.json index 215aa2f..1c0aaf5 100644 --- a/mods/bworld/recipes/smithing_copper_watering_can.json +++ b/mods/bworld/recipes/smithing_copper_watering_can.json @@ -7,6 +7,10 @@ "id": "bworld:copper_ingot", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 5 + }, "result": "bworld:copper_watering_can" } } diff --git a/mods/bworld/recipes/smithing_gold_axe.json b/mods/bworld/recipes/smithing_gold_axe.json index b3905d8..a61eb12 100644 --- a/mods/bworld/recipes/smithing_gold_axe.json +++ b/mods/bworld/recipes/smithing_gold_axe.json @@ -7,6 +7,10 @@ "id": "bworld:gold_ingot", "count": 5 }, + "addition": { + "id": "bworld:gold_coin", + "count": 1 + }, "result": "bworld:gold_axe" } } diff --git a/mods/bworld/recipes/smithing_gold_hoe.json b/mods/bworld/recipes/smithing_gold_hoe.json index 8629461..f722fe6 100644 --- a/mods/bworld/recipes/smithing_gold_hoe.json +++ b/mods/bworld/recipes/smithing_gold_hoe.json @@ -7,6 +7,10 @@ "id": "bworld:gold_ingot", "count": 5 }, + "addition": { + "id": "bworld:gold_coin", + "count": 1 + }, "result": "bworld:gold_hoe" } } diff --git a/mods/bworld/recipes/smithing_gold_knife.json b/mods/bworld/recipes/smithing_gold_knife.json index 0b609d1..7d38a61 100644 --- a/mods/bworld/recipes/smithing_gold_knife.json +++ b/mods/bworld/recipes/smithing_gold_knife.json @@ -7,6 +7,10 @@ "id": "bworld:gold_ingot", "count": 5 }, + "addition": { + "id": "bworld:gold_coin", + "count": 1 + }, "result": "bworld:gold_knife" } } diff --git a/mods/bworld/recipes/smithing_gold_pickaxe.json b/mods/bworld/recipes/smithing_gold_pickaxe.json index cadea80..13acfd3 100644 --- a/mods/bworld/recipes/smithing_gold_pickaxe.json +++ b/mods/bworld/recipes/smithing_gold_pickaxe.json @@ -7,6 +7,10 @@ "id": "bworld:gold_ingot", "count": 5 }, + "addition": { + "id": "bworld:gold_coin", + "count": 1 + }, "result": "bworld:gold_pickaxe" } } diff --git a/mods/bworld/recipes/smithing_gold_shovel.json b/mods/bworld/recipes/smithing_gold_shovel.json index e0adc73..9199b13 100644 --- a/mods/bworld/recipes/smithing_gold_shovel.json +++ b/mods/bworld/recipes/smithing_gold_shovel.json @@ -7,6 +7,10 @@ "id": "bworld:gold_ingot", "count": 5 }, + "addition": { + "id": "bworld:gold_coin", + "count": 1 + }, "result": "bworld:gold_shovel" } } diff --git a/mods/bworld/recipes/smithing_gold_watering_can.json b/mods/bworld/recipes/smithing_gold_watering_can.json index 57cdf3d..f800115 100644 --- a/mods/bworld/recipes/smithing_gold_watering_can.json +++ b/mods/bworld/recipes/smithing_gold_watering_can.json @@ -7,6 +7,10 @@ "id": "bworld:gold_ingot", "count": 5 }, + "addition": { + "id": "bworld:gold_coin", + "count": 1 + }, "result": "bworld:gold_watering_can" } } diff --git a/mods/bworld/recipes/smithing_iron_axe.json b/mods/bworld/recipes/smithing_iron_axe.json index 0b53047..89d2041 100644 --- a/mods/bworld/recipes/smithing_iron_axe.json +++ b/mods/bworld/recipes/smithing_iron_axe.json @@ -7,6 +7,10 @@ "id": "bworld:iron_ingot", "count": 5 }, + "addition": { + "id": "bworld:iron_coin", + "count": 2 + }, "result": "bworld:iron_axe" } } diff --git a/mods/bworld/recipes/smithing_iron_hoe.json b/mods/bworld/recipes/smithing_iron_hoe.json index 104cb61..bb164bd 100644 --- a/mods/bworld/recipes/smithing_iron_hoe.json +++ b/mods/bworld/recipes/smithing_iron_hoe.json @@ -7,6 +7,10 @@ "id": "bworld:iron_ingot", "count": 5 }, + "addition": { + "id": "bworld:iron_coin", + "count": 2 + }, "result": "bworld:iron_hoe" } } diff --git a/mods/bworld/recipes/smithing_iron_knife.json b/mods/bworld/recipes/smithing_iron_knife.json index ed49e45..cf2e595 100644 --- a/mods/bworld/recipes/smithing_iron_knife.json +++ b/mods/bworld/recipes/smithing_iron_knife.json @@ -7,6 +7,10 @@ "id": "bworld:iron_ingot", "count": 5 }, + "addition": { + "id": "bworld:iron_coin", + "count": 2 + }, "result": "bworld:iron_knife" } } diff --git a/mods/bworld/recipes/smithing_iron_pickaxe.json b/mods/bworld/recipes/smithing_iron_pickaxe.json index 1a70765..3c3a8d5 100644 --- a/mods/bworld/recipes/smithing_iron_pickaxe.json +++ b/mods/bworld/recipes/smithing_iron_pickaxe.json @@ -7,6 +7,10 @@ "id": "bworld:iron_ingot", "count": 5 }, + "addition": { + "id": "bworld:iron_coin", + "count": 2 + }, "result": "bworld:iron_pickaxe" } } diff --git a/mods/bworld/recipes/smithing_iron_shovel.json b/mods/bworld/recipes/smithing_iron_shovel.json index 955d76f..da65029 100644 --- a/mods/bworld/recipes/smithing_iron_shovel.json +++ b/mods/bworld/recipes/smithing_iron_shovel.json @@ -7,6 +7,10 @@ "id": "bworld:iron_ingot", "count": 5 }, + "addition": { + "id": "bworld:iron_coin", + "count": 2 + }, "result": "bworld:iron_shovel" } } diff --git a/mods/bworld/recipes/smithing_iron_watering_can.json b/mods/bworld/recipes/smithing_iron_watering_can.json index 22b1599..7d1f0c2 100644 --- a/mods/bworld/recipes/smithing_iron_watering_can.json +++ b/mods/bworld/recipes/smithing_iron_watering_can.json @@ -7,6 +7,10 @@ "id": "bworld:iron_ingot", "count": 5 }, + "addition": { + "id": "bworld:iron_coin", + "count": 2 + }, "result": "bworld:iron_watering_can" } } diff --git a/mods/bworld/recipes/smithing_stone_axe.json b/mods/bworld/recipes/smithing_stone_axe.json index ca2d99d..6e908de 100644 --- a/mods/bworld/recipes/smithing_stone_axe.json +++ b/mods/bworld/recipes/smithing_stone_axe.json @@ -7,6 +7,10 @@ "id": "bworld:stone", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 1 + }, "result": "bworld:stone_axe" } } diff --git a/mods/bworld/recipes/smithing_stone_hoe.json b/mods/bworld/recipes/smithing_stone_hoe.json index 9eaa02a..bb87f31 100644 --- a/mods/bworld/recipes/smithing_stone_hoe.json +++ b/mods/bworld/recipes/smithing_stone_hoe.json @@ -7,6 +7,10 @@ "id": "bworld:stone", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 1 + }, "result": "bworld:stone_hoe" } } diff --git a/mods/bworld/recipes/smithing_stone_knife.json b/mods/bworld/recipes/smithing_stone_knife.json index b701b7c..80f208a 100644 --- a/mods/bworld/recipes/smithing_stone_knife.json +++ b/mods/bworld/recipes/smithing_stone_knife.json @@ -7,6 +7,10 @@ "id": "bworld:stone", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 1 + }, "result": "bworld:stone_knife" } } diff --git a/mods/bworld/recipes/smithing_stone_pickaxe.json b/mods/bworld/recipes/smithing_stone_pickaxe.json index 0c3d989..3e15760 100644 --- a/mods/bworld/recipes/smithing_stone_pickaxe.json +++ b/mods/bworld/recipes/smithing_stone_pickaxe.json @@ -7,6 +7,10 @@ "id": "bworld:stone", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 1 + }, "result": "bworld:stone_pickaxe" } } diff --git a/mods/bworld/recipes/smithing_stone_shovel.json b/mods/bworld/recipes/smithing_stone_shovel.json index 24c3f1f..bb22ac8 100644 --- a/mods/bworld/recipes/smithing_stone_shovel.json +++ b/mods/bworld/recipes/smithing_stone_shovel.json @@ -7,6 +7,10 @@ "id": "bworld:stone", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 1 + }, "result": "bworld:stone_shovel" } } diff --git a/mods/bworld/recipes/smithing_stone_watering_can.json b/mods/bworld/recipes/smithing_stone_watering_can.json index f12f9fb..d200ff8 100644 --- a/mods/bworld/recipes/smithing_stone_watering_can.json +++ b/mods/bworld/recipes/smithing_stone_watering_can.json @@ -7,6 +7,10 @@ "id": "bworld:stone", "count": 5 }, + "addition": { + "id": "bworld:brass_coin", + "count": 1 + }, "result": "bworld:stone_watering_can" } } diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index 0e33e54..1785b89 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -295,7 +295,7 @@ function register_furnace(ctx: ServerContext) { }); } -// smithing table: a tool, some of a material and maybe a third item make a better tool, see smithing.ts. +// smithing table: a tool, some of a material and maybe some of a third item make a better tool, see smithing.ts. // every player gets their own slots, and what's left in them goes back to the player when they close it const TOOL = 0; @@ -439,7 +439,14 @@ function register_smithing_table(ctx: ServerContext) { const addition = container.get(ADDITION); if (!tool || !material) return undefined; const recipe = ctx.recipes.find(SMITHING, { tool, material, addition }); - return recipe && { result: recipe.result, material_count: recipe.material.count, tool, material, addition }; + return recipe && { + result: recipe.result, + material_count: recipe.material.count, + addition_count: recipe.addition?.count ?? 0, + tool, + material, + addition, + }; }; // the result slot shows what taking it would give, the upgraded tool keeps the old one's data @@ -470,7 +477,7 @@ function register_smithing_table(ctx: ServerContext) { if (!recipe || recipe.result !== item.id) return false; recipe.tool.count -= 1; recipe.material.count -= recipe.material_count; - if (recipe.addition) recipe.addition.count -= 1; + if (recipe.addition) recipe.addition.count -= recipe.addition_count; return true; }, }); diff --git a/mods/bworld/scripts/smithing.ts b/mods/bworld/scripts/smithing.ts index fe9887d..13cce01 100644 --- a/mods/bworld/scripts/smithing.ts +++ b/mods/bworld/scripts/smithing.ts @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later -// smithing recipes: the smithing table upgrades a tool with some of a material and maybe one more item. the type is -// registered by the shared script, so the server's menu and anything on a client find them the same way +// smithing recipes: the smithing table upgrades a tool with some of a material and maybe some of one more item. the +// type is registered by the shared script, so the server's menu and anything on a client find them the same way import type { ItemStack, SharedContext } from "bworld/shared"; export const SMITHING = "bworld:smithing"; @@ -10,7 +10,7 @@ export const SMITHING = "bworld:smithing"; export interface SmithingRecipe { tool: string; material: { id: string; count: number }; - addition?: string; + addition?: { id: string; count: number }; result: string; } @@ -31,15 +31,16 @@ export function register_smithing(ctx: SharedContext) { material: read.stack(json.material, "material"), result: read.item(json.result, "result"), }; - if (json.addition !== undefined) recipe.addition = read.item(json.addition, "addition"); - const inputs = `${recipe.tool} ${recipe.material.id} ${recipe.addition}`; + if (json.addition !== undefined) recipe.addition = read.stack(json.addition, "addition"); + const inputs = `${recipe.tool} ${recipe.material.id} ${recipe.addition?.id}`; if (seen.has(inputs)) throw new Error(`there's already one for ${recipe.tool} with ${recipe.material.id}`); seen.add(inputs); return recipe; }, - // with enough of the material + // with enough of the material and the addition matches: (recipe, input) => recipe.tool === input.tool.id && recipe.material.id === input.material.id && - input.material.count >= recipe.material.count && recipe.addition === input.addition?.id, + input.material.count >= recipe.material.count && recipe.addition?.id === input.addition?.id && + (input.addition?.count ?? 0) >= (recipe.addition?.count ?? 0), }); } diff --git a/mods/recipe_viewer/scripts/categories.ts b/mods/recipe_viewer/scripts/categories.ts index a64bc0c..b3715ed 100644 --- a/mods/recipe_viewer/scripts/categories.ts +++ b/mods/recipe_viewer/scripts/categories.ts @@ -100,7 +100,7 @@ function base_categories(tags: TagApi): RecipeCategory[] { draw(recipe, layout) { layout.slot({ ids: [recipe.tool], count: 1 }, 0, 0); layout.slot(stack(recipe.material), SLOT, 0); - layout.slot(recipe.addition ? { ids: [recipe.addition], count: 1 } : undefined, SLOT * 2, 0); + layout.slot(recipe.addition && stack(recipe.addition), SLOT * 2, 0); layout.texture("bworld:arrow_full", 61, 1, ARROW, ARROW); layout.slot({ ids: [recipe.result], count: 1 }, 90, 0); }, diff --git a/mods/recipe_viewer/scripts/recipes.ts b/mods/recipe_viewer/scripts/recipes.ts index 6e51c58..a925aca 100644 --- a/mods/recipe_viewer/scripts/recipes.ts +++ b/mods/recipe_viewer/scripts/recipes.ts @@ -60,7 +60,7 @@ export function inputs(recipe: Recipe, tags: TagApi): Ingredient[] { return [{ ids: tags.expand(recipe.item), count: 1 }]; case "bworld:smithing": return [{ ids: [recipe.tool], count: 1 }, stack(recipe.material)].concat( - recipe.addition ? [{ ids: [recipe.addition], count: 1 }] : [], + recipe.addition ? [stack(recipe.addition)] : [], ); default: { const { grid, extras } = mod_recipe_inputs(recipe, tags); diff --git a/tests/base_game_test.ts b/tests/base_game_test.ts index ecff7a5..b6220a5 100644 --- a/tests/base_game_test.ts +++ b/tests/base_game_test.ts @@ -251,12 +251,13 @@ Deno.test("items are called by their name, or by one made from their id", async assertEquals(display_name("test:thing"), "A Thing"); }); -Deno.test("a smithing table upgrades a wooden pickaxe with 5 stone, using up exactly that", async () => { - const t = await setup([["bworld:wood_pickaxe", 1], ["bworld:stone", 7]]); +Deno.test("a smithing table upgrades a wooden pickaxe with 5 stone and a brass coin, using up exactly that", async () => { + const t = await setup([["bworld:wood_pickaxe", 1], ["bworld:stone", 7], ["bworld:brass_coin", 1]]); t.game.set_block(1, 100, 0, "bworld:smithing_table"); let messages = t.take(1); const pickaxe = slot_of(messages, "bworld:wood_pickaxe"); const stone = slot_of(messages, "bworld:stone"); + const coin = slot_of(messages, "bworld:brass_coin"); // mods' own, like the player's curios const containers = t.game.containers.size; @@ -270,9 +271,14 @@ Deno.test("a smithing table upgrades a wooden pickaxe with 5 stone, using up exa click(t, opened, 3); assertEquals(t.take(1).filter((m) => m.type === "cursor").at(-1)?.item ?? null, null); - // the result shows up once there's enough stone, and taking it uses up the pickaxe and 5 stone + // nor with the stone but not the coin move_to_menu(t, opened, stone, 1); t.game.tick(); + assertEquals(menu_items(t.take(1))[3], null); + + // the result shows up once the coin is in, and taking it uses up the pickaxe, 5 stone and the coin + move_to_menu(t, opened, coin, 2); + t.game.tick(); assertEquals(menu_items(t.take(1))[3], { id: "bworld:stone_pickaxe", count: 1 }); click(t, opened, 3); messages = t.take(1); @@ -289,14 +295,38 @@ Deno.test("a smithing table upgrades a wooden pickaxe with 5 stone, using up exa assertEquals(t.game.containers.size, containers, "its slots are gone"); }); -Deno.test("a smithing result can't be taken once its inputs are gone, even before it updates", async () => { - const t = await setup([["bworld:wood_pickaxe", 1], ["bworld:stone", 5]]); +Deno.test("a smithing addition needs its whole count, and all of it is used up", async () => { + const t = await setup([["bworld:stone_pickaxe", 1], ["bworld:copper_ingot", 5], ["bworld:brass_coin", 6]]); t.game.set_block(1, 100, 0, "bworld:smithing_table"); const messages = t.take(1); t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" }); const opened = opened_menu(t.take(1)); - move_to_menu(t, opened, slot_of(messages, "bworld:wood_pickaxe"), 0); - move_to_menu(t, opened, slot_of(messages, "bworld:stone"), 1); + move_to_menu(t, opened, slot_of(messages, "bworld:stone_pickaxe"), 0); + move_to_menu(t, opened, slot_of(messages, "bworld:copper_ingot"), 1); + + // right-clicking the coins onto the slot puts down one at a time + const coins = inventory_slot(opened, slot_of(messages, "bworld:brass_coin")); + click(t, opened, coins); + for (let i = 0; i < 4; i++) t.send(1, { type: "click", menu: opened.id, slot: 2, button: 2 }); + t.game.tick(); + assertEquals(menu_items(t.take(1))[3], null); + + t.send(1, { type: "click", menu: opened.id, slot: 2, button: 2 }); + t.game.tick(); + assertEquals(menu_items(t.take(1))[3], { id: "bworld:copper_pickaxe", count: 1 }); + click(t, opened, coins); + click(t, opened, 3); + assertEquals(menu_items(t.take(1)).slice(0, 4), [null, null, null, null]); +}); + +Deno.test("a smithing result can't be taken once its inputs are gone, even before it updates", async () => { + const t = await setup([["bworld:copper_pickaxe", 1], ["bworld:iron_ingot", 5]]); + t.game.set_block(1, 100, 0, "bworld:smithing_table"); + const messages = t.take(1); + t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" }); + const opened = opened_menu(t.take(1)); + move_to_menu(t, opened, slot_of(messages, "bworld:copper_pickaxe"), 0); + move_to_menu(t, opened, slot_of(messages, "bworld:iron_ingot"), 1); t.game.tick(); // take the pickaxe back out and try the result in the same tick diff --git a/tests/recipe_viewer_test.ts b/tests/recipe_viewer_test.ts index 47343f8..301572c 100644 --- a/tests/recipe_viewer_test.ts +++ b/tests/recipe_viewer_test.ts @@ -88,7 +88,11 @@ Deno.test("the recipe viewer finds what makes and uses an item, in any recipe ty r.type === "bworld:smelting" && outputs(r)[0].ids[0] === "bworld:iron_ingot" ), ); - assertEquals(ids(inputs(making("bworld:stone_pickaxe")[0])), ["bworld:wood_pickaxe", "bworld:stone"]); + assertEquals(ids(inputs(making("bworld:stone_pickaxe")[0])), [ + "bworld:wood_pickaxe", + "bworld:stone", + "bworld:brass_coin", + ]); assertEquals(category_name("bworld:smithing"), "Smithing"); });