From d4aa663836e22770ea3c25b5922662963bf96582 Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 11 Oct 2026 21:12:07 -0300 Subject: [PATCH] Crabpot model and gui --- mods/bworld/CREDITS.md | 30 +++++++++ mods/bworld/blocks/crabpot.json | 38 ++++++++++++ mods/bworld/models/crabpot.json | 20 ++++++ mods/bworld/scripts/client.ts | 1 + mods/bworld/scripts/server.ts | 29 +++++++++ mods/bworld/textures/crabpot_bottom.png | Bin 0 -> 374 bytes mods/bworld/textures/crabpot_front.png | Bin 0 -> 435 bytes mods/bworld/textures/crabpot_side.png | Bin 0 -> 425 bytes mods/bworld/textures/crabpot_top.png | Bin 0 -> 399 bytes mods/bworld/textures/empty_slot_bait.png | Bin 0 -> 182 bytes tests/crabpot_test.ts | 75 +++++++++++++++++++++++ 11 files changed, 193 insertions(+) create mode 100644 mods/bworld/blocks/crabpot.json create mode 100644 mods/bworld/models/crabpot.json create mode 100644 mods/bworld/textures/crabpot_bottom.png create mode 100644 mods/bworld/textures/crabpot_front.png create mode 100644 mods/bworld/textures/crabpot_side.png create mode 100644 mods/bworld/textures/crabpot_top.png create mode 100644 mods/bworld/textures/empty_slot_bait.png create mode 100644 tests/crabpot_test.ts diff --git a/mods/bworld/CREDITS.md b/mods/bworld/CREDITS.md index c656e01..b16aee3 100644 --- a/mods/bworld/CREDITS.md +++ b/mods/bworld/CREDITS.md @@ -2182,3 +2182,33 @@ Credits Ajay Karat | Devil's Work.shop http://devilswork.shop/ https://devilsworkshop.itch.io/pixel-art-chess-asset-pack license: CC0 1.0 Universal (CC0 1.0) + +# Fishermens-Trap + +https://github.com/Uraneptus/Fishermens-Trap + +license: + +``` +MIT License + +Copyright (c) 2023 Uraneptus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/mods/bworld/blocks/crabpot.json b/mods/bworld/blocks/crabpot.json new file mode 100644 index 0000000..4946b3d --- /dev/null +++ b/mods/bworld/blocks/crabpot.json @@ -0,0 +1,38 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:crabpot", + "name": "Crab Pot", + "textures": { + "front": "bworld:crabpot_front", + "side": "bworld:crabpot_side", + "top": "bworld:crabpot_top", + "bottom": "bworld:crabpot_bottom" + }, + "model": "bworld:crabpot", + "item_model": "bworld:crabpot", + "render_layer": "cutout", + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + } + ], + "variants": { + "facing=1": { "y": 90 }, + "facing=2": { "y": 180 }, + "facing=3": { "y": 270 } + }, + "mining": { + "toughness": 3, + "tool": "axe" + }, + "drops": "bworld:crabpot", + "waterloggable": "bworld:water", + "interactive": true, + "components": { + "bworld:crabpot": {} + } + } +} diff --git a/mods/bworld/models/crabpot.json b/mods/bworld/models/crabpot.json new file mode 100644 index 0000000..0839364 --- /dev/null +++ b/mods/bworld/models/crabpot.json @@ -0,0 +1,20 @@ +{ + "format_version": 1, + "model": { + "id": "bworld:crabpot", + "elements": [ + { + "from": [0, 0, 3], + "to": [16, 10, 13], + "faces": { + "bottom": { "texture": "#bottom", "uv": [16, 3, 0, 13] }, + "top": { "texture": "#top", "uv": [16, 13, 0, 3] }, + "north": { "texture": "#front", "uv": [0, 3, 16, 13] }, + "south": { "texture": "#front", "uv": [0, 3, 16, 13] }, + "west": { "texture": "#side", "uv": [3, 3, 13, 13] }, + "east": { "texture": "#side", "uv": [3, 3, 13, 13] } + } + } + ] + } +} diff --git a/mods/bworld/scripts/client.ts b/mods/bworld/scripts/client.ts index d31d155..47bedcd 100644 --- a/mods/bworld/scripts/client.ts +++ b/mods/bworld/scripts/client.ts @@ -9,6 +9,7 @@ const HEIGHT = 166; export function setup(ctx: ClientContext) { ctx.ui.register_menu_screen("bworld:storage", chest_screen); ctx.ui.register_menu_screen("bworld:furnace", furnace_screen); + ctx.ui.register_menu_screen("bworld:crabpot", (menu) => container_screen(menu, HEIGHT)); ctx.ui.register_menu_screen("bworld:smithing_table", smithing_screen); ctx.ui.register_menu_screen("bworld:fishing_minigame", fishing_minigame_screen); } diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index f99c83d..8077f4c 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -9,6 +9,7 @@ export function setup(ctx: ServerContext) { const storage_menu = register_storage(ctx); register_shipping_bin(ctx, storage_menu); register_furnace(ctx); + register_crabpot(ctx); register_smithing_table(ctx); register_farming(ctx); register_fishing(ctx); @@ -261,6 +262,34 @@ const MATERIAL = 1; const ADDITION = 2; const RESULT = 3; +// the crab pot's menu: its bait slot at the top, and a row of 9 slots under it for what it catches, which players can +// only take from. it doesn't catch anything yet +const CRABPOT_BAIT = 0; +const CRABPOT_OUTPUT = 9; + +function register_crabpot(ctx: ServerContext) { + const menu_type = ctx.menus.register("bworld:crabpot", (menu, block) => { + const container = block_container(ctx, block, 1 + CRABPOT_OUTPUT); + menu.title = "Crab Pot"; + menu.add_slot(container, CRABPOT_BAIT, { x: 79, y: 17, icon: "bworld:empty_slot_bait" }); + for (let i = 0; i < CRABPOT_OUTPUT; i++) { + menu.add_slot(container, 1 + i, { x: 7 + i * 18, y: 45, output_only: true }); + } + menu.add_player_inventory(7, INVENTORY_Y); + menu.still_valid_near(block); + }); + + ctx.components.register_block("bworld:crabpot", { + on_interact(block, _params, player) { + menu_type.open(player, block); + return true; + }, + on_break(block) { + drop_contents(ctx, block); + }, + }); +} + function register_smithing_table(ctx: ServerContext) { const menu_type = ctx.menus.register("bworld:smithing_table", (menu, block, player) => { const container = ctx.containers.create(4); diff --git a/mods/bworld/textures/crabpot_bottom.png b/mods/bworld/textures/crabpot_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..b4eabd633f803e7b8d8a887ea5f6255e71c41485 GIT binary patch literal 374 zcmV-+0g3*JP)Px$FiAu~R5*>@kv~fVK@i1X;9waN*1ZD}xfBU1l1?FD@1MfLLa<12wfZ^y2DWx$ z3I)MNu&|PJHkLvZ(gef^$+;v9SH)u4%^tbJR$sI1%(CzIW`IAh(oS<_dVG3<>vkKT zUqcWH0047_#_BSL-x&bpda_c+{^1dBt}ao!I6s>Xx*Y((NN4WnR5R*Tk`PK!NRnzs zu(f@Fhr8RkjCwqAoA7J?Hd;x7V9@QLl_Yq6y3bMc`l;IlfVpj~H+S*&@`!(+A91~# UCYyTUuK)l507*qoM6N<$f(6Z^rT_o{ literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/crabpot_front.png b/mods/bworld/textures/crabpot_front.png new file mode 100644 index 0000000000000000000000000000000000000000..8cd1ef9e914542ffee55f7acf483fd7deb8bcd3c GIT binary patch literal 435 zcmV;k0ZjghP)Px$ZAnByR5*>*k}*reP!xr~mO@BcLK9Fy8j6$_DmXZ`OBbOyiGRSs$;H`!;N(9L zT*S#uaFU1)E_TokqJ~GnXZJ|4^Ll z0iq~ou5dwlu}P-acDcIs*;;F0*p8AG3J=3}exaQ09$f=2X?bAazYq$Ko68db?z?vi zL*XgxcUlu3WQIYEKM)kFs{oWL$zY+rOej1`m3a)?VWFO=C{}9#_=8i1K|WES>zcY* zD(QDx7`CI7$iClc5eiRvm61}WW@Z%{wnOo2Z>gkMtq}@O&1I!6GjUk%_}vTn;&+sD zGnd6OHByIrJL6v4Wf;Vaf(U@QLVhCipPXeT@>Pt}l?LYr`zmws7EfgU7q`B#L9gxp d^*R4reF9Ni(al@aIUfK3002ovPDHLkV1k&yx_kft literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/crabpot_side.png b/mods/bworld/textures/crabpot_side.png new file mode 100644 index 0000000000000000000000000000000000000000..79e0fdcf14c828787394b8752f5b5b19ddfe92ea GIT binary patch literal 425 zcmV;a0apHrP)Px$V@X6oR5*>*kDp+;QUA{-o$_MXkXmwW%`oO=$8JjMnO2Yb0*T+47* zIRhXnOFX@N0+3Q8^zV-Hm)_jOAi-=pN26N8Fl_+jaESK1AP|rcUtN~DVkNr;`OD!B zHWt+0`qDJpxh$@*00=5c09;{ldQqok3(hM|Z*F{$AP|teee?d7ppxX-yv7w4@9kGo zY6LkP@@3%rLLaWMSX|r06&6!-s{q6RJMWV7qBBuBVd@YNPp1R? z_5b1gsYYdq*>sMb-TmP$6m*@qmccM>%!fBxw&14T#xQLR(Px$Nl8ROR5*>@lCes|U=)SFN+BdIAkhDK-!#~xbBwE|iMelOB=fLHjdk_5iik%+rjJ9_7$X{Hd zCliSNfFO{lsuK0U6nA`* z893Is_r;f<(iOtZF6Z ts;d0b8&@{6GlS&y;XvoGErJA~ni6P;QxpvIYnDsy#_);T0(|mmyw18|5 UAO?X;!IMFhr>mdKI;Vst0J;-38~^|S literal 0 HcmV?d00001 diff --git a/tests/crabpot_test.ts b/tests/crabpot_test.ts new file mode 100644 index 0000000..e3cae18 --- /dev/null +++ b/tests/crabpot_test.ts @@ -0,0 +1,75 @@ +// the crab pot: a block with a model converted from fishermen's trap's fish trap +import { assert, assertEquals } from "@std/assert"; +import { type BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts"; +import { bake_block, type ModelJson } from "$/common/block_models.ts"; +import { shape_at } from "$/common/block_shapes.ts"; +import { get_state_value } from "$/common/utils.ts"; +import { opened_menu, test_game } from "./helpers.ts"; + +Deno.test("a crab pot is a box 10 pixels tall and deep, drawn with its textures, turned by its facing", async () => { + await test_game("mods"); + const pot = EverythingRegistry.get("blocks", "bworld:crabpot")!; + const models = Object.fromEntries(EverythingRegistry.entries("models")); + const quads = bake_block(pot, 0, models); + assertEquals(quads.length, 6); + assertEquals([...new Set(quads.map((q) => q.texture))].sort(), [ + "bworld:crabpot_bottom", + "bworld:crabpot_front", + "bworld:crabpot_side", + "bworld:crabpot_top", + ]); + assertEquals(shape_at(pot, 0), [[0, 0, 3 / 16, 1, 10 / 16, 13 / 16]]); + // facing east, turned a quarter + assertEquals(shape_at(pot, 1 << 16), [[3 / 16, 0, 0, 13 / 16, 10 / 16, 1]]); +}); + +Deno.test("a crab pot placed in water holds it, and leaves it behind when broken", async () => { + const t = await test_game("mods"); + t.join(1, "alice"); + for (let x = -2; x <= 2; x++) { + for (let z = -2; z <= 2; z++) { + t.game.set_block(x, 99, z, "bworld:stone"); + t.game.set_block(x, 100, z, "bworld:air"); + } + } + t.game.set_block(0, 100, 0, "bworld:water"); + t.send(1, { type: "move", x: 0.5, y: 100, z: 2.5, yaw: 0, pitch: 0 }); + t.send(1, { type: "chat", text: "/give bworld:crabpot 2" }); + t.send(1, { type: "select_slot", slot: 0 }); + const waterlogged = (x: number) => { + const info = t.game.world.get_block_info(x, 100, 0)!; + return get_state_value(t.game.world.get_block_value(x, 100, 0), info, "waterlogged"); + }; + + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.5, 1, 0.5] }); + assertEquals(t.game.world.get_block_id(0, 100, 0), "bworld:crabpot"); + assertEquals(waterlogged(0), 1); + // on dry ground it's dry + t.send(1, { type: "use_block", x: 1, y: 99, z: 0, face: "top", hit: [0.5, 1, 0.5] }); + assertEquals(waterlogged(1), 0); + + t.send(1, { type: "break_block", x: 0, y: 100, z: 0 }); + assertEquals(t.game.world.get_block_id(0, 100, 0), "bworld:water"); +}); + +Deno.test("right clicking a crab pot opens its menu: a bait slot on top and 9 output slots under it", async () => { + const t = await test_game("mods"); + t.join(1, "alice"); + t.game.set_block(0, 99, 0, "bworld:stone"); + t.game.set_block(0, 100, 0, "bworld:crabpot"); + t.send(1, { type: "move", x: 0.5, y: 100, z: 2.5, yaw: 0, pitch: 0 }); + t.take(1); + t.send(1, { type: "use_block", x: 0, y: 100, z: 0, face: "south", hit: [0.5, 0.5, 1] }); + const opened = opened_menu(t.take(1)); + assertEquals([opened.menu_type, opened.title], ["bworld:crabpot", "Crab Pot"]); + // then the player's 36 + assertEquals(opened.slots.length, 1 + 9 + 36); + assertEquals(opened.slots[0], { x: 79, y: 17, icon: "bworld:empty_slot_bait" }); + assertEquals( + opened.slots.slice(1, 10).map((s: { x: number; y: number }) => [s.x, s.y]), + [ + ...Array(9).keys(), + ].map((i) => [7 + i * 18, 45]), + ); + assert(opened.slots.slice(1, 10).every((s: { output?: boolean }) => s.output)); +});