Curios and artifacts !

This commit is contained in:
2026-09-30 15:22:32 -03:00
parent 342b45d593
commit 3af5f6e54b
45 changed files with 729 additions and 43 deletions
+8 -1
View File
@@ -36,7 +36,14 @@ export class GuiContainer extends GuiInventoryScreen {
for (const slot of layout.slots) {
this.slots.push(
new Slot("screen", slot.index, MARGIN + slot.x * SLOT_SIZE, AREA_Y + slot.y * SLOT_SIZE, slot.output),
new Slot(
"screen",
slot.index,
MARGIN + slot.x * SLOT_SIZE,
AREA_Y + slot.y * SLOT_SIZE,
slot.output,
slot.icon,
),
);
}
}
+13 -2
View File
@@ -5,7 +5,9 @@ import { ClientMessage, ContainerKey, CRAFTING_RESULT_SLOT } from "$/common/prot
import { point_inside_rec } from "../../common/utils.ts";
import { InputManager } from "../input_manager.ts";
import { ClientInventories } from "../inventory.ts";
import { canvas } from "../renderer/mod.ts";
import { canvas, draw_texture_region, Texture } from "../renderer/mod.ts";
import { AssetManager } from "../assets.ts";
import { get_sprite_region } from "../sprites.ts";
import { draw_item } from "../rendering/render_utils.ts";
import { draw_tooltip, item_tooltip } from "./tooltip.ts";
import { ModGraphics } from "./mod_graphics.ts";
@@ -22,13 +24,16 @@ export class Slot {
y: number;
// can only be taken from, like the crafting or furnace result
output: boolean;
// a texture drawn while it's empty, like minecraft's armor slots
icon: string | undefined;
constructor(container: ContainerKey, index: number, x: number, y: number, output = false) {
constructor(container: ContainerKey, index: number, x: number, y: number, output = false, icon?: string) {
this.container = container;
this.index = index;
this.x = x;
this.y = y;
this.output = output;
this.icon = icon;
}
}
@@ -102,6 +107,12 @@ export class GuiInventoryScreen extends GuiScreen {
const item = this.get_container(slot.container)?.get_item(slot.index);
if (item) {
draw_item(item, this.x + slot.x, this.y + slot.y);
} else if (slot.icon) {
// where an item's sprite would be
const icon = get_sprite_region(slot.icon);
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
const [x, y, size] = [this.x + slot.x + 3, this.y + slot.y + 3, SLOT_SIZE - 6];
draw_texture_region(atlas, icon.x, icon.y, icon.width, icon.height, x, y, size, size);
}
}
highlight("slot_highlight_front");
+32 -1
View File
@@ -20,6 +20,20 @@ let client: Client | undefined;
// what mods draw on inventory screens, see GuiInventoryScreen
export const inventory_overlays: { mod: string; overlay: InventoryOverlay }[] = [];
// mod channels, see ctx.net: who listens on each channel
const net_handlers = new Map<string, { mod: string; handler: (data: unknown) => void }[]>();
// the server sent a mod message
export function receive_mod_message(channel: string, data: unknown) {
for (const { mod, handler } of net_handlers.get(channel) ?? []) {
try {
handler(data);
} catch (e) {
console.error(`[${mod}] a ${channel} handler threw:`, e);
}
}
}
// the loaded mods' recipes, and their names by id
let recipe_book = new RecipeBook();
const mod_names = new Map<string, string>();
@@ -54,6 +68,7 @@ export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
const recipes = register_mod_data(bmods.map((bmod) => ({ id: bmod.manifest.id, data: bmod.data })));
recipe_book = recipes;
inventory_overlays.length = 0;
net_handlers.clear();
mod_names.clear();
for (const listing of listings) mod_names.set(listing.id, listing.name);
@@ -89,6 +104,11 @@ function client_context(listing: ModListing): ClientContext {
const not_yet_fn = (name: string) => () => {
throw new Error(`[${mod}] ctx.ui.${name} isn't implemented yet (custom screens, see docs/modding_plan.md)`);
};
const own = (channel: string) => {
if (!channel.startsWith(`${mod}:`)) {
throw new Error(`[${mod}] channel ${channel} must be in the namespace "${mod}"`);
}
};
const known_item = (id: string) => {
const item = EverythingRegistry.get<ItemRegistry>("items", id);
if (!item) throw new Error(`[${mod}] unknown item ${id}`);
@@ -106,7 +126,18 @@ function client_context(listing: ModListing): ClientContext {
},
hud: not_yet("hud", "HUD elements") as ClientContext["hud"],
input: not_yet("input", "keybinds") as ClientContext["input"],
net: not_yet("net", "mod channels") as ClientContext["net"],
net: {
on(channel, handler) {
own(channel);
const handlers = net_handlers.get(channel) ?? [];
handlers.push({ mod, handler: handler as (data: unknown) => void });
net_handlers.set(channel, handlers);
},
send(channel, data) {
own(channel);
need_client().connection.send({ type: "mod", channel, data });
},
},
player: {
get name() {
return need_client().connection.name;
+4
View File
@@ -7,6 +7,7 @@ import { RemotePlayer } from "./entity/remote_player.ts";
import { ItemEntity } from "./entity/item_entity.ts";
import { RemoteEntity } from "./entity/remote_entity.ts";
import { Player } from "./entity/player.ts";
import { receive_mod_message } from "./mods.ts";
// minecraft's ChunkBatchSizeCalculator: how long loading a chunk takes here, so the server sends as many a tick as
// fit in CHUNK_BUDGET_MS
@@ -236,6 +237,9 @@ export class ClientPacketListener {
}
break;
}
case "mod":
receive_mod_message(message.channel, message.data);
break;
case "close_screen":
// closed by the server (the block broke), it already put everything back
client.screens = client.screens.filter((s) => !(s instanceof GuiContainer));