From 67e8fe5c00b757167a072a1a52301d9c35cbf5f9 Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 11 Oct 2026 19:12:38 -0300 Subject: [PATCH] Lava fishing --- docs/modding/blocks/components.md | 28 ++++++++-------- docs/modding/resources/loot_tables.md | 21 +++++++----- mods/bworld/blocks/lava.json | 3 ++ mods/bworld/items/fishing_rod.json | 3 +- mods/bworld/items/lava_eel.json | 10 +++++- mods/bworld/items/magma_slimefish.json | 10 +++++- mods/bworld/items/mother_moon.json | 10 +++++- mods/bworld/items/prismfish.json | 10 +++++- mods/bworld/items/totemfish.json | 10 +++++- mods/bworld/items/true_goldfish.json | 10 +++++- mods/bworld/items/vampire_squid.json | 10 +++++- mods/bworld/scripts/fishing.ts | 46 +++++++++++++++++++++----- tests/fishing_test.ts | 36 ++++++++++++++++++++ 13 files changed, 167 insertions(+), 40 deletions(-) diff --git a/docs/modding/blocks/components.md b/docs/modding/blocks/components.md index 7fe2c8f..7ba6833 100644 --- a/docs/modding/blocks/components.md +++ b/docs/modding/blocks/components.md @@ -173,19 +173,19 @@ catch up. If it's further behind than that, it skips the rest and logs a warning `mods/bworld/scripts/server.ts` registers these, and any mod that depends on `bworld` can use them: -| Component | Params | What it does | -| ----------------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `bworld:storage` | `rows` | A chest: `rows` × 9 slots, dropped when it's broken. | -| `bworld:shipping_bin` | `rows` | Like `bworld:storage`, and every morning at 06:00 sells what's in it with a `base_sell_value` for coins. | -| `bworld:furnace` | none | Smelts with `furnace` and `fuel` [recipes](../resources/recipes.md). Needs `lit` and `facing` states, see `blocks/furnace.json`. | -| `bworld:smithing_table` | none | Upgrades tools with `smithing` recipes. | -| `bworld:hoeable` | `tool`, `into` | Right clicking with a tool of type `tool` turns it into `into`, like a hoe on grass. | -| `bworld:farmland` | none | Watered with the watering can, dries out every morning. | -| `bworld:crop` | see [Crops](crops.md) | Grows a stage every morning its farmland was watered. | -| `bworld:crop_top` | see [Crops](crops.md) | The top half of a two block crop, like rice. | -| `bworld:water_source` | none | Refills the watering can. | -| `bworld:fishable` | none | The fishing rod's hook floats on it and fish bite there when it lands in it. | -| `bworld:trapdoor` | none | Opens and closes when right clicked, and is placed like Minecraft's (both are rules, in the shared script). Needs `facing` (2 bits), `half` and `open` states, see `blocks/oak_trapdoor.json`. | -| `bworld:fence` | `connects_to` | Joins the blocks in the tag `connects_to` and sturdy sides of other blocks, except leaves. Needs the `north`, `east`, `south` and `west` states. | +| Component | Params | What it does | +| ----------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `bworld:storage` | `rows` | A chest: `rows` × 9 slots, dropped when it's broken. | +| `bworld:shipping_bin` | `rows` | Like `bworld:storage`, and every morning at 06:00 sells what's in it with a `base_sell_value` for coins. | +| `bworld:furnace` | none | Smelts with `furnace` and `fuel` [recipes](../resources/recipes.md). Needs `lit` and `facing` states, see `blocks/furnace.json`. | +| `bworld:smithing_table` | none | Upgrades tools with `smithing` recipes. | +| `bworld:hoeable` | `tool`, `into` | Right clicking with a tool of type `tool` turns it into `into`, like a hoe on grass. | +| `bworld:farmland` | none | Watered with the watering can, dries out every morning. | +| `bworld:crop` | see [Crops](crops.md) | Grows a stage every morning its farmland was watered. | +| `bworld:crop_top` | see [Crops](crops.md) | The top half of a two block crop, like rice. | +| `bworld:water_source` | none | Refills the watering can. | +| `bworld:fishable` | `loot_table`? | The fishing rod's hook floats on it and fish bite there when it lands in it. What's caught is `loot_table`, `bworld:gameplay/fishing` when not given, built from the fish whose `liquid` is this block. | +| `bworld:trapdoor` | none | Opens and closes when right clicked, and is placed like Minecraft's (both are rules, in the shared script). Needs `facing` (2 bits), `half` and `open` states, see `blocks/oak_trapdoor.json`. | +| `bworld:fence` | `connects_to` | Joins the blocks in the tag `connects_to` and sturdy sides of other blocks, except leaves. Needs the `north`, `east`, `south` and `west` states. | Item components work the same way, see [Items](../items/index.md#item-components). diff --git a/docs/modding/resources/loot_tables.md b/docs/modding/resources/loot_tables.md index cf08619..9573120 100644 --- a/docs/modding/resources/loot_tables.md +++ b/docs/modding/resources/loot_tables.md @@ -121,20 +121,22 @@ does nothing unless they hold. ## Where Tables Are Used -| What | How | -| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -| [Blocks](../blocks/index.md) | `"loot_table"` in the block's json, rolled when it breaks, with its states and the tool. `"drops"` is the shorthand for one of an item. | -| [Mobs](../entities/index.md) | `"loot_table"` in the entity's json, rolled when it dies. `killed_by_player` holds when a player killed it. | -| [Crops](../blocks/crops.md) | Their block's `loot_table`, with `block_state` on `age` for grown or not. `harvest` is a table for picking. | -| Fishing | The fishing rod's `loot_table`, `bworld:gameplay/fishing`, rolled when it's reeled in. See [Fishing](#fishing). | -| Scripts | `ctx.loot.roll` and `ctx.loot.fill`, for anything else, like chests in structures. | +| What | How | +| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [Blocks](../blocks/index.md) | `"loot_table"` in the block's json, rolled when it breaks, with its states and the tool. `"drops"` is the shorthand for one of an item. | +| [Mobs](../entities/index.md) | `"loot_table"` in the entity's json, rolled when it dies. `killed_by_player` holds when a player killed it. | +| [Crops](../blocks/crops.md) | Their block's `loot_table`, with `block_state` on `age` for grown or not. `harvest` is a table for picking. | +| Fishing | The `loot_table` of the `bworld:fishable` block the hook is in, `bworld:gameplay/fishing` for water, rolled when it's reeled in. See [Fishing](#fishing). | +| Scripts | `ctx.loot.roll` and `ctx.loot.fill`, for anything else, like chests in structures. | `check-mods` checks that every item, tag and table a table names exists, and that the tables blocks and mobs name do. ## Fishing -The fishing table, `bworld:gameplay/fishing`, isn't a file: the base game builds it from every item with the -`bworld:fish` component, so a mod adds a fish by giving its item the component: +The fishing tables aren't files: the base game builds them from every item with the `bworld:fish` component, so a mod +adds a fish by giving its item the component. A fish lives in one liquid, water unless its `liquid` says otherwise, and +is in that liquid's table: the `loot_table` of its `bworld:fishable` component, `bworld:gameplay/fishing` when it +doesn't name one. Water's is `bworld:gameplay/fishing` and lava's is `bworld:gameplay/lava_fishing`: ```json "components": { @@ -151,6 +153,7 @@ The fishing table, `bworld:gameplay/fishing`, isn't a file: the base game builds | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `weight` | How often it's caught against the other fish, 1 when not given. | | `seasons` | The [seasons](../worldgen/biomes.md#seasons) it's caught in where the hook is, every one when not given. | +| `liquid` | The `bworld:fishable` block it's caught in, `bworld:water` when not given, like `"bworld:lava"`. | | `biomes` | The [biomes](../worldgen/biomes.md#biome-ids) and [biome tags](../worldgen/biomes.md#biome-tags) it's caught in where the hook is, every one when not given. | | `time` | The hours it's caught at on a 24 hour clock, from `from` up to `to`, like `6.5` for 06:30. When `from` is past `to` it wraps around midnight. All day when not given. | | `minigame` | What the player does to land it once it's reeled in, in a screen that holds the fish until they win. Closing it lets the fish get away. Caught right away when not given. The base game's are `"test"`, a Catch button, `"hold"`, a bar that fills while the mouse is held and empties while it isn't: full lands the fish, empty loses it, `"valley"`, Stardew Valley's, where holding the mouse lifts a bar to keep the fish in it, `"ring"`, where a green ring grows out toward gray ones and clicking while it's inside each lands the fish, `"maze"`, where the mouse goes from the start to the end of a maze without touching its walls, in 8 seconds, and `"chess"`, a mate in one from Lichess's puzzles to find in 8 seconds. | diff --git a/mods/bworld/blocks/lava.json b/mods/bworld/blocks/lava.json index 747261b..7fae14c 100644 --- a/mods/bworld/blocks/lava.json +++ b/mods/bworld/blocks/lava.json @@ -10,6 +10,9 @@ "components": { "bworld:bucketable": { "into": "bworld:lava_bucket" + }, + "bworld:fishable": { + "loot_table": "bworld:gameplay/lava_fishing" } } } diff --git a/mods/bworld/items/fishing_rod.json b/mods/bworld/items/fishing_rod.json index e4d549b..f0c10f7 100644 --- a/mods/bworld/items/fishing_rod.json +++ b/mods/bworld/items/fishing_rod.json @@ -17,8 +17,7 @@ "bite": [ 20, 40 - ], - "loot_table": "bworld:gameplay/fishing" + ] } } } diff --git a/mods/bworld/items/lava_eel.json b/mods/bworld/items/lava_eel.json index cb3b4b9..85705ae 100644 --- a/mods/bworld/items/lava_eel.json +++ b/mods/bworld/items/lava_eel.json @@ -7,6 +7,14 @@ "nutrition": 2, "saturation_modifier": 0.1 }, - "base_sell_value": 1 + "components": { + "bworld:fish": { + "liquid": "bworld:lava", + "weight": 2, + "minigame": "valley", + "difficulty": 90 + } + }, + "base_sell_value": 710 } } diff --git a/mods/bworld/items/magma_slimefish.json b/mods/bworld/items/magma_slimefish.json index 21adb09..c62b244 100644 --- a/mods/bworld/items/magma_slimefish.json +++ b/mods/bworld/items/magma_slimefish.json @@ -7,6 +7,14 @@ "nutrition": 2, "saturation_modifier": 0.1 }, - "base_sell_value": 1 + "components": { + "bworld:fish": { + "liquid": "bworld:lava", + "weight": 8, + "minigame": "ring", + "difficulty": 61 + } + }, + "base_sell_value": 85 } } diff --git a/mods/bworld/items/mother_moon.json b/mods/bworld/items/mother_moon.json index 2f312e1..6421da2 100644 --- a/mods/bworld/items/mother_moon.json +++ b/mods/bworld/items/mother_moon.json @@ -7,6 +7,14 @@ "nutrition": 2, "saturation_modifier": 0.1 }, - "base_sell_value": 1 + "components": { + "bworld:fish": { + "liquid": "bworld:lava", + "weight": 10, + "minigame": "valley", + "difficulty": 50 + } + }, + "base_sell_value": 72 } } diff --git a/mods/bworld/items/prismfish.json b/mods/bworld/items/prismfish.json index 5058fe3..9415c17 100644 --- a/mods/bworld/items/prismfish.json +++ b/mods/bworld/items/prismfish.json @@ -7,6 +7,14 @@ "nutrition": 2, "saturation_modifier": 0.1 }, - "base_sell_value": 1 + "components": { + "bworld:fish": { + "liquid": "bworld:lava", + "weight": 1, + "minigame": "maze", + "difficulty": 110 + } + }, + "base_sell_value": 3500 } } diff --git a/mods/bworld/items/totemfish.json b/mods/bworld/items/totemfish.json index 5e4e972..fa3cdea 100644 --- a/mods/bworld/items/totemfish.json +++ b/mods/bworld/items/totemfish.json @@ -7,6 +7,14 @@ "nutrition": 2, "saturation_modifier": 0.1 }, - "base_sell_value": 1 + "components": { + "bworld:fish": { + "liquid": "bworld:lava", + "weight": 4, + "minigame": "ring", + "difficulty": 81 + } + }, + "base_sell_value": 350 } } diff --git a/mods/bworld/items/true_goldfish.json b/mods/bworld/items/true_goldfish.json index aa3c050..7a87903 100644 --- a/mods/bworld/items/true_goldfish.json +++ b/mods/bworld/items/true_goldfish.json @@ -7,6 +7,14 @@ "nutrition": 2, "saturation_modifier": 0.1 }, - "base_sell_value": 1 + "components": { + "bworld:fish": { + "liquid": "bworld:lava", + "weight": 0.1, + "minigame": "hold", + "difficulty": 50 + } + }, + "base_sell_value": 2750 } } diff --git a/mods/bworld/items/vampire_squid.json b/mods/bworld/items/vampire_squid.json index 3d1ff27..b0c6ece 100644 --- a/mods/bworld/items/vampire_squid.json +++ b/mods/bworld/items/vampire_squid.json @@ -7,6 +7,14 @@ "nutrition": 2, "saturation_modifier": 0.1 }, - "base_sell_value": 1 + "components": { + "bworld:fish": { + "liquid": "bworld:lava", + "weight": 10, + "minigame": "chess", + "difficulty": 70 + } + }, + "base_sell_value": 190 } } diff --git a/mods/bworld/scripts/fishing.ts b/mods/bworld/scripts/fishing.ts index d7aec27..1650388 100644 --- a/mods/bworld/scripts/fishing.ts +++ b/mods/bworld/scripts/fishing.ts @@ -11,8 +11,11 @@ const FISHABLE = "bworld:fishable"; const FISH = "bworld:fish"; // the menu a fish's minigame is played in. client.ts gives it the minigame's screen, see minigames/mod.ts const MINIGAME_MENU = "bworld:fishing_minigame"; -// built from every item with bworld:fish, see register_fishing +// what's caught in a fishable block whose bworld:fishable doesn't name a table, like water. each table is built from +// the items with bworld:fish that live in its liquid, see register_fishing const FISHING_TABLE = "bworld:gameplay/fishing"; +// the liquid a fish lives in when it doesn't say +const WATER = "bworld:water"; // further than this from the hook, the line snaps const LINE_LENGTH = 16; // blocks per tick it's thrown at, and how it falls and slows down in the air each tick, like minecraft's hook @@ -35,8 +38,13 @@ interface FishingRodParams { wait: [number, number]; // ticks it stays on the hook before it gets away bite: [number, number]; - // what's caught, a loot table. bworld:season, bworld:time and bworld:biome pick fish by where and when it's reeled in - loot_table: string; +} + +// a block the hook floats on, like water and lava +interface FishableParams { + // what's caught in it, FISHING_TABLE when not given. bworld:season, bworld:time and bworld:biome pick fish by where + // and when it's reeled in + loot_table?: string; } // an item that's caught by fishing @@ -53,6 +61,8 @@ interface FishParams { minigame?: string; // how hard its minigame is, 10 when not given. what it changes is up to the minigame difficulty?: number; + // the fishable block it's caught in, bworld:water when not given. it's in that block's loot table + liquid?: string; } interface Cast { @@ -122,7 +132,10 @@ export function register_fishing(ctx: ServerContext) { }; // fishable blocks are found by their components, see is_fishable - ctx.components.register_block(FISHABLE, {}); + ctx.components.register_block(FISHABLE, {}); + // what's caught in a fishable block + const table_of = (block: string) => + (ctx.blocks.components(block)[FISHABLE] as FishableParams | undefined)?.loot_table ?? FISHING_TABLE; // "seasons": ["summer", "autumn"], holds in any of them, at the loot's position. without a position, like a // table rolled from a command, it holds @@ -151,8 +164,12 @@ export function register_fishing(ctx: ServerContext) { return from <= to ? hour >= from && hour < to : hour >= from || hour < to; }); - // every item with bworld:fish is in the fishing table, caught in its seasons, at its hours and in its biomes + // every item with bworld:fish is in its liquid's fishing table, caught in its seasons, at its hours and in its + // biomes ctx.components.register_item(FISH, {}); + const tables = new Map([ + [FISHING_TABLE, []], + ]); const entries = ctx.items.ids().flatMap((id) => { const fish = ctx.items.components(id)[FISH] as FishParams | undefined; if (!fish) return []; @@ -166,9 +183,18 @@ export function register_fishing(ctx: ServerContext) { if (fish.seasons) conditions.push({ condition: "bworld:season", seasons: fish.seasons }); if (fish.time) conditions.push({ condition: "bworld:time", ...fish.time }); if (fish.biomes) conditions.push({ condition: "bworld:biome", biomes: fish.biomes }); - return [{ item: id, weight: fish.weight ?? 1, conditions }]; + const liquid = fish.liquid ?? WATER; + if (!ctx.blocks.exists(liquid) || !(FISHABLE in ctx.blocks.components(liquid))) { + throw new Error(`${id} is caught in ${liquid}, which isn't a block with ${FISHABLE}`); + } + const entry = { item: id, weight: fish.weight ?? 1, conditions }; + const table = table_of(liquid); + tables.set(table, [...tables.get(table) ?? [], entry]); + return [entry]; }); - ctx.loot.register_table(FISHING_TABLE, { pools: entries.length > 0 ? [{ entries }] : [] }); + for (const [table, entries] of tables) { + ctx.loot.register_table(table, { pools: entries.length > 0 ? [{ entries }] : [] }); + } // holds the fish until its minigame is won, and closes then. closing it before lets the fish get away const minigame_menu = ctx.menus.register<{ minigame: string; fish: ItemStack; difficulty: number }>( @@ -226,7 +252,11 @@ export function register_fishing(ctx: ServerContext) { const cast = casts.get(player.id); if (cast) { if (cast.escape_at !== undefined) { - const loot = ctx.loot.roll(params.loot_table, { position: cast.position, player, tool: rod }); + // a table no fish lives in isn't made, and nothing's caught there + const table = table_of(cast.water!.block); + const loot = ctx.loot.exists(table) + ? ctx.loot.roll(table, { position: cast.position, player, tool: rod }) + : []; for (const item of loot) land(player, item); } stop(player, player.id); diff --git a/tests/fishing_test.ts b/tests/fishing_test.ts index d18a289..b81b331 100644 --- a/tests/fishing_test.ts +++ b/tests/fishing_test.ts @@ -566,3 +566,39 @@ Deno.test("the chess minigame lands the fish when its screen says the mate was p assertEquals(t.fish().length, 1); }, "chess"); }); + +Deno.test("fishing in lava catches the lava fish, from lava's own table", async () => { + const t = await setup(); + const lava_fish = [ + "bworld:lava_eel", + "bworld:magma_slimefish", + "bworld:mother_moon", + "bworld:prismfish", + "bworld:totemfish", + "bworld:true_goldfish", + "bworld:vampire_squid", + ]; + // the pond is lava instead + for (let x = -3; x <= 3; x++) { + for (let z = -9; z <= -3; z++) t.game.set_block(x, 99, z, "bworld:lava"); + } + await with_minigames(async () => { + for (let i = 0; i < 5; i++) { + t.cast(); + assertEquals(t.hooks().length, 1); + assert(t.wait_for_bite()); + t.reel(); + t.game.tick(); + } + // the same fish twice stacks in one slot + const caught = t.fish().map((i: Msg) => i.id); + assertEquals(t.fish().reduce((count: number, i: Msg) => count + i.count, 0), 5); + assert(caught.every((id: string) => lava_fish.includes(id)), caught.join(", ")); + }, null); + // and no lava fish in water's table + const water = EverythingRegistry.get<{ pools: { entries: { item: string }[] }[] }>( + "loot_tables", + "bworld:gameplay/fishing", + )!; + assert(water.pools[0].entries.every((e) => !lava_fish.includes(e.item))); +});