From 69900f700788a0638125586be87b72f51a5c185b Mon Sep 17 00:00:00 2001 From: Paula Date: Wed, 30 Sep 2026 00:11:04 -0300 Subject: [PATCH] Add tiers for watering cans --- docs/modding/items/tools.md | 4 +- mods/bworld/items/copper_watering_can.json | 18 +++++++++ mods/bworld/items/gold_watering_can.json | 18 +++++++++ mods/bworld/items/iron_watering_can.json | 18 +++++++++ mods/bworld/items/stone_watering_can.json | 18 +++++++++ mods/bworld/items/watering_can.json | 12 ------ mods/bworld/items/wood_watering_can.json | 18 +++++++++ .../recipes/crafting_wood_watering_can.json | 27 ++++++++++++++ .../recipes/smithing_copper_watering_can.json | 12 ++++++ .../recipes/smithing_gold_watering_can.json | 12 ++++++ .../recipes/smithing_iron_watering_can.json | 12 ++++++ .../recipes/smithing_stone_watering_can.json | 12 ++++++ mods/bworld/scripts/server.ts | 26 ++++++++----- mods/bworld/textures/copper_watering_can.png | Bin 0 -> 207 bytes mods/bworld/textures/gold_watering_can.png | Bin 0 -> 209 bytes mods/bworld/textures/iron_watering_can.png | Bin 0 -> 205 bytes mods/bworld/textures/stone_watering_can.png | Bin 0 -> 208 bytes mods/bworld/textures/watering_can.png | Bin 232 -> 0 bytes mods/bworld/textures/wood_watering_can.png | Bin 0 -> 207 bytes tests/base_game_test.ts | 8 ++-- tests/farming_test.ts | 6 +-- tests/mod_loading_test.ts | 35 ++++++++++++++---- 22 files changed, 219 insertions(+), 37 deletions(-) create mode 100644 mods/bworld/items/copper_watering_can.json create mode 100644 mods/bworld/items/gold_watering_can.json create mode 100644 mods/bworld/items/iron_watering_can.json create mode 100644 mods/bworld/items/stone_watering_can.json delete mode 100644 mods/bworld/items/watering_can.json create mode 100644 mods/bworld/items/wood_watering_can.json create mode 100644 mods/bworld/recipes/crafting_wood_watering_can.json create mode 100644 mods/bworld/recipes/smithing_copper_watering_can.json create mode 100644 mods/bworld/recipes/smithing_gold_watering_can.json create mode 100644 mods/bworld/recipes/smithing_iron_watering_can.json create mode 100644 mods/bworld/recipes/smithing_stone_watering_can.json create mode 100644 mods/bworld/textures/copper_watering_can.png create mode 100644 mods/bworld/textures/gold_watering_can.png create mode 100644 mods/bworld/textures/iron_watering_can.png create mode 100644 mods/bworld/textures/stone_watering_can.png delete mode 100644 mods/bworld/textures/watering_can.png create mode 100644 mods/bworld/textures/wood_watering_can.png diff --git a/docs/modding/items/tools.md b/docs/modding/items/tools.md index 06c9cf2..86847ab 100644 --- a/docs/modding/items/tools.md +++ b/docs/modding/items/tools.md @@ -39,7 +39,9 @@ The base game's tiers: Tool types don't have to be the base game's. A mod can add a `"sickle"` type and blocks with `"tool": "sickle"`, and a server script can check a held item's type with `ctx.items.tool(id)`, like the base game's `bworld:hoeable` does for -hoes. +hoes. The base game's watering cans are tools of type `"watering_can"` that no block is mined with: they come in the +same five tiers with the same durability, and each holds more water than the last (16, 24, 32, 48 and 64), set by its +`bworld:watering_can` component. ## Durability diff --git a/mods/bworld/items/copper_watering_can.json b/mods/bworld/items/copper_watering_can.json new file mode 100644 index 0000000..ee97628 --- /dev/null +++ b/mods/bworld/items/copper_watering_can.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:copper_watering_can", + "texture": "bworld:copper_watering_can", + "tool": { + "type": "watering_can", + "tier": 1, + "speed": 3.5, + "durability": 5 + }, + "components": { + "bworld:watering_can": { + "max_water": 32 + } + } + } +} diff --git a/mods/bworld/items/gold_watering_can.json b/mods/bworld/items/gold_watering_can.json new file mode 100644 index 0000000..00816ad --- /dev/null +++ b/mods/bworld/items/gold_watering_can.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:gold_watering_can", + "texture": "bworld:gold_watering_can", + "tool": { + "type": "watering_can", + "tier": 0, + "speed": 6, + "durability": 9 + }, + "components": { + "bworld:watering_can": { + "max_water": 64 + } + } + } +} diff --git a/mods/bworld/items/iron_watering_can.json b/mods/bworld/items/iron_watering_can.json new file mode 100644 index 0000000..1a9d7fa --- /dev/null +++ b/mods/bworld/items/iron_watering_can.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:iron_watering_can", + "texture": "bworld:iron_watering_can", + "tool": { + "type": "watering_can", + "tier": 2, + "speed": 4, + "durability": 7 + }, + "components": { + "bworld:watering_can": { + "max_water": 48 + } + } + } +} diff --git a/mods/bworld/items/stone_watering_can.json b/mods/bworld/items/stone_watering_can.json new file mode 100644 index 0000000..45d0720 --- /dev/null +++ b/mods/bworld/items/stone_watering_can.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:stone_watering_can", + "texture": "bworld:stone_watering_can", + "tool": { + "type": "watering_can", + "tier": 1, + "speed": 3, + "durability": 3 + }, + "components": { + "bworld:watering_can": { + "max_water": 24 + } + } + } +} diff --git a/mods/bworld/items/watering_can.json b/mods/bworld/items/watering_can.json deleted file mode 100644 index a90e526..0000000 --- a/mods/bworld/items/watering_can.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "format_version": 1, - "item": { - "id": "bworld:watering_can", - "texture": "bworld:watering_can", - "components": { - "bworld:watering_can": { - "max_water": 32 - } - } - } -} diff --git a/mods/bworld/items/wood_watering_can.json b/mods/bworld/items/wood_watering_can.json new file mode 100644 index 0000000..7bc2f7a --- /dev/null +++ b/mods/bworld/items/wood_watering_can.json @@ -0,0 +1,18 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:wood_watering_can", + "texture": "bworld:wood_watering_can", + "tool": { + "type": "watering_can", + "tier": 0, + "speed": 2, + "durability": 2 + }, + "components": { + "bworld:watering_can": { + "max_water": 16 + } + } + } +} diff --git a/mods/bworld/recipes/crafting_wood_watering_can.json b/mods/bworld/recipes/crafting_wood_watering_can.json new file mode 100644 index 0000000..9ec34ac --- /dev/null +++ b/mods/bworld/recipes/crafting_wood_watering_can.json @@ -0,0 +1,27 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "S ", + " PP", + " PP" + ], + "key": { + "P": [ + "bworld:planks", + "bworld:spruce_planks", + "bworld:birch_planks", + "bworld:jungle_planks", + "bworld:acacia_planks", + "bworld:dark_oak_planks", + "bworld:cherry_planks" + ], + "S": "bworld:stick" + }, + "result": { + "id": "bworld:wood_watering_can", + "count": 1 + } + } +} diff --git a/mods/bworld/recipes/smithing_copper_watering_can.json b/mods/bworld/recipes/smithing_copper_watering_can.json new file mode 100644 index 0000000..cfa97e8 --- /dev/null +++ b/mods/bworld/recipes/smithing_copper_watering_can.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "recipe": { + "type": "smithing", + "tool": "bworld:stone_watering_can", + "material": { + "id": "bworld:copper_ingot", + "count": 5 + }, + "result": "bworld:copper_watering_can" + } +} diff --git a/mods/bworld/recipes/smithing_gold_watering_can.json b/mods/bworld/recipes/smithing_gold_watering_can.json new file mode 100644 index 0000000..ecdf14d --- /dev/null +++ b/mods/bworld/recipes/smithing_gold_watering_can.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "recipe": { + "type": "smithing", + "tool": "bworld:iron_watering_can", + "material": { + "id": "bworld:gold_ingot", + "count": 5 + }, + "result": "bworld:gold_watering_can" + } +} diff --git a/mods/bworld/recipes/smithing_iron_watering_can.json b/mods/bworld/recipes/smithing_iron_watering_can.json new file mode 100644 index 0000000..abc3e67 --- /dev/null +++ b/mods/bworld/recipes/smithing_iron_watering_can.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "recipe": { + "type": "smithing", + "tool": "bworld:copper_watering_can", + "material": { + "id": "bworld:iron_ingot", + "count": 5 + }, + "result": "bworld:iron_watering_can" + } +} diff --git a/mods/bworld/recipes/smithing_stone_watering_can.json b/mods/bworld/recipes/smithing_stone_watering_can.json new file mode 100644 index 0000000..1120894 --- /dev/null +++ b/mods/bworld/recipes/smithing_stone_watering_can.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "recipe": { + "type": "smithing", + "tool": "bworld:wood_watering_can", + "material": { + "id": "bworld:stone", + "count": 5 + }, + "result": "bworld:stone_watering_can" + } +} diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index e326ff8..b9d6725 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -284,7 +284,8 @@ function register_smithing_table(ctx: ServerContext) { // it's dug up const FARMLAND = "bworld:hoed_dirt"; -const WATERING_CAN = "bworld:watering_can"; +// every tier of watering can is a tool of this type, and shares the bworld:watering_can component +const WATERING_CAN = "watering_can"; interface WateringCanData { water: number; @@ -332,13 +333,18 @@ interface CropTopParams { } function register_farming(ctx: ServerContext) { + const is_can = (id: string | undefined) => id !== undefined && ctx.items.tool(id) === WATERING_CAN; + // how much water each tier holds, from its component. every stack goes through on_create, so every can's tier is + // in here before anything reads it + const capacity = new Map(); + const is_watered = (x: number, y: number, z: number) => ctx.world.get_block(x, y, z) === FARMLAND && ctx.world.get_state(x, y, z, "watered") === 1; // with the watering can the player holds. true when the click was about watering, so nothing gets placed const water = (x: number, y: number, z: number, player: Player) => { const can = player.held_item; - if (can?.id !== WATERING_CAN || ctx.world.get_block(x, y, z) !== FARMLAND) { + if (!can || !is_can(can.id) || ctx.world.get_block(x, y, z) !== FARMLAND) { return false; } const data = can.data as WateringCanData; @@ -438,7 +444,7 @@ function register_farming(ctx: ServerContext) { on_interact(block, params, player) { const held = player.held_item; // watering a crop waters the farmland under it - if (held?.id === WATERING_CAN) { + if (is_can(held?.id)) { block.data ??= { days: days_of(block, params) }; return water(block.x, block.y - 1, block.z, player); } @@ -490,20 +496,22 @@ function register_farming(ctx: ServerContext) { ctx.components.register_block("bworld:water_source", { on_interact(_block, _params, player) { const can = player.held_item; - if (can?.id !== WATERING_CAN) return false; - const data = can.data as WateringCanData; - can.data = { ...data, water: data.max_water }; + if (!can || !is_can(can.id)) return false; + // an upgraded can still has its old tier's max_water in its data, so this goes by its own + const max_water = capacity.get(can.id) ?? (can.data as WateringCanData).max_water; + can.data = { water: max_water, max_water } satisfies WateringCanData; return true; }, }); - ctx.components.register_item<{ max_water: number }>(WATERING_CAN, { + ctx.components.register_item<{ max_water: number }>("bworld:watering_can", { on_create(item, params) { + capacity.set(item.id, params.max_water); item.data = { water: 0, max_water: params.max_water } satisfies WateringCanData; }, - get_lore(item) { + get_lore(item, params) { const data = item.data as WateringCanData; - return `Water: ${data.water}/${data.max_water}`; + return `Water: ${data.water}/${params.max_water}`; }, }); } diff --git a/mods/bworld/textures/copper_watering_can.png b/mods/bworld/textures/copper_watering_can.png new file mode 100644 index 0000000000000000000000000000000000000000..c45135478d370359ee2ff5cfdd12a9659f71ba63 GIT binary patch literal 207 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`(>z@qLo9le6C}PQFnM}?$?{3b=rJPFVdQ&MBb@ E0IUd2UjP6A literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/gold_watering_can.png b/mods/bworld/textures/gold_watering_can.png new file mode 100644 index 0000000000000000000000000000000000000000..1af8c1fb00c29b97585e07aabbf7825acf50a0c2 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Gdx`!Lo9le6C}Po_+2^w|NZm7 z{~T96@3NBhiZNKgf4kI!5-q(0OqYA~8uKK2{(pK{&Q@6I$Cmk?yGKK>;`g*6Xu!uWW$3SJ)f`?yN8I&J6@*F*URuAYt22WQ%mvv4F FO#t_fQbGU# literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/stone_watering_can.png b/mods/bworld/textures/stone_watering_can.png new file mode 100644 index 0000000000000000000000000000000000000000..c43ea612560e39f6cfbd94dc8c1beaffeee4f452 GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`(>+}rLo9le6C}PYSi13Ly?65E z`j}5XQ=%MfnWLm;|2se1Sax}EA*0xgv=Yu4iRb6-b9-3-_cnIV=GFWD>1ei({((8oXUiBF>-Ok5cCyZJY%zIg z!f;a{#vz93>h6fkjEc?^u5Ne`#L%r*vT@NQuBNuj;tUL_e5OwvroMOzbRvVNtDnm{ Hr-UW|(kxEs literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/watering_can.png b/mods/bworld/textures/watering_can.png deleted file mode 100644 index 4499912eebb61543f1ca62477e1767bcc604fd9e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 232 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5M?jcysy3fAP;i!~ zi(`mIZ*qdfmj~w#KmY&UrskjgbQ|HNVgc71R&F+XRHCJKfGPP-<&QuA&&^$4AZ1p1 z?b!eC@AfAI1Wide;rBWH$SbC#*v2(%@0e0z@qLo9le6C}PU*q(S=Up3)$ zeat7HDNzo#%$J&D{)xNod|aZXcYx_~j~=7(o7?^SHU5~t-*42xQDpo@|Mtm_M@)Kr zX(FvH3_h~Lo6;mYzHVuh{`B@Ye_Q_j`U6kr?Wyd4$vUHW!%aP<6TR0}H8wIBcT7;5 z!=@nJ#C@WJ { }); Deno.test("a new watering can starts empty, and players are told so in its lore", async () => { - const t = await setup([["bworld:watering_can", 1]]); - const can = last_container(t.take(1), "inventory").find((i: Msg) => i?.id === "bworld:watering_can"); + const t = await setup([["bworld:copper_watering_can", 1]]); + const can = last_container(t.take(1), "inventory").find((i: Msg) => i?.id === "bworld:copper_watering_can"); assertEquals(can.data, { water: 0, max_water: 32 }); assertEquals(can.lore, "Water: 0/32"); // lore is worked out for players, it isn't saved const saved = JSON.parse(t.game.save().level); - const saved_can = saved.players.alice?.inventory?.find((i: Msg) => i?.id === "bworld:watering_can"); + const saved_can = saved.players.alice?.inventory?.find((i: Msg) => i?.id === "bworld:copper_watering_can"); assert(!saved_can || saved_can.lore === undefined); t.game.on_disconnect(1); const after = JSON.parse(t.game.save().level).players.alice.inventory.find((i: Msg) => - i?.id === "bworld:watering_can" + i?.id === "bworld:copper_watering_can" ); assertEquals(after.lore, undefined); }); diff --git a/tests/farming_test.ts b/tests/farming_test.ts index 3dea126..b99eb1f 100644 --- a/tests/farming_test.ts +++ b/tests/farming_test.ts @@ -41,7 +41,7 @@ async function setup(items: string[] = []) { } Deno.test("hoe, fill the can, plant, water, and the crop grows the next morning", async () => { - const t = await setup(["bworld:wood_hoe", "bworld:watering_can", "bworld:wheat_seeds 4"]); + const t = await setup(["bworld:wood_hoe", "bworld:copper_watering_can", "bworld:wheat_seeds 4"]); t.game.set_block(1, 100, 0, "bworld:grass"); t.game.set_block(0, 100, 1, "bworld:grass"); t.game.set_block(2, 100, 0, "bworld:water"); @@ -58,7 +58,7 @@ Deno.test("hoe, fill the can, plant, water, and the crop grows the next morning" assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:wheat"); // a new can is empty, water fills it, and watering the crop waters the farmland under it - t.hold("bworld:watering_can"); + t.hold("bworld:copper_watering_can"); t.take(1); t.use(1, 101, 0); assert(t.take(1).some((m) => m.type === "chat" && m.text.includes("empty"))); @@ -66,7 +66,7 @@ Deno.test("hoe, fill the can, plant, water, and the crop grows the next morning" t.use(2, 100, 0); t.use(1, 101, 0); assertEquals(t.state(1, 100, 0, "watered"), 1); - const can = t.inventory_now().find((i) => i?.id === "bworld:watering_can"); + const can = t.inventory_now().find((i) => i?.id === "bworld:copper_watering_can"); assertEquals(can?.data, { water: 31, max_water: 32 }); // nothing happens during the day diff --git a/tests/mod_loading_test.ts b/tests/mod_loading_test.ts index 9cdd23b..a2327fe 100644 --- a/tests/mod_loading_test.ts +++ b/tests/mod_loading_test.ts @@ -27,17 +27,17 @@ Deno.test("the base game loads from mods/bworld", async () => { const bworld = (entries: [string, unknown][]) => entries.filter(([id]) => id.startsWith("bworld:")).length; // 7 kinds of log, planks and leaves assertEquals(bworld(EverythingRegistry.entries("blocks")), 42); - // 38 items (20 of them tools) plus the item forms of the 37 blocks that have one - assertEquals(bworld(EverythingRegistry.entries("items")), 75); - // bworld's 16 (4 wood tools, 7 planks, the fishing rod), the cooking pot, stove, cutting board and wood knife are - // farmersdelight's - assertEquals(game.recipes.shaped.length, 20); - // every log and fish smelts, every log burns - assertEquals(game.recipes.furnace.size, 14); + // 42 items (25 of them tools) plus the item forms of the 37 blocks that have one + assertEquals(bworld(EverythingRegistry.entries("items")), 79); + // bworld's 18 (4 wood tools, the wood watering can, 7 planks, the fishing rod, the smithing table), the cooking pot, + // stove, cutting board and wood knife are farmersdelight's + assertEquals(game.recipes.shaped.length, 22); + // every log and fish smelts, every log burns, and so do sand into glass and cobblestone into stone + assertEquals(game.recipes.furnace.size, 16); assertEquals(game.recipes.fuel.size, 8); assertEquals(EverythingRegistry.get("blocks", "bworld:water")?.replaceable, true); // still has its code until it's a component - assert(EverythingRegistry.get("items", "bworld:watering_can")?.on_create); + assert(EverythingRegistry.get("items", "bworld:copper_watering_can")?.on_create); }); Deno.test("mods/bworld json survives going to the registry and back", async () => { @@ -242,6 +242,25 @@ Deno.test("every tier of pickaxe, axe, shovel and hoe exists and can be made", a } }); +Deno.test("every tier of watering can exists, can be made and holds more than the last", async () => { + const { game } = await test_game("mods"); + const made = new Set([ + ...game.recipes.shaped.map((recipe) => recipe.result.id), + ...game.recipes.smithing.map((recipe) => recipe.result), + ]); + let last = 0; + for (const tier of ["wood", "stone", "copper", "iron", "gold"]) { + const id = `bworld:${tier}_watering_can`; + const item = EverythingRegistry.get("items", id); + assertEquals(item?.tool?.type, "watering_can", id); + assertEquals(item?.texture_id, id); + assert(made.has(id), `nothing makes ${id}`); + const max_water = (item?.components?.["bworld:watering_can"] as { max_water: number }).max_water; + assert(max_water > last, id); + last = max_water; + } +}); + Deno.test("a lit furnace shows its lit front", async () => { await test_game("mods"); const furnace = EverythingRegistry.get("blocks", "bworld:furnace")!;