From 84a622c3f190be409979f22d7f4e4f64e980ae19 Mon Sep 17 00:00:00 2001 From: Paula Date: Mon, 28 Sep 2026 13:33:40 -0300 Subject: [PATCH] Fishing ! --- MODS.md | 1 + client/rendering/item_renderer.ts | 9 +- client/rendering/render_utils.ts | 8 +- common/everything_registry.ts | 2 + common/mod_check.ts | 1 + common/mod_data.ts | 12 ++ common/utils.ts | 14 ++ mods/bworld/blocks/water.json | 3 +- mods/bworld/items/cod.json | 11 ++ mods/bworld/items/cooked_cod.json | 11 ++ mods/bworld/items/cooked_salmon.json | 11 ++ mods/bworld/items/fishing_rod.json | 22 ++++ mods/bworld/items/salmon.json | 11 ++ mods/bworld/recipes/crafting_fishing_rod.json | 19 +++ mods/bworld/recipes/smelting_cod.json | 12 ++ mods/bworld/recipes/smelting_salmon.json | 12 ++ mods/bworld/scripts/server.ts | 123 ++++++++++++++++++ mods/bworld/textures/cod.png | Bin 0 -> 541 bytes mods/bworld/textures/cooked_cod.png | Bin 0 -> 393 bytes mods/bworld/textures/cooked_salmon.png | Bin 0 -> 421 bytes mods/bworld/textures/fishing_hook.png | Bin 0 -> 1152 bytes mods/bworld/textures/fishing_rod.png | Bin 0 -> 6373 bytes mods/bworld/textures/fishing_rod_cast.png | Bin 0 -> 6088 bytes mods/bworld/textures/grass.png | Bin 175 -> 0 bytes mods/bworld/textures/salmon.png | Bin 0 -> 575 bytes tests/fishing_test.ts | 94 +++++++++++++ tests/mod_loading_test.ts | 12 +- 27 files changed, 367 insertions(+), 21 deletions(-) create mode 100644 mods/bworld/items/cod.json create mode 100644 mods/bworld/items/cooked_cod.json create mode 100644 mods/bworld/items/cooked_salmon.json create mode 100644 mods/bworld/items/fishing_rod.json create mode 100644 mods/bworld/items/salmon.json create mode 100644 mods/bworld/recipes/crafting_fishing_rod.json create mode 100644 mods/bworld/recipes/smelting_cod.json create mode 100644 mods/bworld/recipes/smelting_salmon.json create mode 100644 mods/bworld/textures/cod.png create mode 100644 mods/bworld/textures/cooked_cod.png create mode 100644 mods/bworld/textures/cooked_salmon.png create mode 100644 mods/bworld/textures/fishing_hook.png create mode 100644 mods/bworld/textures/fishing_rod.png create mode 100644 mods/bworld/textures/fishing_rod_cast.png delete mode 100644 mods/bworld/textures/grass.png create mode 100644 mods/bworld/textures/salmon.png create mode 100644 tests/fishing_test.ts diff --git a/MODS.md b/MODS.md index 24c3e20..2720260 100644 --- a/MODS.md +++ b/MODS.md @@ -418,6 +418,7 @@ clicked on somewhere it can go and eaten otherwise. | `id` | required | registry key | The item's id. | | `name` | from the id | `name` | What players see, like `"Copper Pickaxe"`. Made from the id when not set. | | `texture` | required | `texture_id` | Texture id. | +| `data_textures` | none | `data_textures` | `{ "cast": "bworld:fishing_rod_cast" }`: a stack whose `data` has that key set is drawn with that texture instead, like a cast fishing rod. The first key that's set wins. | | `tool` | none | `tool_type` | Tool type used by blocks' `mining.tool`. | | `places` | none | `block_id` | Block placed when used on a block face. | | `max_stack` | `64` | new | Largest stack size. | diff --git a/client/rendering/item_renderer.ts b/client/rendering/item_renderer.ts index 26b951a..ee5d9f0 100644 --- a/client/rendering/item_renderer.ts +++ b/client/rendering/item_renderer.ts @@ -7,6 +7,7 @@ import type { ItemStack } from "$/common/inventory.ts"; import { push_vertex, Texture } from "$/client/renderer/mod.ts"; import { block_item_texture, cube_face_texture, cube_face_tint } from "$/common/block_models.ts"; import { item_model } from "./item_model.ts"; +import { item_texture } from "$/common/utils.ts"; // how big items on the ground are drawn, minecraft's ground transform const BLOCK_SCALE = 0.25; @@ -113,11 +114,3 @@ function push_textured_quad(atlas: Texture, region: { x: number; y: number }, co push_vertex(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, color[0], color[1], color[2], 1); } } - -function item_texture(item: ItemStack) { - const texture_id = EverythingRegistry.get("items", item.type_id)?.texture_id; - if (typeof texture_id === "function") { - return texture_id(item); - } - return texture_id ?? "engine:missing"; -} diff --git a/client/rendering/render_utils.ts b/client/rendering/render_utils.ts index d8d4def..8de0a99 100644 --- a/client/rendering/render_utils.ts +++ b/client/rendering/render_utils.ts @@ -3,6 +3,7 @@ import { get_sprite_region } from "$/client/sprites.ts"; import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts"; import { AssetManager } from "$/client/assets.ts"; import { ItemStack } from "$/common/inventory.ts"; +import { item_texture } from "$/common/utils.ts"; import { block_item_texture, cube_face_texture, cube_face_tint } from "$/common/block_models.ts"; import { draw_text, draw_texture_region, draw_texture_region_skewed, Texture } from "$/client/renderer/mod.ts"; @@ -93,12 +94,7 @@ export function draw_item(item: ItemStack, x: number, y: number) { // ey its not a bad name function draw_item_item(item: ItemStack, item_info: ItemRegistry, x: number, y: number) { - let texture_id = "engine:missing"; - if (typeof item_info?.texture_id === "string") { - texture_id = item_info.texture_id; - } else if (typeof item_info?.texture_id === "function") { - texture_id = item_info.texture_id(item); - } + const texture_id = item_texture(item, item_info); const sprite_region = get_sprite_region(texture_id); draw_texture_region( AssetManager.instance.get("bworld:textures"), diff --git a/common/everything_registry.ts b/common/everything_registry.ts index fddb4c7..f3880e1 100644 --- a/common/everything_registry.ts +++ b/common/everything_registry.ts @@ -158,6 +158,8 @@ export interface FoodProperties { export interface ItemRegistry { texture_id: string | ((item: ItemStack) => string); + // shown in place of texture_id while the stack's data has that key set, like a cast fishing rod. the first wins + data_textures?: Record; // what players see, like "Iron Ingot". made from the id when not set, see display_name in common/utils.ts name?: string; block_id?: string; diff --git a/common/mod_check.ts b/common/mod_check.ts index 3da43ab..edbb98c 100644 --- a/common/mod_check.ts +++ b/common/mod_check.ts @@ -129,6 +129,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable texture, see ItemRegistry.data_textures + data_textures?: Record; tool?: string; places?: string; max_stack?: number; @@ -192,6 +194,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson { throw new Error(`${id} picks its texture with a function, which json can't hold`); } const json: ItemJson = { id, texture: item.texture_id }; + if (item.data_textures !== undefined) json.data_textures = item.data_textures; if (item.tool_type !== undefined) json.tool = item.tool_type; if (item.block_id !== undefined) json.places = item.block_id; if (item.max_stack !== undefined) json.max_stack = item.max_stack; @@ -204,6 +207,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson { export function item_from_json(json: ItemJson): ItemRegistry { const item: ItemRegistry = { texture_id: json.texture }; + if (json.data_textures !== undefined) item.data_textures = json.data_textures; if (json.tool !== undefined) item.tool_type = json.tool; if (json.places !== undefined) item.block_id = json.places; if (json.max_stack !== undefined) item.max_stack = json.max_stack; @@ -477,6 +481,14 @@ export function validate_item(json: unknown): Problems { if (!is_object(json)) return ["item must be an object"]; const problems = validate_id(json.id, "id"); problems.push(...validate_id(json.texture, "texture")); + if (json.data_textures !== undefined) { + if (!is_object(json.data_textures)) problems.push("data_textures must be { data key: texture id }"); + else { + for (const [key, id] of Object.entries(json.data_textures)) { + problems.push(...validate_id(id, `data_textures.${key}`)); + } + } + } if (json.places !== undefined) problems.push(...validate_id(json.places, "places")); problems.push(...validate_text(json.name, "name"), ...validate_text(json.lore, "lore")); if (json.max_stack !== undefined && (!Number.isInteger(json.max_stack) || (json.max_stack as number) < 1)) { diff --git a/common/utils.ts b/common/utils.ts index 8478e89..48ca210 100644 --- a/common/utils.ts +++ b/common/utils.ts @@ -1,6 +1,7 @@ import { ID_MASK, STATE_SHIFT } from "./constants.ts"; import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_registry.ts"; import { block_item_texture, cube_face_texture } from "./block_models.ts"; +import type { ItemStack } from "./inventory.ts"; export function point_inside_rec( point_x: number, @@ -46,6 +47,19 @@ export function register_block_item(block: BlockRegistry) { EverythingRegistry.register("items", block.id, item); } +// the texture a stack is drawn with: one of its data_textures when its data has that key set, or its texture +export function item_texture( + item: ItemStack, + info = EverythingRegistry.get("items", item.type_id), +): string { + if (!info) return "engine:missing"; + const data = item.data as Record | undefined; + for (const [key, texture] of Object.entries(info.data_textures ?? {})) { + if (data?.[key]) return texture; + } + return typeof info.texture_id === "function" ? info.texture_id(item) : info.texture_id; +} + // what players see an item called: its name, or one made from its id, so bworld:iron_ingot is "Iron Ingot" export function display_name(item_id: string): string { const name = EverythingRegistry.get("items", item_id)?.name; diff --git a/mods/bworld/blocks/water.json b/mods/bworld/blocks/water.json index 7ec7ca3..1b85cdb 100644 --- a/mods/bworld/blocks/water.json +++ b/mods/bworld/blocks/water.json @@ -10,7 +10,8 @@ "item": false, "replaceable": true, "components": { - "bworld:water_source": {} + "bworld:water_source": {}, + "bworld:fishable": {} } } } diff --git a/mods/bworld/items/cod.json b/mods/bworld/items/cod.json new file mode 100644 index 0000000..3fd9109 --- /dev/null +++ b/mods/bworld/items/cod.json @@ -0,0 +1,11 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:cod", + "texture": "bworld:cod", + "food": { + "nutrition": 2, + "saturation_modifier": 0.1 + } + } +} diff --git a/mods/bworld/items/cooked_cod.json b/mods/bworld/items/cooked_cod.json new file mode 100644 index 0000000..f8d9018 --- /dev/null +++ b/mods/bworld/items/cooked_cod.json @@ -0,0 +1,11 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:cooked_cod", + "texture": "bworld:cooked_cod", + "food": { + "nutrition": 5, + "saturation_modifier": 0.6 + } + } +} diff --git a/mods/bworld/items/cooked_salmon.json b/mods/bworld/items/cooked_salmon.json new file mode 100644 index 0000000..4ad911c --- /dev/null +++ b/mods/bworld/items/cooked_salmon.json @@ -0,0 +1,11 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:cooked_salmon", + "texture": "bworld:cooked_salmon", + "food": { + "nutrition": 6, + "saturation_modifier": 0.8 + } + } +} diff --git a/mods/bworld/items/fishing_rod.json b/mods/bworld/items/fishing_rod.json new file mode 100644 index 0000000..cbc4d5f --- /dev/null +++ b/mods/bworld/items/fishing_rod.json @@ -0,0 +1,22 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:fishing_rod", + "texture": "bworld:fishing_rod", + "data_textures": { + "cast": "bworld:fishing_rod_cast" + }, + "max_stack": 1, + "lore": "Right click water to cast, and again when something bites.", + "components": { + "bworld:fishing_rod": { + "wait": [100, 600], + "bite": [20, 40], + "loot": [ + { "item": "bworld:cod", "weight": 60 }, + { "item": "bworld:salmon", "weight": 25 } + ] + } + } + } +} diff --git a/mods/bworld/items/salmon.json b/mods/bworld/items/salmon.json new file mode 100644 index 0000000..9b72606 --- /dev/null +++ b/mods/bworld/items/salmon.json @@ -0,0 +1,11 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:salmon", + "texture": "bworld:salmon", + "food": { + "nutrition": 2, + "saturation_modifier": 0.1 + } + } +} diff --git a/mods/bworld/recipes/crafting_fishing_rod.json b/mods/bworld/recipes/crafting_fishing_rod.json new file mode 100644 index 0000000..0a4ebc6 --- /dev/null +++ b/mods/bworld/recipes/crafting_fishing_rod.json @@ -0,0 +1,19 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + " S", + " SW", + "S W" + ], + "key": { + "S": "bworld:stick", + "W": "bworld:wheat" + }, + "result": { + "id": "bworld:fishing_rod", + "count": 1 + } + } +} diff --git a/mods/bworld/recipes/smelting_cod.json b/mods/bworld/recipes/smelting_cod.json new file mode 100644 index 0000000..621bf04 --- /dev/null +++ b/mods/bworld/recipes/smelting_cod.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "recipe": { + "type": "furnace", + "input": "bworld:cod", + "output": { + "id": "bworld:cooked_cod", + "count": 1 + }, + "cook_time": 200 + } +} diff --git a/mods/bworld/recipes/smelting_salmon.json b/mods/bworld/recipes/smelting_salmon.json new file mode 100644 index 0000000..6822e0b --- /dev/null +++ b/mods/bworld/recipes/smelting_salmon.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "recipe": { + "type": "furnace", + "input": "bworld:salmon", + "output": { + "id": "bworld:cooked_salmon", + "count": 1 + }, + "cook_time": 200 + } +} diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index 958d4b6..575df6c 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -7,6 +7,7 @@ export function setup(ctx: ServerContext) { register_furnace(ctx); register_smithing_table(ctx); register_farming(ctx); + register_fishing(ctx); } // right clicking with a type of tool turns the block into another, like any hoe on grass @@ -506,3 +507,125 @@ function register_farming(ctx: ServerContext) { }, }); } + +// fishing, like minecraft's without the bobber: right click water with a rod to cast, wait for a bite, and right click +// again before it gets away to reel it in. there's no hook entity yet, so a chat message says when something bites + +const FISHING_ROD = "bworld:fishing_rod"; +// further than this from where they cast, the line snaps +const LINE_LENGTH = 16; + +interface FishingRodParams { + // ticks until something bites, the shortest and longest, like minecraft's 5 to 30 seconds + wait: [number, number]; + // ticks it stays on the hook before it gets away + bite: [number, number]; + loot: { item: string; weight: number }[]; +} + +interface Cast { + x: number; + y: number; + z: number; + // the block they cast into, the line comes out when it's gone + block: string; + // the hotbar slot the rod is in, switching away reels it in + slot: number; + params: FishingRodParams; + // ticks, when something bites and when it gets away + bite_at: number; + escape_at?: number; +} + +function register_fishing(ctx: ServerContext) { + // by player id + const casts = new Map(); + // the water each player right clicked this tick, for their rod's on_use, which doesn't get the block + const aimed = new Map(); + + const between = ([min, max]: [number, number]) => min + Math.floor(Math.random() * (max - min + 1)); + + const pick = (loot: FishingRodParams["loot"]) => { + const total = loot.reduce((sum, entry) => sum + entry.weight, 0); + let roll = Math.random() * total; + for (const entry of loot) { + roll -= entry.weight; + if (roll < 0) return entry.item; + } + return loot.at(-1)?.item; + }; + + // takes the line out of the water, the rod in the slot looks uncast again + const stop = (player: Player | undefined, id: string) => { + const cast = casts.get(id); + casts.delete(id); + const rod = cast && player?.inventory.get(cast.slot); + if (rod?.id === FISHING_ROD) rod.data = undefined; + }; + + ctx.components.register_block("bworld:fishable", { + on_interact(block, _params, player) { + aimed.set(player.id, { + x: block.x, + y: block.y, + z: block.z, + block: block.id, + tick: ctx.system.current_tick, + }); + return false; + }, + }); + + ctx.components.register_item(FISHING_ROD, { + on_use(rod, params, player) { + const cast = casts.get(player.id); + if (cast) { + if (cast.escape_at !== undefined) { + const item = pick(params.loot); + if (item) player.give_item(item); + } + stop(player, player.id); + return; + } + const water = aimed.get(player.id); + aimed.delete(player.id); + if (water?.tick !== ctx.system.current_tick) { + // cast before the server restarted + rod.data = undefined; + return; + } + casts.set(player.id, { + x: water.x, + y: water.y, + z: water.z, + block: water.block, + slot: player.selected_slot, + params, + bite_at: ctx.system.current_tick + between(params.wait), + }); + rod.data = { cast: true }; + }, + }); + + ctx.events.after.tick.subscribe(() => { + const now = ctx.system.current_tick; + for (const [id, cast] of casts) { + const player = ctx.players.get(id); + const { x, y, z } = player?.position ?? cast; + const distance = Math.hypot(x - cast.x, y - cast.y, z - cast.z); + if ( + !player || player.selected_slot !== cast.slot || player.held_item?.id !== FISHING_ROD || + distance > LINE_LENGTH || ctx.world.get_block(cast.x, cast.y, cast.z) !== cast.block + ) { + stop(player, id); + } else if (cast.escape_at === undefined && now >= cast.bite_at) { + cast.escape_at = now + between(cast.params.bite); + player.send_message("Something's biting! Right click to reel it in"); + } else if (cast.escape_at !== undefined && now >= cast.escape_at) { + // it got away, wait for another + cast.escape_at = undefined; + cast.bite_at = now + between(cast.params.wait); + } + } + }); +} diff --git a/mods/bworld/textures/cod.png b/mods/bworld/textures/cod.png new file mode 100644 index 0000000000000000000000000000000000000000..be17046a502e84160ef94ff92ba674517a99045c GIT binary patch literal 541 zcmV+&0^Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01m(a01m(bYSxJf00007bV*G`2jm72 z3kx|e{O>6M00EszL_t(I%e|8^NLx`9hQBKzWGE!uH)y#HLa92`;!s+O;OHXG7UXT+ z1jWtORTOF6T}l@RK~jiA1__lQ1`KE=B$XtOmq*O-o-YuJ#Nl?3TuhqMLcuehd%mCl z{`Vf?x-O4i8%Gyx-MO(i(C8p;B&_GBZG$jR7<;ux^P@1nn+N}mErx{ z!4B5;PPM(A(f$4K<|olaf=(E+usqM&-l>iZf=jtFz8?UybcK|P<9RLGPLql0anh+g zZKsKNXt@gmJQ*G4<>XUFpFab@snjWCFNs=`P8iatG_Wk$n}O%Geggs0sXR)>iCPlp ztjM=7E24X51nljMRw~Za>v01*l{%N-8z>bApzSoNWj6(^n3*AfH*@PffjN~r=~Ujp zp4Xz3D|7J47X7ajnXz}Y8he3rR;1$(o2&E(=l!_q0h7t(y#vdV+@5^IvLw|)k?MKX zSk8StF>p*uX6zmP5H=aa-mT*M0Wox*6S fsEZ~3cb$I$^9#lXHxONE00000NkvXXu0mjfIF;}9 literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/cooked_cod.png b/mods/bworld/textures/cooked_cod.png new file mode 100644 index 0000000000000000000000000000000000000000..9307a892a5436d678aa713e80f122d92c9238c88 GIT binary patch literal 393 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3 zQ$0gN_s>q|Kvh3HT^vI!{I5>jo5d6;(E2`_Wt*_HqmHPcw&B;ZjW^wLcz&_mUdl1) zlve1hE8kYWt(jQcw)XhnHrwvku^V{!WYWrP?28Tmc-Q`o)%pEr>#xs+GiNqCS)8}K z!=ksZuN>47)>BY0n!#J;w&=w3nzsiWrW@SPn)T2wFllC@L&Ln= zMjmaeH3U8GOx0o8+sYTXQiZ9d#3{;2^ikrcM`{xc0+rM+-xOX@uV!?CmBC0UAb8dl k51+fcjIY05zEWUaPGV}J_S(hVz%XF&boFyt=akR{0G$q-M*si- literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/cooked_salmon.png b/mods/bworld/textures/cooked_salmon.png new file mode 100644 index 0000000000000000000000000000000000000000..9c1ce5a35ab348af743add8573580299113ce405 GIT binary patch literal 421 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85p>QK$!8;-MT+OLG}_)Usv|KoGhHohEr867=c1kC9V-A!TD(= z<%vb93;~Imc_n&&t|1C##(JiDhKBB+oy>tYF?zZQ%7J&dg_W%8LfIcD$llgszt)bKsa ze*Nta^)J_?XUp>+^O;k*vKMq9n8`n}^rY6|P79XjG{ zaxd?N9ZnQj>6?DfQ&CbVQqfV(?yQjhfqfN@4oWgw$_))1DV;~=@H6tI8qW?@`dBL< zc7>JEgQe-#vF_v7Sj+FJ?AzYZ?&#rHk-D|}ug*F#%G(=m>(&db6$pTwR!e0}k)HR1P8XS}^5JTbRSC3N4%6kw1sc)I$z JtaD0e0sz{pm&yPD literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/fishing_hook.png b/mods/bworld/textures/fishing_hook.png new file mode 100644 index 0000000000000000000000000000000000000000..a7473f9734caf564d13323a53f2546d73f289e97 GIT binary patch literal 1152 zcmV-`1b_R9P)^Nzi$L+_h6d4o@0mB)PR$Tw<&*A>S!3Rg@)nZ5?95{UP zi8BWA*vGbX`1SedoA+=0?)rk^5?I-{p`Y;?e!V|n{`8l(erNT}6VF7q%Dj!t%5&UK zKxZQ1?WgnJrSpLt9-yBW*E8*z{Q2G+$Y_du!j8L;9P5*JCD~VAHshihxW>owtJr(~ z+(q371YV;j{*D_mxzn)|-KG_ucsl*0PySoN$#=~-a4E*N&V(}_`KVB>VXDO)1viNpj1ThEDAS<6Y^4f_o;w>X za|Q3y7sWVn1@R<)o;28;Bxw?%NriF(H(yw2)lIV=ibYgzgh(bNqow1+>7E_mJ>Mi6 zW41Zb5ihQQi)ViU##C;8A_{`gI62kDFS%`w=VJ;hP*4}m5fjWu*(r+By|-lPEQdOT z`eUybvUVl_MX0R+LjnbkK%x}rFlHkHj}iK0AZPJhpa7{;Za~RiBtV?Vvo@YFTCuFW z-Pm3rgh~*DG)XeV@?L$wdW&eG>{QgNYEaXtNpq0kgN6_+%zY}Gm^ZaxX3>)6DA7la zAzF+v#hf?^wlQ@nBug=+lrxHEpOGsgKEqMCNbyBWC{|)gC0Ddh^;K)AR%1;yH*V6f z1-KT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iHq}>eS1;cGJ?NvTm<%b#1{=kH4#lgwPT-kbNm| z;qDFaCC64q-5r>r)5@6~00fKI5I6;5O^_W7UvpihQOP%AFq1f&)$5vpybLlBs#j8h z=FAN!Du`Fvn3Y3_=ftYP{uc$47P*kK%v6&HUp_V6=5M8{s@fZ>DZ>q7QP*n44|}Jo z&2R(N>bB5aQ}^ZLst1P}OtnAc(4xES=DxMO{pj804pYrTUi#4OqIISY6ZHy>QwI;7 pn9{*^?K#DW=g5(%M|YVc5PN6=7n_5!is1<(=q_H)#~p)X{|yHQF@pdA literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/grass.png b/mods/bworld/textures/grass.png deleted file mode 100644 index 65954b68b7d81a7db37c70fbea6e88c3a846b3de..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 175 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Wu7jMAr`&K2@J%=P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01m?d01m?e$8V@)00007bV*G`2jm72 z3LQ7p9v#jA00F;AL_t(I%f*wwYZGA@$3Jg9I!Ky3lhEUiK!&p^qIRg7p-WrQ=%65u zS?UyZb8zb5UtqyWFq4bLK?lL5h}222R0tLw5>L1i5>9jGa#qnLkAwC|O#IQwcYUAF z_xnEI=Xv3OoU0G-$^7!N0H`~ci+h4AYD#kXEMBcaS?WsLt9v4)EFRWnD@G#O}NZF*65Y7GFceGVX@;g}WxuHPc;h5%$TX|7L33W){t3YWHqH;8N4Y=!5%RN5KGbh|R5z7`id!de?SXUzq3lh4ZxA z!BF7Z?rfQX$oDDvUhMkd$Sj3phXI&exrKf7fcjNnU+ctK$>p;c=_Fsj_1Hwi`Ow0) zY-Xbl6E8MUPuEAn0Asm)mUs6b#YQ69$=KY*|S?a1 t.game.players()[0].inventory.to_data(); + const slot = inventory().findIndex((i: Msg) => i?.id === ROD); + t.send(1, { type: "select_slot", slot }); + const rod = () => inventory()[slot]; + const cast = () => t.send(1, { type: "use_block", x: 2, y: 100, z: 0, face: "top" }); + const reel = () => t.send(1, { type: "use_item" }); + const fish = () => inventory().filter((i: Msg) => i?.id === "bworld:cod" || i?.id === "bworld:salmon"); + // ticks until something bites, false if nothing did in 35 seconds + const wait_for_bite = () => { + t.take(1); + for (let i = 0; i < 700; i++) { + t.game.tick(); + if (t.take(1).some((m: Msg) => m.type === "chat" && m.text.includes("biting"))) return true; + } + return false; + }; + return { ...t, slot, rod, cast, reel, fish, wait_for_bite }; +} + +Deno.test("cast into water, reel in a fish once something bites", async () => { + const t = await setup(); + t.cast(); + assertEquals(t.rod()?.data, { cast: true }); + + assert(t.wait_for_bite()); + t.reel(); + assertEquals(t.fish().length, 1); + assertEquals(t.rod()?.data, undefined); +}); + +Deno.test("reeling in before a bite catches nothing", async () => { + const t = await setup(); + t.cast(); + t.reel(); + assertEquals(t.fish().length, 0); + assertEquals(t.rod()?.data, undefined); +}); + +Deno.test("right clicking air with an uncast rod does nothing", async () => { + const t = await setup(); + t.reel(); + assertEquals(t.rod()?.data, undefined); + for (let i = 0; i < 700; i++) t.game.tick(); + assertEquals(t.fish().length, 0); +}); + +Deno.test("switching away from the rod takes the line out", async () => { + const t = await setup(); + t.cast(); + t.send(1, { type: "select_slot", slot: (t.slot + 1) % 9 }); + t.game.tick(); + assertEquals(t.rod()?.data, undefined); + t.send(1, { type: "select_slot", slot: t.slot }); + assert(!t.wait_for_bite()); +}); + +Deno.test("the line comes out when the water is gone", async () => { + const t = await setup(); + t.cast(); + t.game.set_block(2, 100, 0, "bworld:stone"); + t.game.tick(); + assertEquals(t.rod()?.data, undefined); +}); + +Deno.test("a cast rod shows its cast texture", async () => { + await test_game("mods"); + const rod = new ItemStack(ROD, 1); + assertEquals(item_texture(rod), "bworld:fishing_rod"); + rod.data = { cast: true }; + assertEquals(item_texture(rod), "bworld:fishing_rod_cast"); + assertEquals(EverythingRegistry.get("items", ROD)?.max_stack, 1); +}); diff --git a/tests/mod_loading_test.ts b/tests/mod_loading_test.ts index 7935e56..896047e 100644 --- a/tests/mod_loading_test.ts +++ b/tests/mod_loading_test.ts @@ -27,12 +27,12 @@ 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); - // 33 items (20 of them tools) plus the item forms of the 37 blocks that have one - assertEquals(bworld(EverythingRegistry.entries("items")), 70); - // bworld's 15 (4 wood tools, 7 planks), the cooking pot and stove are farmersdelight's - assertEquals(game.recipes.shaped.length, 17); - // every log smelts and burns - assertEquals(game.recipes.furnace.size, 12); + // 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 and stove are farmersdelight's + assertEquals(game.recipes.shaped.length, 18); + // every log and fish smelts, every log burns + assertEquals(game.recipes.furnace.size, 14); assertEquals(game.recipes.fuel.size, 8); assertEquals(EverythingRegistry.get("blocks", "bworld:water")?.replaceable, true); // still has its code until it's a component