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
+14 -2
View File
@@ -59,8 +59,8 @@ const MAX_UNZIPPED_BYTES = 64 * 1024 * 1024;
// written into every entry, so packing the same mod twice gives the same bytes and the same hash
const FIXED_TIME = new Date(Date.UTC(2020, 0, 1));
export type ScriptSide = "server" | "client" | "worldgen" | "shared";
export const SCRIPT_SIDES: ScriptSide[] = ["server", "client", "worldgen", "shared"];
export type ScriptSide = "server" | "client" | "worldgen" | "shared" | "content";
export const SCRIPT_SIDES: ScriptSide[] = ["server", "client", "worldgen", "shared", "content"];
export interface Mod {
manifest: ManifestJson;
@@ -302,6 +302,8 @@ export function client_copy(mod: Mod): Mod {
const scripts = { ...mod.scripts };
delete scripts.server;
delete scripts.worldgen;
// players get what it registered in data, see common/mod_api/content.ts
delete scripts.content;
const {
noises: _n,
density_functions: _d,
@@ -354,3 +356,13 @@ export function png_size(bytes: Uint8Array): { width: number; height: number } |
const view = new DataView(bytes.buffer, bytes.byteOffset);
return { width: view.getUint32(16), height: view.getUint32(20) };
}
// a mod's bundled script as a url import() takes, for realms without file access
export function data_url(code: string) {
const bytes = new TextEncoder().encode(code);
let binary = "";
for (let i = 0; i < bytes.length; i += 0x8000) {
binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
}
return `data:application/javascript;base64,${btoa(binary)}`;
}