New hooks
This commit is contained in:
+18
-3
@@ -4,7 +4,14 @@
|
||||
// the block rules shared scripts register (see BlockRules in mod_api/shared.ts), run the same way on the server and on
|
||||
// clients: what states a placed block gets, and how blocks change with the blocks beside them. each side has its own
|
||||
// BlockRules, with its own world: the server's is the real one, a client's is what it shows and guesses ahead with
|
||||
import type { BlockInteraction, BlockPlacement, BlockRules as Rules, Face, SharedWorld } from "./mod_api/shared.ts";
|
||||
import type {
|
||||
BlockInteraction,
|
||||
BlockPlacement,
|
||||
BlockRules as Rules,
|
||||
Face,
|
||||
SharedBlock,
|
||||
SharedWorld,
|
||||
} from "./mod_api/shared.ts";
|
||||
import { type BlockRegistry, EverythingRegistry } from "./everything_registry.ts";
|
||||
import { default_block_value, set_state_value } from "./utils.ts";
|
||||
|
||||
@@ -124,8 +131,15 @@ export class BlockRules {
|
||||
}
|
||||
|
||||
// tells the blocks beside x y z it changed, so they can change with it like a fence joining it: their rules'
|
||||
// on_neighbor_change. the world's set_state calls this again for what they change, until nothing changes
|
||||
notify_neighbors(get_block: SharedWorld["get_block"], x: number, y: number, z: number) {
|
||||
// on_neighbor_change, then after for each, which the server runs its components' on_neighbor_change in. the
|
||||
// world's set_state calls this again for what they change, until nothing changes
|
||||
notify_neighbors(
|
||||
get_block: SharedWorld["get_block"],
|
||||
x: number,
|
||||
y: number,
|
||||
z: number,
|
||||
after?: (x: number, y: number, z: number, neighbor: SharedBlock) => void,
|
||||
) {
|
||||
const neighbor = { x, y, z, id: get_block(x, y, z) ?? "bworld:air" };
|
||||
for (const [dx, dy, dz] of NEIGHBORS) {
|
||||
const [nx, ny, nz] = [x + dx, y + dy, z + dz];
|
||||
@@ -137,6 +151,7 @@ export class BlockRules {
|
||||
const at = { x: nx, y: ny, z: nz, id };
|
||||
this.run(mod, `${rules_id} on_neighbor_change`, () => rules.on_neighbor_change!(at, params, neighbor));
|
||||
}
|
||||
after?.(nx, ny, nz, neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user