This commit is contained in:
2026-10-22 19:55:59 -03:00
parent 1b30d71a47
commit 4cd29a17b3
37 changed files with 427 additions and 155 deletions
+2
View File
@@ -145,6 +145,8 @@ export interface BlockRegistry {
// right clicking it does something instead of placing a block, clients don't predict placing against it.
// behavior runs on the server, see server/game/blocks.ts
interactive?: boolean;
// the mouse wheel turned while looking at it goes to its components' on_scroll instead of the hotbar
scrollable?: boolean;
// placing a block into it replaces it, like water
replaceable?: boolean;
// the blocks (ids or #tags) it can stand on, like crops on farmland. it can't be placed elsewhere, and breaks when
+19 -1
View File
@@ -67,6 +67,9 @@ export interface BlockComponent<P = any> {
on_click?(block: BlockRef, params: P, player: Player): void;
// return true if it did something, so no block gets placed
on_interact?(block: BlockRef, params: P, player: Player): boolean;
// the player turned the mouse wheel while looking at it, for a block whose json has "scrollable": true, like a
// setting turned up and down. the wheel doesn't change their hotbar slot then
on_scroll?(block: BlockRef, params: P, player: Player, scroll: BlockScroll): void;
on_tick?(block: BlockRef, params: P, dt: number): void;
on_second?(block: BlockRef, params: P, dt: number): void;
// every morning at 06:00, for every block with data in the world, near a player or not. day is ServerWorld.day
@@ -318,6 +321,21 @@ export interface ServerWorld {
set_time(time: number): void;
}
// the mouse wheel turned at a block, see BlockComponent.on_scroll
export interface BlockScroll {
// how many notches, more than 0 turned up and less than 0 down
readonly amount: number;
readonly face: Face;
// where on the block they look, 0 to 1 on each axis, like BlockInteraction's
readonly hit: readonly [number, number, number];
}
export interface MessageOptions {
// shows it above their hotbar for a moment instead of in chat, like neoforge's overlay messages. for something
// that changes as they do it, like a setting they're scrolling through
overlay?: boolean;
}
export interface SetStateOptions {
// true when not given
update_neighbors?: boolean;
@@ -389,7 +407,7 @@ export interface Player {
readonly held_item: ItemStack | undefined;
// what doesn't fit in the inventory drops at their feet
give_item(id: Id, count?: number, data?: unknown): void;
send_message(text: string): void;
send_message(text: string, options?: MessageOptions): void;
// items drawn on them, under a key so each mod keeps its own list, like "bworld:curios". replaces what that key
// had, [] clears it. only items whose json has worn show. not saved: set it again when they join
set_worn(key: string, items: ItemStack[]): void;
+4 -1
View File
@@ -81,6 +81,7 @@ export interface BlockJson {
drops?: string;
item?: boolean;
interactive?: boolean;
scrollable?: boolean;
replaceable?: boolean;
place_on?: string[];
place_in?: string[];
@@ -320,6 +321,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (block.loot_table !== undefined) json.loot_table = block.loot_table;
if (!has_item) json.item = false;
if (block.interactive) json.interactive = true;
if (block.scrollable) json.scrollable = true;
if (!!block.replaceable !== !!block.liquid) json.replaceable = !!block.replaceable;
if (block.place_on) json.place_on = block.place_on;
if (block.place_in) json.place_in = block.place_in;
@@ -370,6 +372,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
if (json.drops !== undefined) block.drop_table = json.drops;
if (json.loot_table !== undefined) block.loot_table = json.loot_table;
if (json.interactive) block.interactive = true;
if (json.scrollable) block.scrollable = true;
if (json.replaceable ?? json.liquid) block.replaceable = true;
if (json.place_on) block.place_on = json.place_on;
if (json.place_in) block.place_in = json.place_in;
@@ -666,7 +669,7 @@ export function validate_block(json: unknown): Problems {
}
}
problems.push(...validate_text(json.name, "name"));
for (const key of ["cull_same", "transparent", "collision", "item", "interactive", "replaceable"]) {
for (const key of ["cull_same", "transparent", "collision", "item", "interactive", "scrollable", "replaceable"]) {
if (json[key] !== undefined && typeof json[key] !== "boolean") problems.push(`${key} must be true or false`);
}
if (json.tint !== undefined) {
+14 -2
View File
@@ -10,7 +10,7 @@ export const AIR_ID = "bworld:air";
// bump when a client and server of different versions can't play together.
// the server rejects a different version before the client downloads anything
export const PROTOCOL_VERSION = 23;
export const PROTOCOL_VERSION = 24;
export interface PlayerInfo {
id: string;
@@ -123,6 +123,17 @@ export type ClientMessage =
// right click on a block: interact with it, or place the held block against `face`. hit is where on the block it
// clicked, 0 to 1 on each axis, like minecraft's click location. seq is like break_block's
| { type: "use_block"; x: number; y: number; z: number; face: Faces; hit?: [number, number, number]; seq?: number }
// the mouse wheel turned while looking at a scrollable block, see BlockRegistry.scrollable. amount is how many
// notches, up above 0. face and hit are like use_block's
| {
type: "scroll_block";
x: number;
y: number;
z: number;
face: Faces;
hit: [number, number, number];
amount: number;
}
| { type: "select_slot"; slot: number }
// a slot of the open menu, or of menu 0 when none is. shift moves the stack to the other part of the menu instead,
// like minecraft's quick move. clicks for a menu that isn't open any more are ignored
@@ -224,7 +235,8 @@ export type ServerMessage =
// fields of a block's client data, see BlockRef.set_client_data. to the players who have the chunk: every field
// right after it, then each field when it changes. null when a field is gone, and every field when the block is
| { type: "block_data"; x: number; y: number; z: number; data: Record<string, unknown> }
| { type: "chat"; from?: string; text: string }
// overlay shows it above the hotbar for a moment instead of in chat, like how long a pulse repeater waits
| { type: "chat"; from?: string; text: string; overlay?: boolean }
// the player is here now. with motion, they're moving that fast (blocks per second) too: the server is moving them,
// like when knocked back, and the client keeps going that way until the next one. id counts up, see move
| { type: "teleport"; id: number; x: number; y: number; z: number; motion?: [number, number, number] }