Neighbor Updates as a Queue

This commit is contained in:
2026-10-20 13:40:44 -03:00
parent 0af35d1e17
commit 77cd327f94
9 changed files with 348 additions and 138 deletions
+19 -19
View File
@@ -50,23 +50,6 @@ export function receive_mod_message(channel: string, data: unknown) {
}
}
// what the mods' shared scripts registered, run to guess ahead of the server, see common/block_rules.ts
export let block_rules = new BlockRules(run_mod);
// whether shared scripts are being set up, the only time they can register rules
let rules_setup = false;
// whether client scripts are being set up, the only time they can register visuals, since chunk workers are told
// which blocks have them when the level starts
let client_setup = false;
function run_mod<T>(mod: string, what: string, fn: () => T): T | undefined {
try {
return fn();
} catch (e) {
console.error(`[${mod}] ${what} threw:`, e);
return undefined;
}
}
// the world shared rules see on this client: what it shows. what they change is a guess the server corrects
const rules_world: SharedWorld = {
get_block(x, y, z) {
@@ -105,10 +88,27 @@ const rules_world: SharedWorld = {
},
};
// what the mods' shared scripts registered, run to guess ahead of the server, see common/block_rules.ts
export let block_rules = new BlockRules(run_mod, rules_world.get_block);
// whether shared scripts are being set up, the only time they can register rules
let rules_setup = false;
// whether client scripts are being set up, the only time they can register visuals, since chunk workers are told
// which blocks have them when the level starts
let client_setup = false;
function run_mod<T>(mod: string, what: string, fn: () => T): T | undefined {
try {
return fn();
} catch (e) {
console.error(`[${mod}] ${what} threw:`, e);
return undefined;
}
}
// this client changed the block at x y z ahead of the server, the blocks beside it change with it the way they will
// on the server
export function predict_neighbors(x: number, y: number, z: number) {
block_rules.notify_neighbors(rules_world.get_block, x, y, z);
block_rules.notify_neighbors(x, y, z);
}
// the loaded mods' recipes, and their names by id
@@ -162,7 +162,7 @@ export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
loading_mod(bmod.manifest.id, bmod.manifest.engine_access ?? false, fn);
// every mod's shared rules first, so client scripts can count on any mod's being there
block_rules = new BlockRules(run_mod);
block_rules = new BlockRules(run_mod, rules_world.get_block);
rules_setup = true;
for (const [i, bmod] of bmods.entries()) {
const code = bmod.scripts.shared;