Register recipe api
This commit is contained in:
@@ -53,7 +53,7 @@ import type {
|
||||
ServerContext,
|
||||
SlotOptions,
|
||||
} from "$/common/mod_api/server.ts";
|
||||
import { ModLoadError } from "$/common/mod_loader.ts";
|
||||
import { ModLoadError, shared_recipes_api } from "$/common/mod_loader.ts";
|
||||
import {
|
||||
argument,
|
||||
block as block_argument,
|
||||
@@ -269,10 +269,17 @@ export class ModRuntime {
|
||||
// shared scripts, the block rules clients run too. their world is the server's
|
||||
async load_shared_scripts(game: GameServer, scripts: ScriptSource[]) {
|
||||
this.game = game;
|
||||
for (const { mod, version, url, engine_access, config } of scripts) {
|
||||
await loading_mod(mod, engine_access, () => this.#load_shared_script(mod, version, url, config));
|
||||
this.#shared_setup = true;
|
||||
try {
|
||||
for (const { mod, version, url, engine_access, config } of scripts) {
|
||||
await loading_mod(mod, engine_access, () => this.#load_shared_script(mod, version, url, config));
|
||||
}
|
||||
} finally {
|
||||
this.#shared_setup = false;
|
||||
}
|
||||
}
|
||||
// while shared scripts set up, the only time they can register recipes, as on clients
|
||||
#shared_setup = false;
|
||||
|
||||
async #load_shared_script(mod: string, version: string, url: string, config: Record<string, unknown>) {
|
||||
const module = await import(url);
|
||||
@@ -292,6 +299,9 @@ export class ModRuntime {
|
||||
this.fluid_rules.register(mod, id, rules);
|
||||
},
|
||||
},
|
||||
recipes: shared_recipes_api(() => this.game.recipes, () => this.#shared_setup, (message) => {
|
||||
throw new ModLoadError(mod, message);
|
||||
}),
|
||||
world: {
|
||||
get_block: world.get_block,
|
||||
get_state: world.get_state,
|
||||
|
||||
Reference in New Issue
Block a user