Block registry api

This commit is contained in:
2026-11-12 20:41:13 -03:00
parent e7fe663746
commit 76802ed430
39 changed files with 499 additions and 100 deletions
+9 -4
View File
@@ -7,15 +7,17 @@
import { basename, dirname, resolve } from "@std/path";
import { type Mod, MOD_EXTENSION, SCRIPT_SIDES, type ScriptSide, write_mod } from "@/common/mod.ts";
import type { ManifestJson } from "@/common/mod_data.ts";
import { load_and_check, type LoadedMod, mod_deno_config } from "./check_mods.ts";
import { content_script, load_and_check, type LoadedMod, mod_deno_config } from "./check_mods.ts";
import { mod_data } from "@/common/mod_check.ts";
// what each script is bundled for: the server runs in deno, clients in browsers, worldgen and shared in both
// what each script is bundled for: the server runs in deno, clients in browsers, worldgen and shared in both. content
// scripts only run on the server
const PLATFORMS: Record<ScriptSide, "deno" | "browser"> = {
server: "deno",
client: "browser",
worldgen: "browser",
shared: "browser",
content: "deno",
};
// a mod that passed check-mods, as .cubi bytes
@@ -33,9 +35,12 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
}
const texture_json = new Map([...mod.texture_json].sort(([a], [b]) => a.localeCompare(b)));
// without what the content script registered, which the server registers again when it loads the .cubi
const data = mod_data(mod);
data.blocks = mod.blocks.filter(({ file }) => file !== content_script(mod)).map(({ json }) => json);
return write_mod({
manifest,
data: mod_data(mod),
data,
scripts,
textures,
texture_json,
@@ -80,7 +85,7 @@ if (import.meta.main) {
}
// its siblings are checked too, so references to mods it depends on can be checked
const folder = resolve(dir);
const mod = load_and_check(dirname(folder)).find((m) => resolve(m.dir) === folder);
const mod = (await load_and_check(dirname(folder))).find((m) => resolve(m.dir) === folder);
if (!mod) {
console.error(`${dir} isn't a mod folder`);
Deno.exit(1);