Crabpot model and gui

This commit is contained in:
2026-10-11 21:12:07 -03:00
parent 7655d5a0ce
commit d4aa663836
11 changed files with 193 additions and 0 deletions
+30
View File
@@ -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.
```
+38
View File
@@ -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": {}
}
}
}
+20
View File
@@ -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] }
}
}
]
}
}
+1
View File
@@ -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);
}
+29
View File
@@ -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<BlockRef>("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<BlockRef>("bworld:smithing_table", (menu, block, player) => {
const container = ctx.containers.create(4);
Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

+75
View File
@@ -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<BlockRegistry>("blocks", "bworld:crabpot")!;
const models = Object.fromEntries(EverythingRegistry.entries<ModelJson>("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));
});