Proper cutting board

This commit is contained in:
2026-09-29 00:04:56 -03:00
parent a51adba46f
commit 445148e812
26 changed files with 549 additions and 16 deletions
+3
View File
@@ -140,6 +140,9 @@ export interface BlockRegistry {
place_in?: string[];
// custom components from mods and their params, the server runs them
components?: Record<string, unknown>;
// draws the item a server script gives it (ServerWorld.set_block_item) on top of it, like farmer's delight's
// cutting board. surface is the height in pixels it lies on. turned with the variant's y
item_display?: { surface: number };
compiled_states?: CompiledStateDefinition[];
}
+7
View File
@@ -175,6 +175,11 @@ export interface ServerWorld {
get_state(x: number, y: number, z: number, name: string): number | undefined;
set_state(x: number, y: number, z: number, name: string, value: number): boolean;
get_block_data<T>(x: number, y: number, z: number): T | undefined;
// the item a block with item_display shows on top of it, like a block entity renderer: saved with the block's data
// and synced to players. undefined shows nothing. it goes away with the block, without dropping
set_block_item(x: number, y: number, z: number, item: ItemStack | undefined): void;
// a copy
get_block_item(x: number, y: number, z: number): ItemStack | undefined;
// pops an item out of the block at x y z, like a broken block's drops
drop_item(x: number, y: number, z: number, item: ItemStack): void;
// an entity from entities/ with its feet at x y z. throws for kinds that don't exist
@@ -202,6 +207,8 @@ export interface Player {
readonly id: string;
readonly name: string;
readonly position: Readonly<Position>;
// where they look, in radians. 0 is north (-z), going up turning west
readonly yaw: number;
readonly inventory: Container; // 36 slots, hotbar is 0-8
readonly selected_slot: number;
readonly held_item: ItemStack | undefined;
+9
View File
@@ -55,6 +55,7 @@ export interface BlockJson {
place_in?: string[];
states?: BlockStateDefinition[];
components?: Record<string, unknown>;
item_display?: { surface: number };
}
export interface OreJson {
@@ -202,6 +203,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (block.place_in) json.place_in = block.place_in;
if (block.states) json.states = block.states;
if (block.components) json.components = block.components;
if (block.item_display) json.item_display = block.item_display;
return json;
}
@@ -233,6 +235,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
if (json.place_in) block.place_in = json.place_in;
if (json.states) block.states = json.states;
if (json.components) block.components = json.components;
if (json.item_display) block.item_display = json.item_display;
return { block, has_item: json.item ?? true };
}
@@ -436,6 +439,12 @@ export function validate_block(json: unknown): Problems {
}
}
if (json.drops !== undefined) problems.push(...validate_id(json.drops, "drops"));
if (json.item_display !== undefined) {
const surface = is_object(json.item_display) ? json.item_display.surface : undefined;
if (typeof surface !== "number" || surface < 0 || surface > 16) {
problems.push("item_display.surface must be the height in pixels items lie on, from 0 to 16");
}
}
for (const key of ["place_on", "place_in"]) {
const list = json[key];
if (list === undefined) continue;
+3
View File
@@ -166,6 +166,9 @@ export type ServerMessage =
// to the players who have the chunk, including the one who caused it, which corrects anything their client
// predicted wrong
| { type: "set_block"; x: number; y: number; z: number; id: string; state?: number }
// the item a block shows, see BlockRegistry.item_display. to the players who have the chunk, after it and whenever
// it changes. null when it shows nothing any more
| { type: "set_block_item"; x: number; y: number; z: number; item: ItemData | null }
| { type: "chat"; from?: string; text: string }
| { type: "teleport"; x: number; y: number; z: number }
| { type: "container"; container: ContainerKey; items: (ItemData | null)[] }