Curios slots rendering !

This commit is contained in:
2026-10-01 17:57:22 -03:00
parent ea9f3f61bb
commit f2c3cb8135
39 changed files with 1032 additions and 226 deletions
+55 -2
View File
@@ -1,7 +1,7 @@
// curios: accessory slots for items in the curios tags, next to the player's inventory, see
// mods/bworld/scripts/curios.ts
import { assert, assertEquals } from "@std/assert";
import { PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
import { PLAYER_MENU_EXTRA, PROTOCOL_VERSION } from "$/common/protocol.ts";
import { copy_dir, test_game } from "./helpers.ts";
import type { WorldSave } from "$/server/game/saves.ts";
@@ -27,7 +27,20 @@ async function setup(save?: WorldSave) {
version: "1.0.0",
dependencies: [{ id: "bworld", version: "*" }],
});
write("items/ring.json", { format_version: 1, item: { id: "jewelry:ring", texture: "bworld:coal" } });
// the ring shows on the player's right arm, the amulet doesn't show
const worn = { model: "jewelry:ring_worn", texture: "bworld:coal" };
write("items/ring.json", { format_version: 1, item: { id: "jewelry:ring", texture: "bworld:coal", worn } });
write("models/ring_worn.geo.json", {
format_version: "1.12.0",
"minecraft:geometry": [{
description: { identifier: "geometry.ring", texture_width: 16, texture_height: 16 },
bones: [{
name: "right_arm",
pivot: [-5, 22, 0],
cubes: [{ origin: [-8, 12, -2], size: [4, 1, 4], uv: [0, 0] }],
}],
}],
});
write("items/amulet.json", { format_version: 1, item: { id: "jewelry:amulet", texture: "bworld:coal" } });
write("tags/items/bworld/curios/ring.json", { format_version: 1, tag: { values: ["jewelry:ring"] } });
write("tags/items/bworld/curios/curio.json", { format_version: 1, tag: { values: ["jewelry:amulet"] } });
@@ -141,3 +154,43 @@ Deno.test("the giant chestplate goes in the body slot and gives 20 more health w
assertEquals(t.game.players()[0].max_health, 20);
assertEquals(t.game.players()[0].health, 20);
});
Deno.test("everyone sees what a player wears that has a worn model, and players joining later too", async () => {
const t = await setup();
const alice = t.game.players()[0].id;
t.join(2, "bob");
const worn_messages = (conn: number) => t.take(conn).filter((m: Msg) => m.type === "player_worn");
// the ring (given first) and the amulet, only the ring has a worn model
t.send(1, { type: "click", menu: 0, slot: 0, button: 0, shift: true });
t.send(1, { type: "click", menu: 0, slot: 1, button: 0, shift: true });
t.game.tick();
const ring = [{ id: alice, worn: [{ id: "jewelry:ring", count: 1 }] }];
for (const conn of [1, 2]) {
assertEquals(worn_messages(conn).map(({ id, worn }: Msg) => ({ id, worn })), ring);
}
t.game.tick();
assertEquals(worn_messages(2), [], "only sent when it changes");
// someone joining later gets it with the players already there
const carol = t.join(3, "carol");
assertEquals(carol.players.find((p: Msg) => p.id === alice).worn, ring[0].worn);
// rejoining wears it again: alice is told about herself, the others with player_join
t.game.on_disconnect(1);
t.take(2);
t.game.on_connect(1);
t.send(1, { type: "hello", name: "alice", protocol: PROTOCOL_VERSION });
t.send(1, { type: "ready" });
const messages = t.take(1);
const rejoined = messages.find((m: Msg) => m.type === "join");
assertEquals(messages.filter((m: Msg) => m.type === "player_worn").map((m: Msg) => m.worn), [ring[0].worn]);
const joined = t.take(2).find((m: Msg) => m.type === "player_join");
assertEquals(joined.player.worn, ring[0].worn);
// and taking it off
const ring_slot = PLAYER_MENU_EXTRA + curio_slot(t, "ring");
t.send(1, { type: "click", menu: 0, slot: ring_slot, button: 0, shift: true });
t.game.tick();
assertEquals(worn_messages(2).map((m: Msg) => [m.id, m.worn]), [[rejoined.id, []]]);
});