Predict interactions with blocks

This commit is contained in:
2026-10-10 14:21:27 -03:00
parent 7fe9c15b67
commit 79ff6f9ad5
15 changed files with 355 additions and 73 deletions
+12
View File
@@ -97,6 +97,14 @@ export interface BlockPlacement extends Position {
readonly facing: "north" | "east" | "south" | "west";
}
// a player right clicking face of a block, at hit (0 to 1 on each axis of the block), like minecraft's BlockHitResult.
// facing is the way the player looks, along the ground
export interface BlockInteraction {
readonly face: Face;
readonly hit: readonly [number, number, number];
readonly facing: "north" | "east" | "south" | "west";
}
// P is the component's params from the block json
// deno-lint-ignore no-explicit-any
export interface BlockRules<P = any> {
@@ -106,4 +114,8 @@ export interface BlockRules<P = any> {
// a block next to it (on any of the 6 sides) was placed, broken or changed its states, like minecraft's
// updateShape. neighbor is where, and what's there now
on_neighbor_change?(block: SharedBlock, params: P, neighbor: SharedBlock): void;
// a player right clicks it, like minecraft's useWithoutItem: changes only its states and its neighbors', which
// the clicking client shows right away instead of waiting for the server. return true if it did something, then
// nothing is placed. the server runs the server script's on_interact too
on_interact?(block: SharedBlock, params: P, interaction: BlockInteraction): boolean | void;
}