Rename bmod to just mod
This commit is contained in:
@@ -147,7 +147,7 @@ vanilla textures they use (pistons, redstone torches, rails) aren't in bworld ye
|
||||
**What `texture` does today.** It copies PNGs keeping their folders, since bworld already names a texture in a subfolder
|
||||
by joining the folders with `_`, which is the same id the converted models use. A `.png.mcmeta` becomes the `.json` next
|
||||
to the png, keeping only its `animation` section: bworld reads the same format. It checks every texture against the
|
||||
limits a `.bmod` checks, skips Minecraft's own textures (the remap points at bworld's), and needs `--namespace` when a
|
||||
limits a `.cubi` checks, skips Minecraft's own textures (the remap points at bworld's), and needs `--namespace` when a
|
||||
folder holds textures of more than one mod, since a texture's namespace comes from the mod it ends up in. For Create
|
||||
0.5.0.j it copies 989 textures and 11 animations, and skips the six 512×512 title screen panoramas. Its textures and
|
||||
models together make a mod `check-mods` accepts, with warnings only for the 27 missing textures.
|
||||
|
||||
@@ -22,7 +22,7 @@ deno task build && deno task server # packs the mods and starts a se
|
||||
**Getting started**
|
||||
|
||||
- [Getting Started](docs/modding/gettingstarted/index.md): making, checking, running and testing a mod
|
||||
- [Mod Files](docs/modding/gettingstarted/modfiles.md): the folder layout, `manifest.json`, scripts and `.bmod` files
|
||||
- [Mod Files](docs/modding/gettingstarted/modfiles.md): the folder layout, `manifest.json`, scripts and `.cubi` files
|
||||
|
||||
**Concepts**
|
||||
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ flowers decorate around it: `raw_generation`, `lakes`, `local_modifications`, `u
|
||||
4. **Deterministic, nothing saved.** Starts and pieces are recomputed from the seed whenever they're needed, like
|
||||
everything else generation makes. No structure data goes into saves.
|
||||
5. **Server only.** Templates, pools, structures, features and loot tables are server data, left out of the copy of a
|
||||
`.bmod` players download, like worldgen scripts are now. The only thing clients need is the blocks.
|
||||
`.cubi` players download, like worldgen scripts are now. The only thing clients need is the blocks.
|
||||
6. **No goal of matching Minecraft's positions.** bworld's seeds and random numbers aren't Java's, and its terrain is
|
||||
its own, so structures land in different places than in Minecraft with the same seed. What has to match is how pieces
|
||||
fit together and what each field means.
|
||||
@@ -219,7 +219,7 @@ its own blocks, like Trek's, or for another mod's namespace, like `remaps/waysto
|
||||
skipped.
|
||||
|
||||
An NBT reader (`common/nbt.ts`) is about 60 lines. Templates are parsed once and kept as the remapped palette and
|
||||
compact arrays: positions and palette indexes as typed arrays, block entities in a map. They're packed into `.bmod`
|
||||
compact arrays: positions and palette indexes as typed arrays, block entities in a map. They're packed into `.cubi`
|
||||
files as they are, like textures, and only the server copy keeps them.
|
||||
|
||||
### Processor Lists
|
||||
|
||||
@@ -9,13 +9,13 @@ import { sha256 } from "./common/utils.ts";
|
||||
import { createCanvas, loadImage } from "@gfx/canvas-wasm";
|
||||
import { ENGINE_TEXTURE_DIR, load_and_check, load_order, LoadedMod } from "./tools/check_mods.ts";
|
||||
import { pack_mod } from "./tools/pack_mod.ts";
|
||||
import { BMOD_EXTENSION } from "./common/bmod.ts";
|
||||
import { MOD_EXTENSION } from "./common/mod.ts";
|
||||
import { ENGINE_TEXTURES_INDEX } from "./server/host.ts";
|
||||
|
||||
// all overridable so tests can build somewhere else
|
||||
const BUILD_FOLDER = Deno.env.get("BUILD_DIR") ?? "build";
|
||||
const MODS_FOLDER = Deno.env.get("MODS_DIR") ?? "mods";
|
||||
// where the server loads .bmod files from. the build puts every mod in mods/ there, next to any others
|
||||
// where the server loads .cubi files from. the build puts every mod in mods/ there, next to any others
|
||||
const SERVER_MODS_FOLDER = Deno.env.get("SERVER_MODS_DIR") ?? "server_mods";
|
||||
|
||||
function clear_folder(folder: string) {
|
||||
@@ -104,17 +104,17 @@ function load_mods(): LoadedMod[] {
|
||||
return load_order(mods);
|
||||
}
|
||||
|
||||
// every mod in mods/ into server_mods/<id>.bmod. other .bmod files there are left alone, they're other people's mods
|
||||
// every mod in mods/ into server_mods/<id>.cubi. other .cubi files there are left alone, they're other people's mods
|
||||
async function build_mods(mods: LoadedMod[]) {
|
||||
Deno.mkdirSync(SERVER_MODS_FOLDER, { recursive: true });
|
||||
remove_old_format();
|
||||
for (const mod of mods) {
|
||||
Deno.writeFileSync(`${SERVER_MODS_FOLDER}/${mod.id}${BMOD_EXTENSION}`, await pack_mod(mod));
|
||||
Deno.writeFileSync(`${SERVER_MODS_FOLDER}/${mod.id}${MOD_EXTENSION}`, await pack_mod(mod));
|
||||
}
|
||||
console.log(`Mods: ${mods.map((m) => m.id).join(", ") || "none"}`);
|
||||
}
|
||||
|
||||
// builds before .bmod files put each mod's server script in a folder here with an index.json
|
||||
// builds before .cubi files put each mod's server script in a folder here with an index.json
|
||||
function remove_old_format() {
|
||||
for (const entry of Deno.readDirSync(SERVER_MODS_FOLDER)) {
|
||||
if (entry.isDirectory || entry.name === "index.json") {
|
||||
@@ -153,7 +153,7 @@ async function build() {
|
||||
try {
|
||||
const now = performance.now();
|
||||
clear_folder(BUILD_FOLDER);
|
||||
// checked first: a mod with errors stops the build before any .bmod is written
|
||||
// checked first: a mod with errors stops the build before any .cubi is written
|
||||
const mods = load_mods();
|
||||
await build_assets();
|
||||
await build_client();
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the texture atlas: the engine's textures and every mod's in one image, built by the client when it joins a server
|
||||
// from the textures in the server's .bmod files
|
||||
// from the textures in the server's .cubi files
|
||||
import { TEXTURE_SIZE } from "@/common/constants.ts";
|
||||
import type { SpriteRegion } from "@/common/constants.ts";
|
||||
import { type Animation, texture_animation, type TextureJson } from "@/common/texture_animation.ts";
|
||||
|
||||
+5
-5
@@ -181,12 +181,12 @@ async function join_server(address: ServerAddress, name: string, status: (text:
|
||||
|
||||
// textures, blocks and items all come from the server's mods, so this happens before anything else
|
||||
status("Downloading the server's mods...");
|
||||
const bmods = await download_mods(welcome.mods, address.base);
|
||||
const mods = await download_mods(welcome.mods, address.base);
|
||||
const textures = await engine_textures();
|
||||
const texture_json = new Map<string, TextureJson>();
|
||||
for (const bmod of bmods) {
|
||||
for (const [id, png] of bmod.textures) textures.set(id, png);
|
||||
for (const [id, json] of bmod.texture_json ?? []) texture_json.set(id, json);
|
||||
for (const mod of mods) {
|
||||
for (const [id, png] of mod.textures) textures.set(id, png);
|
||||
for (const [id, json] of mod.texture_json ?? []) texture_json.set(id, json);
|
||||
}
|
||||
const atlas = await build_atlas(textures, texture_json);
|
||||
loaded_mods = true;
|
||||
@@ -194,7 +194,7 @@ async function join_server(address: ServerAddress, name: string, status: (text:
|
||||
set_texture_animations(atlas_texture.tex, device.queue, atlas.animated);
|
||||
AssetManager.instance.assets["cubi:textures"] = atlas_texture;
|
||||
AssetManager.instance.assets["cubi:textures_info"] = atlas.regions;
|
||||
await load_client_mods(welcome.mods, bmods);
|
||||
await load_client_mods(welcome.mods, mods);
|
||||
console.log(`Mods: ${welcome.mods.map((mod) => `${mod.id} ${mod.version}`).join(", ") || "none"}`);
|
||||
|
||||
status("Joining...");
|
||||
|
||||
+23
-23
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// loads the mods the server lists: downloads their .bmod files, registers their data, then runs their client scripts.
|
||||
// loads the mods the server lists: downloads their .cubi files, registers their data, then runs their client scripts.
|
||||
// see docs/modding/networking/index.md
|
||||
import { AIR } from "@/common/constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry, type ItemRegistry } from "@/common/everything_registry.ts";
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
register_mod_data,
|
||||
shared_recipes_api,
|
||||
} from "@/common/mod_loader.ts";
|
||||
import { type Bmod, read_bmod } from "@/common/bmod.ts";
|
||||
import { type Mod, read_mod } from "@/common/mod.ts";
|
||||
import { get_state_value, set_state_value, shared_items_api } from "@/common/utils.ts";
|
||||
import { BlockRules } from "@/common/block_rules.ts";
|
||||
import { fluid_exists, FluidRules, same_fluid } from "@/common/fluids.ts";
|
||||
@@ -135,19 +135,19 @@ export function set_mods_client(game_client: Client) {
|
||||
client = game_client;
|
||||
}
|
||||
|
||||
// downloads every mod's .bmod and checks it against the hash the server listed. everything a mod runs comes from
|
||||
// downloads every mod's .cubi and checks it against the hash the server listed. everything a mod runs comes from
|
||||
// the checked bytes, never fetched twice
|
||||
export async function download_mods(listings: ModListing[], base: URL): Promise<Bmod[]> {
|
||||
export async function download_mods(listings: ModListing[], base: URL): Promise<Mod[]> {
|
||||
return await Promise.all(listings.map(async (listing) => {
|
||||
try {
|
||||
const bytes = await fetch_verified(new URL(listing.file, base), listing.sha256, `${listing.name}`);
|
||||
const bmod = read_bmod(bytes, `${listing.id}.bmod`);
|
||||
if (bmod.manifest.id !== listing.id) throw new Error(`the server listed it as ${listing.id}`);
|
||||
const mod = read_mod(bytes, `${listing.id}.cubi`);
|
||||
if (mod.manifest.id !== listing.id) throw new Error(`the server listed it as ${listing.id}`);
|
||||
// the confirm screen said whether it has engine access, going by the listing
|
||||
if ((bmod.manifest.engine_access ?? false) !== (listing.engine_access ?? false)) {
|
||||
if ((mod.manifest.engine_access ?? false) !== (listing.engine_access ?? false)) {
|
||||
throw new Error("its engine access isn't what the server listed");
|
||||
}
|
||||
return bmod;
|
||||
return mod;
|
||||
} catch (e) {
|
||||
throw new ModLoadError(listing.id, (e as Error).message);
|
||||
}
|
||||
@@ -155,14 +155,14 @@ export async function download_mods(listings: ModListing[], base: URL): Promise<
|
||||
}
|
||||
|
||||
// registers the mods' data and runs their client scripts, in the order the server listed them
|
||||
export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
|
||||
for (const [i, bmod] of bmods.entries()) {
|
||||
if (bmod.credits) {
|
||||
mod_credits.push({ name: listings[i].name, version: listings[i].version, text: bmod.credits });
|
||||
export async function load_client_mods(listings: ModListing[], mods: Mod[]) {
|
||||
for (const [i, mod] of mods.entries()) {
|
||||
if (mod.credits) {
|
||||
mod_credits.push({ name: listings[i].name, version: listings[i].version, text: mod.credits });
|
||||
}
|
||||
}
|
||||
|
||||
const recipes = register_mod_data(bmods.map((bmod) => ({ id: bmod.manifest.id, data: bmod.data })));
|
||||
const recipes = register_mod_data(mods.map((mod) => ({ id: mod.manifest.id, data: mod.data })));
|
||||
recipe_book = recipes;
|
||||
inventory_overlays.length = 0;
|
||||
menu_screens.clear();
|
||||
@@ -174,20 +174,20 @@ export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
|
||||
// for engine access mods. the last server's hooks go first
|
||||
clear_hooks();
|
||||
expose_engine({ common: common_engine(), client: client_engine() });
|
||||
const as_mod = (bmod: Bmod, fn: () => Promise<void>) =>
|
||||
loading_mod(bmod.manifest.id, bmod.manifest.engine_access ?? false, fn);
|
||||
const as_mod = (mod: Mod, fn: () => Promise<void>) =>
|
||||
loading_mod(mod.manifest.id, mod.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, rules_world.get_block);
|
||||
set_fluid_rules(new FluidRules(run_mod));
|
||||
rules_setup = true;
|
||||
for (const [i, bmod] of bmods.entries()) {
|
||||
const code = bmod.scripts.shared;
|
||||
for (const [i, mod] of mods.entries()) {
|
||||
const code = mod.scripts.shared;
|
||||
if (!code) continue;
|
||||
await as_mod(bmod, async () => {
|
||||
await as_mod(mod, async () => {
|
||||
const module = await import(script_url(code));
|
||||
if (typeof module.setup !== "function") {
|
||||
throw new ModLoadError(bmod.manifest.id, "the shared script doesn't export a setup function");
|
||||
throw new ModLoadError(mod.manifest.id, "the shared script doesn't export a setup function");
|
||||
}
|
||||
await module.setup(shared_context(listings[i]));
|
||||
});
|
||||
@@ -196,13 +196,13 @@ export async function load_client_mods(listings: ModListing[], bmods: Bmod[]) {
|
||||
check_recipe_types(recipe_book);
|
||||
|
||||
client_setup = true;
|
||||
for (const [i, bmod] of bmods.entries()) {
|
||||
const code = bmod.scripts.client;
|
||||
for (const [i, mod] of mods.entries()) {
|
||||
const code = mod.scripts.client;
|
||||
if (!code) continue;
|
||||
await as_mod(bmod, async () => {
|
||||
await as_mod(mod, async () => {
|
||||
const module = await import(script_url(code));
|
||||
if (typeof module.setup !== "function") {
|
||||
throw new ModLoadError(bmod.manifest.id, "the client script doesn't export a setup function");
|
||||
throw new ModLoadError(mod.manifest.id, "the client script doesn't export a setup function");
|
||||
}
|
||||
await module.setup(client_context(listings[i]));
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// .bmod files: a built mod in one zip, what servers load from server_mods/ and send to players. see
|
||||
// .cubi files: a built mod in one zip, what servers load from server_mods/ and send to players. see
|
||||
// docs/modding/gettingstarted/modfiles.md. the same code reads them on the server and in the browser, so it only works on bytes
|
||||
import { unzipSync, zipSync } from "fflate";
|
||||
import type { ModelFileJson } from "./block_models.ts";
|
||||
@@ -49,9 +49,9 @@ import { type FeatureJson, validate_feature } from "./worldgen/features.ts";
|
||||
import { texture_animation, type TextureJson, validate_texture_json } from "./texture_animation.ts";
|
||||
import { ENGINE_GLOBAL } from "./hooks.ts";
|
||||
|
||||
export const BMOD_EXTENSION = ".bmod";
|
||||
export const MOD_EXTENSION = ".cubi";
|
||||
|
||||
// what a .bmod can hold at most unzipped, so a small file can't unzip into gigabytes
|
||||
// what a .cubi can hold at most unzipped, so a small file can't unzip into gigabytes
|
||||
const MAX_FILES = 4096;
|
||||
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
|
||||
@@ -60,7 +60,7 @@ 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 interface Bmod {
|
||||
export interface Mod {
|
||||
manifest: ManifestJson;
|
||||
data: ModData;
|
||||
// bundled javascript, one module per side
|
||||
@@ -72,10 +72,10 @@ export interface Bmod {
|
||||
credits?: string;
|
||||
}
|
||||
|
||||
export class BmodError extends Error {
|
||||
export class ModError extends Error {
|
||||
constructor(file: string, problems: string[]) {
|
||||
super(`${file}: ${problems.join("; ")}`);
|
||||
this.name = "BmodError";
|
||||
this.name = "ModError";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,32 +87,32 @@ export class BmodError extends Error {
|
||||
// textures/<name>.png the texture <mod id>:<name>
|
||||
// textures/<name>.json its animation, if it has one
|
||||
// credits.md
|
||||
export function write_bmod(bmod: Bmod): Uint8Array<ArrayBuffer> {
|
||||
export function write_mod(mod: Mod): Uint8Array<ArrayBuffer> {
|
||||
const text = (value: string) => new TextEncoder().encode(value);
|
||||
const manifest: ManifestJson = { ...bmod.manifest, scripts: {} };
|
||||
const manifest: ManifestJson = { ...mod.manifest, scripts: {} };
|
||||
delete manifest.credits;
|
||||
|
||||
const files: Record<string, Uint8Array> = {};
|
||||
for (const side of SCRIPT_SIDES) {
|
||||
const code = bmod.scripts[side];
|
||||
const code = mod.scripts[side];
|
||||
if (code !== undefined) {
|
||||
files[`scripts/${side}.js`] = text(code);
|
||||
manifest.scripts![side] = `scripts/${side}.js`;
|
||||
}
|
||||
}
|
||||
if (Object.keys(manifest.scripts!).length === 0) delete manifest.scripts;
|
||||
if (bmod.credits !== undefined) {
|
||||
files["credits.md"] = text(bmod.credits);
|
||||
if (mod.credits !== undefined) {
|
||||
files["credits.md"] = text(mod.credits);
|
||||
manifest.credits = "credits.md";
|
||||
}
|
||||
for (const [id, png] of bmod.textures) {
|
||||
for (const [id, png] of mod.textures) {
|
||||
files[`textures/${id.split(":")[1]}.png`] = png;
|
||||
}
|
||||
for (const [id, json] of bmod.texture_json ?? []) {
|
||||
for (const [id, json] of mod.texture_json ?? []) {
|
||||
files[`textures/${id.split(":")[1]}.json`] = text(JSON.stringify(json));
|
||||
}
|
||||
files["manifest.json"] = text(JSON.stringify(manifest, null, "\t"));
|
||||
files["data.json"] = text(JSON.stringify(bmod.data));
|
||||
files["data.json"] = text(JSON.stringify(mod.data));
|
||||
|
||||
// sorted, so the order doesn't depend on how the files were collected
|
||||
const sorted: Record<string, Uint8Array> = {};
|
||||
@@ -120,8 +120,8 @@ export function write_bmod(bmod: Bmod): Uint8Array<ArrayBuffer> {
|
||||
return zipSync(sorted, { mtime: FIXED_TIME, level: 9 }) as Uint8Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
// opens and checks a .bmod. file is only for error messages. throws BmodError listing what's wrong
|
||||
export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
// opens and checks a .cubi. file is only for error messages. throws ModError listing what's wrong
|
||||
export function read_mod(bytes: Uint8Array, file: string): Mod {
|
||||
let files: Record<string, Uint8Array>;
|
||||
let count = 0;
|
||||
let total = 0;
|
||||
@@ -137,7 +137,7 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
throw new BmodError(file, [`isn't a readable .bmod: ${(e as Error).message}`]);
|
||||
throw new ModError(file, [`isn't a readable .cubi: ${(e as Error).message}`]);
|
||||
}
|
||||
|
||||
const problems: string[] = [];
|
||||
@@ -158,10 +158,10 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
|
||||
const manifest = parse("manifest.json") as ManifestJson | undefined;
|
||||
const raw_data = parse("data.json") as Partial<ModData> | undefined;
|
||||
if (!manifest || !raw_data) throw new BmodError(file, problems);
|
||||
if (!manifest || !raw_data) throw new ModError(file, problems);
|
||||
|
||||
for (const problem of validate_manifest(manifest, manifest.id)) problems.push(`manifest.json: ${problem}`);
|
||||
if (problems.length > 0) throw new BmodError(file, problems);
|
||||
if (problems.length > 0) throw new ModError(file, problems);
|
||||
const mod = manifest.id;
|
||||
|
||||
const data: ModData = {
|
||||
@@ -229,7 +229,7 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
if (typeof id === "string" && id.split(":")[0] !== mod) problems.push(`${id} isn't in this mod's namespace`);
|
||||
}
|
||||
|
||||
const scripts: Bmod["scripts"] = {};
|
||||
const scripts: Mod["scripts"] = {};
|
||||
for (const [side, path] of Object.entries(manifest.scripts ?? {})) {
|
||||
const code = text(path);
|
||||
if (!SCRIPT_SIDES.includes(side as ScriptSide) || code === undefined) {
|
||||
@@ -288,14 +288,14 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
}
|
||||
}
|
||||
|
||||
if (problems.length > 0) throw new BmodError(file, problems);
|
||||
if (problems.length > 0) throw new ModError(file, problems);
|
||||
return { manifest, data, scripts, textures, texture_json, credits };
|
||||
}
|
||||
|
||||
// the same mod without its server and worldgen scripts, the terrain's data and its config, what players get. the
|
||||
// server sends them the world
|
||||
export function client_copy(bmod: Bmod): Bmod {
|
||||
const scripts = { ...bmod.scripts };
|
||||
export function client_copy(mod: Mod): Mod {
|
||||
const scripts = { ...mod.scripts };
|
||||
delete scripts.server;
|
||||
delete scripts.worldgen;
|
||||
const {
|
||||
@@ -306,8 +306,8 @@ export function client_copy(bmod: Bmod): Bmod {
|
||||
features: _f,
|
||||
config: _c,
|
||||
...data
|
||||
} = bmod.data;
|
||||
return { ...bmod, scripts, data };
|
||||
} = mod.data;
|
||||
return { ...mod, scripts, data };
|
||||
}
|
||||
|
||||
function checked(list: unknown, name: string, validate: (json: unknown) => string[], problems: string[]): unknown[] {
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// checks between mods: dependencies, load order, and ids one mod uses from another. pure, so the build, check-mods
|
||||
// and the server (on .bmod files) all use it
|
||||
// and the server (on .cubi files) all use it
|
||||
import {
|
||||
type BlockJson,
|
||||
choice_list,
|
||||
@@ -78,7 +78,7 @@ export interface LoadedMod {
|
||||
texture_json: Map<string, TextureJson>;
|
||||
}
|
||||
|
||||
// what a mod's data files hold, as packed into its .bmod
|
||||
// what a mod's data files hold, as packed into its .cubi
|
||||
export function mod_data(mod: LoadedMod): ModData {
|
||||
return {
|
||||
blocks: mod.blocks.map((b) => b.json),
|
||||
|
||||
@@ -73,12 +73,12 @@ export interface ModData {
|
||||
config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
// a mod as the server lists it to clients, in load order: the .bmod players download, without its server script
|
||||
// a mod as the server lists it to clients, in load order: the .cubi players download, without its server script
|
||||
export interface ModListing {
|
||||
id: string;
|
||||
name: string;
|
||||
version: string;
|
||||
// sha-256 in hex of the .bmod, clients check it before using anything in it
|
||||
// sha-256 in hex of the .cubi, clients check it before using anything in it
|
||||
sha256: string;
|
||||
// where it's served from, relative to the server's root. named by its hash, so it never changes
|
||||
file: string;
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ import { current_client, update_client } from "./client_updates.ts";
|
||||
import { guard_shortcuts } from "./shortcuts.ts";
|
||||
import { center_mouse } from "./center_mouse.ts";
|
||||
|
||||
// where the project was built from: build/ and server_mods/ (the .bmod files) are bundled into the app with --include
|
||||
// where the project was built from: build/ and server_mods/ (the .cubi files) are bundled into the app with --include
|
||||
const ROOT = fromFileUrl(new URL("../", import.meta.url));
|
||||
const BUILD_DIR = join(ROOT, "build");
|
||||
|
||||
@@ -46,7 +46,7 @@ const win = new Deno.BrowserWindow({ title: "bworld", width: 1280, height: 720 }
|
||||
guard_shortcuts(win);
|
||||
|
||||
// the singleplayer game server, started the first time singleplayer connects so players who only join other servers
|
||||
// don't get a world made for them. it plays the .bmod files the app was built with
|
||||
// don't get a world made for them. it plays the .cubi files the app was built with
|
||||
let host: Promise<Host> | undefined;
|
||||
|
||||
function singleplayer_host(): Promise<Host> {
|
||||
@@ -102,7 +102,7 @@ Deno.serve(async (req) => {
|
||||
center_mouse();
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
// the singleplayer server's socket and its .bmod downloads
|
||||
// the singleplayer server's socket and its .cubi downloads
|
||||
if (url.pathname === "/ws" || url.pathname.startsWith("/mods/")) {
|
||||
try {
|
||||
return (await singleplayer_host()).handle(req);
|
||||
|
||||
@@ -34,5 +34,5 @@ from:
|
||||
Mod code from that server runs with _the page's_ origin, including its local storage. So the client lists the server's
|
||||
mods and asks before loading anything, and remembers the answer per server and mod.
|
||||
|
||||
Every `.bmod` a client downloads is checked against the SHA-256 the server listed, and scripts are run from the checked
|
||||
Every `.cubi` a client downloads is checked against the SHA-256 the server listed, and scripts are run from the checked
|
||||
bytes. That guarantees the files are the ones the server listed. It doesn't protect against a malicious server.
|
||||
|
||||
@@ -50,11 +50,11 @@ Folders in `mods/` starting with `_` or `.` are skipped, which is handy for park
|
||||
## Building and Running
|
||||
|
||||
```sh
|
||||
deno task build # packs every mod in mods/ into server_mods/<id>.bmod, and builds the client
|
||||
deno task server # starts a server with every .bmod in server_mods/
|
||||
deno task build # packs every mod in mods/ into server_mods/<id>.cubi, and builds the client
|
||||
deno task server # starts a server with every .cubi in server_mods/
|
||||
```
|
||||
|
||||
`build` refuses to pack a mod that has errors. The server checks every `.bmod` again when it starts, and a problem in
|
||||
`build` refuses to pack a mod that has errors. The server checks every `.cubi` again when it starts, and a problem in
|
||||
any mod stops it from starting, naming the mod and what's wrong. The game never runs with some mods missing.
|
||||
|
||||
Open the server's address in a browser to play. To try a change, rebuild and restart the server, then rejoin. Leaving a
|
||||
@@ -101,6 +101,6 @@ Deno.test("a hoe turns grass into farmland", async () => {
|
||||
|
||||
## Next Steps
|
||||
|
||||
- [Mod Files](modfiles.md): the manifest, the folder layout, and `.bmod` files.
|
||||
- [Mod Files](modfiles.md): the manifest, the folder layout, and `.cubi` files.
|
||||
- [Sides](../concepts/sides.md): which script runs where, and why it matters.
|
||||
- [Blocks](../blocks/index.md) and [Items](../items/index.md): most mods start here.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Mod Files
|
||||
|
||||
A mod is a folder with a `manifest.json`, some data files, textures, and up to four scripts. The build packs it into a
|
||||
single `.bmod` file, which is what servers load.
|
||||
single `.cubi` file, which is what servers load.
|
||||
|
||||
## Layout
|
||||
|
||||
@@ -109,18 +109,18 @@ this repository. That config maps the API types, which scripts import as `cubi/s
|
||||
import type { ServerContext } from "cubi/server";
|
||||
```
|
||||
|
||||
## `.bmod` Files
|
||||
## `.cubi` Files
|
||||
|
||||
A `.bmod` is a built mod in one zip file. Servers load every `.bmod` in their `server_mods/` folder, so installing a mod
|
||||
A `.cubi` is a built mod in one zip file. Servers load every `.cubi` in their `server_mods/` folder, so installing a mod
|
||||
on a server is dropping its file there and restarting.
|
||||
|
||||
```sh
|
||||
deno task pack-mod mods/copper_tools # writes copper_tools.bmod, to share
|
||||
deno task pack-mod mods/copper_tools # writes copper_tools.cubi, to share
|
||||
deno task build # packs every mod in mods/ into server_mods/
|
||||
```
|
||||
|
||||
```
|
||||
copper_tools.bmod
|
||||
copper_tools.cubi
|
||||
manifest.json # with scripts and credits pointing into the zip
|
||||
data.json # every block, model, item, entity, recipe, ore, tag and loot table, and the config
|
||||
scripts/server.js # each script bundled into one module
|
||||
@@ -134,7 +134,7 @@ copper_tools.bmod
|
||||
|
||||
- Packing checks the mod first, like `check-mods`, and refuses one with errors.
|
||||
- Packing the same mod twice gives the same bytes, so the file only changes when the mod does.
|
||||
- `deno task build` leaves other `.bmod` files in `server_mods/` alone, so mods from elsewhere can sit next to the ones
|
||||
- `deno task build` leaves other `.cubi` files in `server_mods/` alone, so mods from elsewhere can sit next to the ones
|
||||
it builds.
|
||||
- Players get a copy **without** `scripts/server.js`, `scripts/worldgen.js` and the config. See
|
||||
[Networking](../networking/index.md).
|
||||
|
||||
@@ -15,7 +15,7 @@ Prefer the Game API. Many mods hooking the same thing is a sign it should become
|
||||
`game_version` has to be one minor version: `~0.1.0` (0.1.0 and later 0.1 patches) or an exact `0.1.2`. Loading the mod
|
||||
on another version is a load error, so the server doesn't start with it.
|
||||
|
||||
Without `engine_access`, importing `cubi/engine` is an error in `check-mods`, when a `.bmod` loads, and when the script
|
||||
Without `engine_access`, importing `cubi/engine` is an error in `check-mods`, when a `.cubi` loads, and when the script
|
||||
runs. When players join from another site, the confirm screen marks mods that change the engine.
|
||||
|
||||
## Hooking
|
||||
|
||||
@@ -13,7 +13,7 @@ client server
|
||||
│◄────────────────────────────────────────┤
|
||||
│ │
|
||||
│ [another site: confirm screen] │
|
||||
│ download every .bmod, check each one's │
|
||||
│ download every .cubi, check each one's │
|
||||
│ sha256, build the texture atlas, load │
|
||||
│ data in the listed order, run client │
|
||||
│ scripts' setup, start chunk workers │
|
||||
@@ -28,9 +28,9 @@ client server
|
||||
```
|
||||
|
||||
- The client loads mods **in the order the server lists them**, so both sides register the same content the same way.
|
||||
- Every `.bmod` is checked against its SHA-256 before it's opened, and scripts run from the checked bytes, so what runs
|
||||
- Every `.cubi` is checked against its SHA-256 before it's opened, and scripts run from the checked bytes, so what runs
|
||||
is exactly what the server listed.
|
||||
- Players get each mod's `.bmod` **without its server and worldgen scripts**. The server makes that copy when it starts,
|
||||
- Players get each mod's `.cubi` **without its server and worldgen scripts**. The server makes that copy when it starts,
|
||||
named by its hash so it can be cached forever.
|
||||
- If any download, hash check or client `setup` fails, the client disconnects and says which mod failed. It never joins
|
||||
with some mods missing.
|
||||
|
||||
@@ -75,5 +75,5 @@ The engine's own textures use the `engine` namespace and come from `assets/`, no
|
||||
|
||||
## How Players Get Them
|
||||
|
||||
Textures go in the mod's `.bmod`. When a player joins, their client puts every mod's textures into one atlas. The server
|
||||
Textures go in the mod's `.cubi`. When a player joins, their client puts every mod's textures into one atlas. The server
|
||||
never decodes images.
|
||||
|
||||
@@ -9,7 +9,7 @@ generator, and a **biome source** picks biomes. The names and fields follow Mine
|
||||
the [Minecraft Wiki](https://minecraft.wiki/w/Density_function) explains most of them. Where bworld differs, it says so
|
||||
below.
|
||||
|
||||
These files are server only: they're left out of the copy of a `.bmod` players download.
|
||||
These files are server only: they're left out of the copy of a `.cubi` players download.
|
||||
|
||||
```
|
||||
my_mod/
|
||||
|
||||
@@ -23,7 +23,7 @@ A mod is built from up to three layers. Most mods only need the first one or two
|
||||
|
||||
## Status
|
||||
|
||||
**Built:** the mod loader and `.bmod` files (packing, loading from `server_mods/`, sending players a copy without the
|
||||
**Built:** the mod loader and `.cubi` files (packing, loading from `server_mods/`, sending players a copy without the
|
||||
server and worldgen scripts), delivery to clients (hashed downloads, the confirm screen for other sites, credits), the
|
||||
data layer (blocks, block models with variants, items, recipes including mods' own types, entities and entity models,
|
||||
ores), server scripts (components, events, commands, timers, storage, recipes, containers, displayed items), menus like
|
||||
@@ -34,8 +34,8 @@ and screens as a mod, world time, and worn items (an item's `worn` model, `playe
|
||||
drawn on other players and on the first person arm). See [Menus](modding/inventories/menus.md),
|
||||
[Screens](modding/gui/index.md) and [Worn Models](modding/items/index.md#worn-models).
|
||||
|
||||
The code is in `common/mod_loader.ts`, `common/mod_data.ts`, `common/mod_check.ts`, `common/bmod.ts`,
|
||||
`server/game/mod_runtime.ts`, `server/game/menu.ts`, `server/load_bmods.ts`, `client/mods.ts`, `client/menu.ts`,
|
||||
The code is in `common/mod_loader.ts`, `common/mod_data.ts`, `common/mod_check.ts`, `common/mod.ts`,
|
||||
`server/game/mod_runtime.ts`, `server/game/menu.ts`, `server/load_mods.ts`, `client/mods.ts`, `client/menu.ts`,
|
||||
`common/worldgen_loader.ts`, and for worn items `client/rendering/worn_renderer.ts`, `player_model.ts` and
|
||||
`model_math.ts`.
|
||||
|
||||
|
||||
+8
-8
@@ -6,7 +6,7 @@
|
||||
import { serveDir, serveFile } from "@std/http/file-server";
|
||||
import { join } from "@std/path";
|
||||
import { GameToHost, HostToGame, READ_DONE, READ_HEADER, READ_TOO_SMALL } from "./game/host_protocol.ts";
|
||||
import { load_bmods } from "./load_bmods.ts";
|
||||
import { load_mods } from "./load_mods.ts";
|
||||
import { list_chunks, read_chunk, write_chunks } from "./regions.ts";
|
||||
import { default_worldgen_workers, start_worldgen_workers } from "./worldgen_workers.ts";
|
||||
import type { SavedChunk } from "./game/saves.ts";
|
||||
@@ -22,7 +22,7 @@ export const DESKTOP_DOWNLOADS = ["windows.zip", "linux.zip"];
|
||||
export interface HostOptions {
|
||||
// what deno task build made: the client and the engine's assets
|
||||
build_dir: string;
|
||||
// the .bmod files to load
|
||||
// the .cubi files to load
|
||||
server_mods_dir: string;
|
||||
// <mod id>.json files that change mods' settings, see docs/modding/misc/config.md. without it every mod uses its
|
||||
// own config.json
|
||||
@@ -47,7 +47,7 @@ export interface Host {
|
||||
|
||||
// throws when the mods have problems, saying what they are
|
||||
export async function start_host(options: HostOptions): Promise<Host> {
|
||||
const mods = await load_bmods(options.server_mods_dir, engine_texture_ids(options.build_dir), options.config_dir);
|
||||
const mods = await load_mods(options.server_mods_dir, engine_texture_ids(options.build_dir), options.config_dir);
|
||||
console.log(`Mods: ${mods.map((mod) => `${mod.listing.id} ${mod.listing.version}`).join(", ") || "none"}`);
|
||||
// what players download, by path
|
||||
const downloads = new Map(mods.map((mod) => [`/${mod.listing.file}`, mod.client_bytes]));
|
||||
@@ -148,12 +148,12 @@ export async function start_host(options: HostOptions): Promise<Host> {
|
||||
type: "init",
|
||||
save,
|
||||
default_seed: options.seed ?? crypto.randomUUID(),
|
||||
mods: mods.map(({ listing, bmod }) => ({
|
||||
mods: mods.map(({ listing, mod }) => ({
|
||||
listing,
|
||||
data: bmod.data,
|
||||
server_code: bmod.scripts.server,
|
||||
worldgen_code: bmod.scripts.worldgen,
|
||||
shared_code: bmod.scripts.shared,
|
||||
data: mod.data,
|
||||
server_code: mod.scripts.server,
|
||||
worldgen_code: mod.scripts.worldgen,
|
||||
shared_code: mod.scripts.shared,
|
||||
})),
|
||||
worldgen_ports: worldgen.ports,
|
||||
} satisfies HostToGame,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the server's mods: every .bmod in server_mods/, checked, with the server's changes to their config, sorted so
|
||||
// the server's mods: every .cubi in server_mods/, checked, with the server's changes to their config, sorted so
|
||||
// dependencies load first, and with the copy players download (the same mod without its server script) ready to serve
|
||||
import { join } from "@std/path";
|
||||
import { type Bmod, BMOD_EXTENSION, client_copy, read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { client_copy, type Mod, MOD_EXTENSION, read_mod, write_mod } from "@/common/mod.ts";
|
||||
import { check_references, load_order, type LoadedMod } from "@/common/mod_check.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { data_file, FORMAT_VERSION } from "@/common/mod_data.ts";
|
||||
@@ -12,7 +12,7 @@ import { is_object, json_object } from "@/common/schema.ts";
|
||||
import { sha256 } from "@/common/utils.ts";
|
||||
|
||||
export interface ServerMod {
|
||||
bmod: Bmod;
|
||||
mod: Mod;
|
||||
listing: ModListing;
|
||||
// what's served at listing.file
|
||||
client_bytes: Uint8Array<ArrayBuffer>;
|
||||
@@ -28,7 +28,7 @@ export class ModsError extends Error {
|
||||
// engine_textures are the cubi: texture ids, for checking the textures mods use. config_dir has the server's
|
||||
// <mod id>.json files that change mods' config. a mod with problems stops the whole server from starting, the game
|
||||
// never runs with some mods missing
|
||||
export async function load_bmods(
|
||||
export async function load_mods(
|
||||
dir: string,
|
||||
engine_textures: Iterable<string>,
|
||||
config_dir?: string,
|
||||
@@ -36,7 +36,7 @@ export async function load_bmods(
|
||||
let files: string[];
|
||||
try {
|
||||
files = [...Deno.readDirSync(dir)]
|
||||
.filter((entry) => entry.isFile && entry.name.endsWith(BMOD_EXTENSION))
|
||||
.filter((entry) => entry.isFile && entry.name.endsWith(MOD_EXTENSION))
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
} catch (e) {
|
||||
@@ -45,26 +45,26 @@ export async function load_bmods(
|
||||
}
|
||||
|
||||
const problems: string[] = [];
|
||||
const by_id = new Map<string, { file: string; bmod: Bmod }>();
|
||||
const by_id = new Map<string, { file: string; mod: Mod }>();
|
||||
for (const file of files) {
|
||||
try {
|
||||
const bmod = read_bmod(Deno.readFileSync(join(dir, file)), file);
|
||||
const other = by_id.get(bmod.manifest.id);
|
||||
const mod = read_mod(Deno.readFileSync(join(dir, file)), file);
|
||||
const other = by_id.get(mod.manifest.id);
|
||||
if (other) {
|
||||
problems.push(`${file} and ${other.file} are both the mod "${bmod.manifest.id}"`);
|
||||
problems.push(`${file} and ${other.file} are both the mod "${mod.manifest.id}"`);
|
||||
continue;
|
||||
}
|
||||
by_id.set(bmod.manifest.id, { file, bmod });
|
||||
by_id.set(mod.manifest.id, { file, mod });
|
||||
} catch (e) {
|
||||
problems.push((e as Error).message);
|
||||
}
|
||||
}
|
||||
if (config_dir) {
|
||||
for (const { bmod } of by_id.values()) change_config(bmod, config_dir, problems);
|
||||
for (const { mod } of by_id.values()) change_config(mod, config_dir, problems);
|
||||
}
|
||||
|
||||
// the same checks check-mods runs on mod folders
|
||||
const loaded = [...by_id.values()].map(({ file, bmod }) => as_loaded_mod(file, bmod));
|
||||
const loaded = [...by_id.values()].map(({ file, mod }) => as_loaded_mod(file, mod));
|
||||
check_references(loaded, engine_textures);
|
||||
for (const mod of loaded) {
|
||||
const dependencies = (mod.manifest?.dependencies ?? []) as { id: string }[];
|
||||
@@ -82,29 +82,29 @@ export async function load_bmods(
|
||||
}
|
||||
if (problems.length > 0) throw new ModsError(problems);
|
||||
|
||||
return await Promise.all(ordered.map(async (mod) => {
|
||||
const bmod = by_id.get(mod.id)!.bmod;
|
||||
const client_bytes = write_bmod(client_copy(bmod));
|
||||
return await Promise.all(ordered.map(async ({ id }) => {
|
||||
const mod = by_id.get(id)!.mod;
|
||||
const client_bytes = write_mod(client_copy(mod));
|
||||
const hash = await sha256(client_bytes);
|
||||
return {
|
||||
bmod,
|
||||
mod,
|
||||
client_bytes,
|
||||
listing: {
|
||||
id: bmod.manifest.id,
|
||||
name: bmod.manifest.name,
|
||||
version: bmod.manifest.version,
|
||||
id: mod.manifest.id,
|
||||
name: mod.manifest.name,
|
||||
version: mod.manifest.version,
|
||||
sha256: hash,
|
||||
file: `mods/${hash}${BMOD_EXTENSION}`,
|
||||
file: `mods/${hash}${MOD_EXTENSION}`,
|
||||
size: client_bytes.length,
|
||||
...(bmod.manifest.engine_access ? { engine_access: true } : {}),
|
||||
...(mod.manifest.engine_access ? { engine_access: true } : {}),
|
||||
},
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
// applies config_dir/<mod id>.json to the mod's config, when the server has one
|
||||
function change_config(bmod: Bmod, config_dir: string, problems: string[]) {
|
||||
const file = join(config_dir, `${bmod.manifest.id}.json`);
|
||||
function change_config(mod: Mod, config_dir: string, problems: string[]) {
|
||||
const file = join(config_dir, `${mod.manifest.id}.json`);
|
||||
let text: string;
|
||||
try {
|
||||
text = Deno.readTextFileSync(file);
|
||||
@@ -124,9 +124,9 @@ function change_config(bmod: Bmod, config_dir: string, problems: string[]) {
|
||||
problems.push(`${file}: must be { "format_version": ${FORMAT_VERSION}, "config": { ... } }`);
|
||||
return;
|
||||
}
|
||||
const changed = apply_config(bmod.data.config ?? {}, config_file.data.config as Record<string, unknown>);
|
||||
const changed = apply_config(mod.data.config ?? {}, config_file.data.config as Record<string, unknown>);
|
||||
problems.push(...changed.problems.map((problem) => `${file}: ${problem}`));
|
||||
bmod.data.config = changed.config;
|
||||
mod.data.config = changed.config;
|
||||
}
|
||||
|
||||
// a mod's config with changes made to it, like a server's config/<mod id>.json makes: objects are changed setting by
|
||||
@@ -163,34 +163,34 @@ function json_kind(value: unknown): string {
|
||||
}
|
||||
|
||||
// in the shape the checks in common/mod_check.ts take
|
||||
function as_loaded_mod(file: string, bmod: Bmod): LoadedMod {
|
||||
function as_loaded_mod(file: string, mod: Mod): LoadedMod {
|
||||
const entries = <T>(list: T[]) => list.map((json) => ({ file: `${file} data.json`, json }));
|
||||
return {
|
||||
id: bmod.manifest.id,
|
||||
id: mod.manifest.id,
|
||||
dir: file,
|
||||
report: { id: bmod.manifest.id, errors: [], warnings: [] },
|
||||
manifest: bmod.manifest as unknown as Record<string, unknown>,
|
||||
blocks: entries(bmod.data.blocks),
|
||||
models: entries(bmod.data.models),
|
||||
items: entries(bmod.data.items),
|
||||
recipes: entries(bmod.data.recipes),
|
||||
ores: entries(bmod.data.ores),
|
||||
spawns: entries(bmod.data.spawns),
|
||||
entities: entries(bmod.data.entities),
|
||||
entity_models: entries(bmod.data.entity_models),
|
||||
effects: entries(bmod.data.effects),
|
||||
fluids: entries(bmod.data.fluids),
|
||||
tags: entries(bmod.data.tags),
|
||||
loot_tables: entries(bmod.data.loot_tables ?? []),
|
||||
biomes: entries(bmod.data.biomes ?? []),
|
||||
noises: entries(bmod.data.noises ?? []),
|
||||
density_functions: entries(bmod.data.density_functions ?? []),
|
||||
noise_settings: entries(bmod.data.noise_settings ?? []),
|
||||
biome_sources: entries(bmod.data.biome_sources ?? []),
|
||||
features: entries(bmod.data.features ?? []),
|
||||
config: bmod.data.config,
|
||||
textures: [...bmod.textures.keys()],
|
||||
report: { id: mod.manifest.id, errors: [], warnings: [] },
|
||||
manifest: mod.manifest as unknown as Record<string, unknown>,
|
||||
blocks: entries(mod.data.blocks),
|
||||
models: entries(mod.data.models),
|
||||
items: entries(mod.data.items),
|
||||
recipes: entries(mod.data.recipes),
|
||||
ores: entries(mod.data.ores),
|
||||
spawns: entries(mod.data.spawns),
|
||||
entities: entries(mod.data.entities),
|
||||
entity_models: entries(mod.data.entity_models),
|
||||
effects: entries(mod.data.effects),
|
||||
fluids: entries(mod.data.fluids),
|
||||
tags: entries(mod.data.tags),
|
||||
loot_tables: entries(mod.data.loot_tables ?? []),
|
||||
biomes: entries(mod.data.biomes ?? []),
|
||||
noises: entries(mod.data.noises ?? []),
|
||||
density_functions: entries(mod.data.density_functions ?? []),
|
||||
noise_settings: entries(mod.data.noise_settings ?? []),
|
||||
biome_sources: entries(mod.data.biome_sources ?? []),
|
||||
features: entries(mod.data.features ?? []),
|
||||
config: mod.data.config,
|
||||
textures: [...mod.textures.keys()],
|
||||
texture_files: new Map(),
|
||||
texture_json: new Map(bmod.texture_json),
|
||||
texture_json: new Map(mod.texture_json),
|
||||
};
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { GAME_VERSION } from "@/common/constants.ts";
|
||||
import { engine_version_problem, validate_manifest } from "@/common/mod_data.ts";
|
||||
import { ItemStack } from "@/common/inventory.ts";
|
||||
import { EverythingRegistry } from "@/common/everything_registry.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
import { pack_mod } from "@/tools/pack_mod.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
@@ -157,7 +157,7 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
|
||||
Deno.test("a client mod hooks LocalPlayer from its .cubi", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_engine_" });
|
||||
write_mod(dir, "floaty", {
|
||||
client: [
|
||||
@@ -175,7 +175,7 @@ Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
|
||||
});
|
||||
const mod = load_and_check(dir)[0];
|
||||
assertEquals(mod.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(mod), "floaty.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "floaty.cubi");
|
||||
const listing: ModListing = {
|
||||
id: "floaty",
|
||||
name: "floaty",
|
||||
@@ -186,7 +186,7 @@ Deno.test("a client mod hooks LocalPlayer from its .bmod", async () => {
|
||||
engine_access: true,
|
||||
};
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
|
||||
const client = { options: new Options(), level: {}, connection: { send() {} } };
|
||||
const player = new LocalPlayer(client as unknown as Client, "id", "alice");
|
||||
@@ -337,7 +337,7 @@ Deno.test("hook needs a loading mod with engine access", async () => {
|
||||
assertStringIncludes(String(import_error), `sneaky imports cubi/engine without "engine_access"`);
|
||||
});
|
||||
|
||||
Deno.test("cubi/engine without engine_access is an error in check-mods and in a .bmod", async () => {
|
||||
Deno.test("cubi/engine without engine_access is an error in check-mods and in a .cubi", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_engine_" });
|
||||
const script = `import { engine } from "cubi/engine";
|
||||
export function setup() {
|
||||
@@ -351,7 +351,7 @@ Deno.test("cubi/engine without engine_access is an error in check-mods and in a
|
||||
|
||||
// packed anyway, the bundle gives it away
|
||||
const bytes = await pack_mod(mod);
|
||||
assertThrows(() => read_bmod(bytes, "sneaky.bmod"), Error, "a script uses cubi/engine");
|
||||
assertThrows(() => read_mod(bytes, "sneaky.cubi"), Error, "a script uses cubi/engine");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { EverythingRegistry } from "@/common/everything_registry.ts";
|
||||
import type { FluidJson } from "@/common/mod_data.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import type { FluidApi } from "@/common/mod_api/shared.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import { register_mod_data } from "@/common/mod_loader.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
import { fluid_rules } from "@/client/fluid_rules.ts";
|
||||
@@ -38,7 +38,7 @@ function fluid_mod(dir: string, fluids: Record<string, unknown>, shared_script?:
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test("a mod's fluids/ file registers a fluid, packed into its .bmod", async () => {
|
||||
Deno.test("a mod's fluids/ file registers a fluid, packed into its .cubi", async () => {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_fluids_" });
|
||||
const syrup = { id: "testfluids:syrup", name: "Maple Syrup", color: "#a0522d", texture: "testfluids:syrup_still" };
|
||||
fluid_mod(dir, { "syrup.json": syrup });
|
||||
@@ -48,9 +48,9 @@ Deno.test("a mod's fluids/ file registers a fluid, packed into its .bmod", async
|
||||
assertEquals(mods[0].report.warnings, [
|
||||
"fluids/syrup.json: texture testfluids:syrup_still doesn't exist, it will show as missing",
|
||||
]);
|
||||
const bmod = read_bmod(await pack_mod(mods[0]), "testfluids.bmod");
|
||||
const mod = read_mod(await pack_mod(mods[0]), "testfluids.cubi");
|
||||
EverythingRegistry.clear();
|
||||
register_mod_data([{ id: "testfluids", data: bmod.data }]);
|
||||
register_mod_data([{ id: "testfluids", data: mod.data }]);
|
||||
assertEquals(EverythingRegistry.get<FluidJson>("fluids", "testfluids:syrup"), syrup);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
@@ -87,11 +87,11 @@ async function both_sides(ask: (fluids: FluidApi) => unknown) {
|
||||
const server = ask(game.mods.fluid_rules.api());
|
||||
|
||||
const mod = load_and_check(dir).find((m) => m.id === "testfluids")!;
|
||||
const bmod = read_bmod(await pack_mod(mod), "testfluids.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "testfluids.cubi");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const listing: ModListing = { id: "testfluids", name: "Test", version: "1.0.0", sha256: "", file: "", size: 0 };
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
return { server, client: ask(fluid_rules.api()) };
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import { mod_data } from "@/common/mod_check.ts";
|
||||
import type { ServerModSource } from "@/server/game/load_mods.ts";
|
||||
import { GameServer } from "@/server/game/game_server.ts";
|
||||
import { start_game } from "@/server/game/load_mods.ts";
|
||||
import { apply_config } from "@/server/load_bmods.ts";
|
||||
import { apply_config } from "@/server/load_mods.ts";
|
||||
import { AIR_ID, PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
import { decode_level_chunk } from "@/common/chunk_streaming.ts";
|
||||
import { CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
@@ -45,7 +45,7 @@ function read_mod_sources(mods_dir: string): ServerModSource[] {
|
||||
name: String(mod.manifest?.name),
|
||||
version: String(mod.manifest?.version),
|
||||
sha256: "source",
|
||||
file: `mods/${mod.id}.bmod`,
|
||||
file: `mods/${mod.id}.cubi`,
|
||||
size: 0,
|
||||
...(mod.manifest?.engine_access === true ? { engine_access: true } : {}),
|
||||
},
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
// mods' config.json: their settings, which servers and tests can change, see docs/modding/misc/config.md
|
||||
import { assert, assertEquals, assertRejects } from "@std/assert";
|
||||
import { read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod, write_mod } from "@/common/mod.ts";
|
||||
import type { ModData } from "@/common/mod_loader.ts";
|
||||
import { apply_config, load_bmods } from "@/server/load_bmods.ts";
|
||||
import { apply_config, load_mods } from "@/server/load_mods.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
import { create_mod } from "@/tools/new_mod.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
@@ -90,22 +90,22 @@ Deno.test("a server changes a mod's settings with config/<mod id>.json, and play
|
||||
Deno.mkdirSync(`${dir}/server_mods`);
|
||||
Deno.mkdirSync(`${dir}/config`);
|
||||
Deno.writeFileSync(
|
||||
`${dir}/server_mods/tiny.bmod`,
|
||||
write_bmod({
|
||||
`${dir}/server_mods/tiny.cubi`,
|
||||
write_mod({
|
||||
manifest: { format_version: 1, id: "tiny", name: "Tiny", version: "1.0.0" },
|
||||
data,
|
||||
scripts: {},
|
||||
textures: new Map(),
|
||||
}),
|
||||
);
|
||||
const config_of = async () => (await load_bmods(`${dir}/server_mods`, [], `${dir}/config`))[0].bmod.data.config;
|
||||
const config_of = async () => (await load_mods(`${dir}/server_mods`, [], `${dir}/config`))[0].mod.data.config;
|
||||
|
||||
assertEquals(await config_of(), data.config, "without a file, the mod's own");
|
||||
|
||||
Deno.writeTextFileSync(`${dir}/config/tiny.json`, config_file({ ore: { depth: 50 } }));
|
||||
assertEquals(await config_of(), { speed: 16, ore: { size: 4, depth: 50 } });
|
||||
const [mod] = await load_bmods(`${dir}/server_mods`, [], `${dir}/config`);
|
||||
assertEquals(read_bmod(mod.client_bytes, mod.listing.file).data.config, undefined);
|
||||
const [mod] = await load_mods(`${dir}/server_mods`, [], `${dir}/config`);
|
||||
assertEquals(read_mod(mod.client_bytes, mod.listing.file).data.config, undefined);
|
||||
|
||||
Deno.writeTextFileSync(`${dir}/config/tiny.json`, config_file({ ore: { depht: 50 } }));
|
||||
await assertRejects(config_of, Error, "ore.depht");
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// .bmod files: packing mods, reading them back, and the server loading a folder of them
|
||||
// .cubi files: packing mods, reading them back, and the server loading a folder of them
|
||||
import { assert, assertEquals, assertRejects, assertStringIncludes, assertThrows } from "@std/assert";
|
||||
import { zipSync } from "fflate";
|
||||
import { ATLAS_BORDER, atlas_layout, extrude_borders } from "@/client/atlas.ts";
|
||||
import { MAX_TEXTURE_SIZE } from "@/common/constants.ts";
|
||||
import { type Bmod, read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { type Mod, read_mod, write_mod } from "@/common/mod.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
import { pack_mod } from "@/tools/pack_mod.ts";
|
||||
import { create_mod } from "@/tools/new_mod.ts";
|
||||
import { load_bmods } from "@/server/load_bmods.ts";
|
||||
import { load_mods } from "@/server/load_mods.ts";
|
||||
import { start_host } from "@/server/host.ts";
|
||||
import { copy_dir } from "./helpers.ts";
|
||||
import { PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
@@ -20,35 +20,35 @@ import { list_chunks, read_chunk, write_chunks } from "@/server/regions.ts";
|
||||
|
||||
const ENGINE_TEXTURES = ["cubi:missing", ...Array.from({ length: 9 }, (_, i) => `cubi:break_${i}`)];
|
||||
|
||||
// mods/bworld and one made from the template, packed into a folder of .bmod files
|
||||
// mods/bworld and one made from the template, packed into a folder of .cubi files
|
||||
async function packed_mods() {
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_bmod_src_" });
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_mod_src_" });
|
||||
copy_dir("mods/bworld", `${sources}/bworld`);
|
||||
create_mod("copper_tools", "Copper Tools", sources);
|
||||
const mods = load_and_check(sources);
|
||||
for (const mod of mods) assertEquals(mod.report.errors, [], mod.id);
|
||||
|
||||
const folder = Deno.makeTempDirSync({ prefix: "bworld_bmod_" });
|
||||
for (const mod of mods) Deno.writeFileSync(`${folder}/${mod.id}.bmod`, await pack_mod(mod));
|
||||
const folder = Deno.makeTempDirSync({ prefix: "bworld_mod_" });
|
||||
for (const mod of mods) Deno.writeFileSync(`${folder}/${mod.id}.cubi`, await pack_mod(mod));
|
||||
return { sources, folder, mods };
|
||||
}
|
||||
|
||||
Deno.test("packing a mod keeps its data, scripts, textures and credits, and gives the same bytes every time", async () => {
|
||||
const { sources, folder, mods } = await packed_mods();
|
||||
const template = mods.find((mod) => mod.id === "copper_tools")!;
|
||||
const bytes = Deno.readFileSync(`${folder}/copper_tools.bmod`);
|
||||
const bytes = Deno.readFileSync(`${folder}/copper_tools.cubi`);
|
||||
assertEquals(await pack_mod(template), bytes);
|
||||
|
||||
const bmod = read_bmod(bytes, "copper_tools.bmod");
|
||||
assertEquals(bmod.manifest.id, "copper_tools");
|
||||
assertEquals(bmod.data.blocks.map((b) => b.id), template.blocks.map((b) => b.json.id));
|
||||
assertEquals(bmod.data.recipes, template.recipes.map((r) => r.json));
|
||||
assertEquals([...bmod.textures.keys()].sort(), [...template.textures].sort());
|
||||
assertEquals(Object.keys(bmod.scripts).sort(), ["client", "server", "worldgen"]);
|
||||
assertStringIncludes(bmod.scripts.server!, "setup");
|
||||
assert(bmod.credits);
|
||||
const mod = read_mod(bytes, "copper_tools.cubi");
|
||||
assertEquals(mod.manifest.id, "copper_tools");
|
||||
assertEquals(mod.data.blocks.map((b) => b.id), template.blocks.map((b) => b.json.id));
|
||||
assertEquals(mod.data.recipes, template.recipes.map((r) => r.json));
|
||||
assertEquals([...mod.textures.keys()].sort(), [...template.textures].sort());
|
||||
assertEquals(Object.keys(mod.scripts).sort(), ["client", "server", "worldgen"]);
|
||||
assertStringIncludes(mod.scripts.server!, "setup");
|
||||
assert(mod.credits);
|
||||
|
||||
const bworld = read_bmod(Deno.readFileSync(`${folder}/bworld.bmod`), "bworld.bmod");
|
||||
const bworld = read_mod(Deno.readFileSync(`${folder}/bworld.cubi`), "bworld.cubi");
|
||||
assertEquals(bworld.data.blocks.length, [...Deno.readDirSync("mods/bworld/blocks")].length);
|
||||
assertEquals(Object.keys(bworld.scripts), ["server", "client", "worldgen", "shared"]);
|
||||
|
||||
@@ -56,33 +56,33 @@ Deno.test("packing a mod keeps its data, scripts, textures and credits, and give
|
||||
Deno.removeSync(folder, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("broken .bmod files are turned away, saying why", () => {
|
||||
Deno.test("broken .cubi files are turned away, saying why", () => {
|
||||
const text = (value: unknown) => new TextEncoder().encode(JSON.stringify(value));
|
||||
const manifest = { format_version: 1, id: "broken", name: "Broken", version: "1.0.0" };
|
||||
const zip = (files: Record<string, Uint8Array>) => zipSync(files);
|
||||
|
||||
assertThrows(() => read_bmod(new TextEncoder().encode("not a zip"), "a.bmod"), Error, "isn't a readable .bmod");
|
||||
assertThrows(() => read_bmod(zip({ "data.json": text({}) }), "b.bmod"), Error, "manifest.json is missing");
|
||||
assertThrows(() => read_mod(new TextEncoder().encode("not a zip"), "a.cubi"), Error, "isn't a readable .cubi");
|
||||
assertThrows(() => read_mod(zip({ "data.json": text({}) }), "b.cubi"), Error, "manifest.json is missing");
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zip({
|
||||
"manifest.json": text(manifest),
|
||||
"data.json": text({ blocks: [{ id: "other:thing", textures: "broken:x" }, { id: "broken:y" }] }),
|
||||
}),
|
||||
"c.bmod",
|
||||
"c.cubi",
|
||||
),
|
||||
Error,
|
||||
"other:thing isn't in this mod's namespace",
|
||||
);
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zip({
|
||||
"manifest.json": text({ ...manifest, scripts: { server: "scripts/server.js" } }),
|
||||
"data.json": text({}),
|
||||
}),
|
||||
"d.bmod",
|
||||
"d.cubi",
|
||||
),
|
||||
Error,
|
||||
"scripts.server scripts/server.js isn't in the file",
|
||||
@@ -94,9 +94,9 @@ Deno.test("broken .bmod files are turned away, saying why", () => {
|
||||
new DataView(big.buffer).setUint32(20, 16);
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zip({ "manifest.json": text(manifest), "data.json": text({}), "textures/big.png": big }),
|
||||
"e.bmod",
|
||||
"e.cubi",
|
||||
),
|
||||
Error,
|
||||
`textures can be at most ${MAX_TEXTURE_SIZE}×${MAX_TEXTURE_SIZE}`,
|
||||
@@ -104,46 +104,46 @@ Deno.test("broken .bmod files are turned away, saying why", () => {
|
||||
// too much once unzipped, without unzipping it all
|
||||
const huge = new Uint8Array(65 * 1024 * 1024);
|
||||
assertThrows(
|
||||
() => read_bmod(zip({ "manifest.json": text(manifest), "data.json": text({}), "big.bin": huge }), "f.bmod"),
|
||||
() => read_mod(zip({ "manifest.json": text(manifest), "data.json": text({}), "big.bin": huge }), "f.cubi"),
|
||||
Error,
|
||||
"unzips to more than",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("the server loads every .bmod in its folder, dependencies first, and players get them without server scripts", async () => {
|
||||
Deno.test("the server loads every .cubi in its folder, dependencies first, and players get them without server scripts", async () => {
|
||||
const { sources, folder } = await packed_mods();
|
||||
const mods = await load_bmods(folder, ENGINE_TEXTURES);
|
||||
const mods = await load_mods(folder, ENGINE_TEXTURES);
|
||||
assertEquals(mods.map((mod) => mod.listing.id), ["bworld", "copper_tools"]);
|
||||
|
||||
for (const mod of mods) {
|
||||
assertEquals(mod.listing.file, `mods/${mod.listing.sha256}.bmod`);
|
||||
assertEquals(mod.listing.file, `mods/${mod.listing.sha256}.cubi`);
|
||||
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", mod.client_bytes));
|
||||
assertEquals([...digest].map((b) => b.toString(16).padStart(2, "0")).join(""), mod.listing.sha256);
|
||||
const copy = read_bmod(mod.client_bytes, mod.listing.file);
|
||||
const copy = read_mod(mod.client_bytes, mod.listing.file);
|
||||
assertEquals(copy.scripts.server, undefined, "server scripts never go to players");
|
||||
assertEquals(copy.scripts.worldgen, undefined, "players get the world from the server, not its generator");
|
||||
assertEquals(copy.scripts.shared, mod.bmod.scripts.shared, "players run the shared rules too");
|
||||
assertEquals(copy.scripts.shared, mod.mod.scripts.shared, "players run the shared rules too");
|
||||
// the terrain's data stays on the server too, the rest is the same
|
||||
const { noises, density_functions, noise_settings, biome_sources, ...data } = mod.bmod.data;
|
||||
const { noises, density_functions, noise_settings, biome_sources, ...data } = mod.mod.data;
|
||||
assertEquals(copy.data, { ...data, noises: [], density_functions: [], noise_settings: [], biome_sources: [] });
|
||||
if (mod.listing.id === "bworld") {
|
||||
assert([noises, density_functions, noise_settings, biome_sources].every((list) => list!.length > 0));
|
||||
}
|
||||
}
|
||||
assert(mods[1].bmod.scripts.server, "the server still has it");
|
||||
assert(mods[1].mod.scripts.server, "the server still has it");
|
||||
|
||||
// the same mod twice, and a mod whose dependency isn't there
|
||||
Deno.copyFileSync(`${folder}/copper_tools.bmod`, `${folder}/copper_tools_again.bmod`);
|
||||
await assertRejects(() => load_bmods(folder, ENGINE_TEXTURES), Error, 'are both the mod "copper_tools"');
|
||||
Deno.removeSync(`${folder}/copper_tools_again.bmod`);
|
||||
Deno.removeSync(`${folder}/bworld.bmod`);
|
||||
await assertRejects(() => load_bmods(folder, ENGINE_TEXTURES), Error, `depends on "bworld"`);
|
||||
Deno.copyFileSync(`${folder}/copper_tools.cubi`, `${folder}/copper_tools_again.cubi`);
|
||||
await assertRejects(() => load_mods(folder, ENGINE_TEXTURES), Error, 'are both the mod "copper_tools"');
|
||||
Deno.removeSync(`${folder}/copper_tools_again.cubi`);
|
||||
Deno.removeSync(`${folder}/bworld.cubi`);
|
||||
await assertRejects(() => load_mods(folder, ENGINE_TEXTURES), Error, `depends on "bworld"`);
|
||||
|
||||
Deno.removeSync(sources, { recursive: true });
|
||||
Deno.removeSync(folder, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("the host serves each mod's player copy by its hash, and a game made from .bmod files plays", async () => {
|
||||
Deno.test("the host serves each mod's player copy by its hash, and a game made from .cubi files plays", async () => {
|
||||
const { sources, folder } = await packed_mods();
|
||||
const build = Deno.makeTempDirSync({ prefix: "bworld_build_" });
|
||||
Deno.mkdirSync(`${build}/assets/textures`, { recursive: true });
|
||||
@@ -157,31 +157,31 @@ Deno.test("the host serves each mod's player copy by its hash, and a game made f
|
||||
build_dir: build,
|
||||
server_mods_dir: folder,
|
||||
world_dir: world,
|
||||
seed: "bmod-seed",
|
||||
seed: "mod-seed",
|
||||
on_fatal: (message) => {
|
||||
throw new Error(message);
|
||||
},
|
||||
});
|
||||
const listings = (await load_bmods(folder, ENGINE_TEXTURES)).map((mod) => mod.listing);
|
||||
const listings = (await load_mods(folder, ENGINE_TEXTURES)).map((mod) => mod.listing);
|
||||
for (const listing of listings) {
|
||||
const response = await host.handle(new Request(`http://localhost/${listing.file}`));
|
||||
assertEquals(response.status, 200);
|
||||
assertEquals(response.headers.get("access-control-allow-origin"), "*");
|
||||
const bmod = read_bmod(new Uint8Array(await response.arrayBuffer()), listing.file);
|
||||
assertEquals(bmod.manifest.id, listing.id);
|
||||
const mod = read_mod(new Uint8Array(await response.arrayBuffer()), listing.file);
|
||||
assertEquals(mod.manifest.id, listing.id);
|
||||
}
|
||||
assertEquals((await host.handle(new Request("http://localhost/mods/nope.bmod"))).status, 404);
|
||||
assertEquals((await host.handle(new Request("http://localhost/mods/nope.cubi"))).status, 404);
|
||||
|
||||
// the game worker loaded both mods, including the template's server script, and saves
|
||||
await host.shutdown();
|
||||
const saved = JSON.parse(Deno.readTextFileSync(`${world}/level.json`));
|
||||
assertEquals(saved.seed, "bmod-seed");
|
||||
assertEquals(saved.seed, "mod-seed");
|
||||
|
||||
for (const dir of [sources, folder, build]) Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("a mod with its own deno.json is bundled with it", async () => {
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_bmod_project_" });
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_mod_project_" });
|
||||
copy_dir("mods/bworld", `${sources}/bworld`);
|
||||
const mod = `${sources}/project`;
|
||||
Deno.mkdirSync(`${mod}/scripts/lib`, { recursive: true });
|
||||
@@ -205,8 +205,8 @@ Deno.test("a mod with its own deno.json is bundled with it", async () => {
|
||||
|
||||
const project = load_and_check(sources).find((m) => m.id === "project")!;
|
||||
assertEquals(project.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(project), "project.bmod");
|
||||
assertStringIncludes(bmod.scripts.server!, "hello from a deno project");
|
||||
const packed = read_mod(await pack_mod(project), "project.cubi");
|
||||
assertStringIncludes(packed.scripts.server!, "hello from a deno project");
|
||||
Deno.removeSync(sources, { recursive: true });
|
||||
});
|
||||
|
||||
@@ -415,9 +415,9 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
// write_bmod without anything optional still makes a file read_bmod takes
|
||||
// write_mod without anything optional still makes a file read_mod takes
|
||||
Deno.test("a mod with only data packs and reads", () => {
|
||||
const bmod: Bmod = {
|
||||
const mod: Mod = {
|
||||
manifest: { format_version: 1, id: "tiny", name: "Tiny", version: "1.0.0" },
|
||||
data: {
|
||||
blocks: [],
|
||||
@@ -435,5 +435,5 @@ Deno.test("a mod with only data packs and reads", () => {
|
||||
scripts: {},
|
||||
textures: new Map(),
|
||||
};
|
||||
assertEquals(read_bmod(write_bmod(bmod), "tiny.bmod").manifest.id, "tiny");
|
||||
assertEquals(read_mod(write_mod(mod), "tiny.cubi").manifest.id, "tiny");
|
||||
});
|
||||
@@ -6,7 +6,7 @@
|
||||
import { assert, assertEquals, assertRejects } from "@std/assert";
|
||||
import { EverythingRegistry } from "@/common/everything_registry.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
import { load_order } from "@/common/mod_check.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
@@ -89,11 +89,11 @@ const seen = globalThis as unknown as Record<string, unknown>;
|
||||
async function load_client(dir: string) {
|
||||
const mod = load_and_check(dir).find((m) => m.id === "testrecipes")!;
|
||||
assertEquals(mod.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(mod), "testrecipes.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "testrecipes.cubi");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const listing: ModListing = { id: "testrecipes", name: "Test", version: "1.0.0", sha256: "", file: "", size: 0 };
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
}
|
||||
|
||||
Deno.test("recipes a shared script registers are on the server and clients, for their scripts and crafting", async () => {
|
||||
@@ -223,7 +223,7 @@ Deno.test("recipes can only be registered while shared scripts set up", async ()
|
||||
|
||||
Deno.test("every mod's recipe types are registered on a client too, so it loads them", async () => {
|
||||
const mods = load_order(load_and_check("mods"));
|
||||
const bmods = await Promise.all(mods.map(async (mod) => read_bmod(await pack_mod(mod), `${mod.id}.bmod`)));
|
||||
const packed = await Promise.all(mods.map(async (mod) => read_mod(await pack_mod(mod), `${mod.id}.cubi`)));
|
||||
const listings = mods.map((mod): ModListing => ({
|
||||
id: mod.id,
|
||||
name: mod.id,
|
||||
@@ -233,5 +233,5 @@ Deno.test("every mod's recipe types are registered on a client too, so it loads
|
||||
size: 0,
|
||||
}));
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods(listings, bmods);
|
||||
await load_client_mods(listings, packed);
|
||||
});
|
||||
|
||||
+4
-4
@@ -9,7 +9,7 @@ import { type BlockRegistry, EverythingRegistry } from "@/common/everything_regi
|
||||
import type { ManifestJson, TagJson } from "@/common/mod_data.ts";
|
||||
import { resolve_tags, tag_api, type TagSource } from "@/common/tags.ts";
|
||||
import { can_stand_on } from "@/common/utils.ts";
|
||||
import { read_bmod, write_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod, write_mod } from "@/common/mod.ts";
|
||||
import { update_crafting_result } from "@/server/game/crafting.ts";
|
||||
import { check_mods } from "@/tools/check_mods.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
@@ -208,7 +208,7 @@ Deno.test("check-mods finds broken tags and tags nobody defines", async () => {
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
|
||||
Deno.test("tags survive packing into a .bmod", () => {
|
||||
Deno.test("tags survive packing into a .cubi", () => {
|
||||
const tag: TagJson = { registry: "items", id: "c:ingots/tin", values: ["x:tin", { id: "y:tin", required: false }] };
|
||||
const data = {
|
||||
blocks: [],
|
||||
@@ -224,6 +224,6 @@ Deno.test("tags survive packing into a .bmod", () => {
|
||||
tags: [tag],
|
||||
};
|
||||
const manifest: ManifestJson = { format_version: 1, id: "x", name: "X", version: "1.0.0" };
|
||||
const bmod = read_bmod(write_bmod({ manifest, data, scripts: {}, textures: new Map() }), "x.bmod");
|
||||
assertEquals(bmod.data.tags, [tag]);
|
||||
const mod = read_mod(write_mod({ manifest, data, scripts: {}, textures: new Map() }), "x.cubi");
|
||||
assertEquals(mod.data.tags, [tag]);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// animated textures: textures/<name>.json, carrying it through .bmod files, and playing it a tick at a time
|
||||
// animated textures: textures/<name>.json, carrying it through .cubi files, and playing it a tick at a time
|
||||
import { assertEquals, assertThrows } from "@std/assert";
|
||||
import { zipSync } from "fflate";
|
||||
import { read_bmod, texture_size_problem } from "@/common/bmod.ts";
|
||||
import { read_mod, texture_size_problem } from "@/common/mod.ts";
|
||||
import { texture_animation, validate_texture_json } from "@/common/texture_animation.ts";
|
||||
import { AnimatedTexture } from "@/client/texture_animations.ts";
|
||||
import { load_and_check } from "@/tools/check_mods.ts";
|
||||
@@ -70,7 +70,7 @@ Deno.test("an animated texture's frames have to fit the size limit, not its whol
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("a texture's .json is checked, packed into the .bmod and read back", async () => {
|
||||
Deno.test("a texture's .json is checked, packed into the .cubi and read back", async () => {
|
||||
const sources = Deno.makeTempDirSync({ prefix: "bworld_anim_src_" });
|
||||
copy_dir("mods/bworld", `${sources}/bworld`);
|
||||
create_mod("lava_lamps", "Lava Lamps", sources);
|
||||
@@ -83,8 +83,8 @@ Deno.test("a texture's .json is checked, packed into the .bmod and read back", a
|
||||
const lamps = () => load_and_check(sources).find((m) => m.id === "lava_lamps")!;
|
||||
const mod = lamps();
|
||||
assertEquals(mod.report.errors, []);
|
||||
const bmod = read_bmod(await pack_mod(mod), "lava_lamps.bmod");
|
||||
assertEquals([...bmod.texture_json!], [["lava_lamps:lamps_goo", json]]);
|
||||
const packed = read_mod(await pack_mod(mod), "lava_lamps.cubi");
|
||||
assertEquals([...packed.texture_json!], [["lava_lamps:lamps_goo", json]]);
|
||||
|
||||
// a .json without its png, or one that doesn't fit it, is an error
|
||||
Deno.writeTextFileSync(`${textures}/stray.json`, JSON.stringify(json));
|
||||
@@ -103,14 +103,14 @@ Deno.test("a texture's .json is checked, packed into the .bmod and read back", a
|
||||
const manifest = { format_version: 1, id: "broken", name: "Broken", version: "1.0.0" };
|
||||
assertThrows(
|
||||
() =>
|
||||
read_bmod(
|
||||
read_mod(
|
||||
zipSync({
|
||||
"manifest.json": text(manifest),
|
||||
"data.json": text({}),
|
||||
"textures/goo.png": png_header(16, 32),
|
||||
"textures/goo.json": text({ animation: { frames: [2] } }),
|
||||
}),
|
||||
"broken.bmod",
|
||||
"broken.cubi",
|
||||
),
|
||||
Error,
|
||||
"textures/goo.json: animation.frames[0] isn't one of the png's frames, 0 to 1",
|
||||
|
||||
@@ -9,7 +9,7 @@ import { BlockRegistry, EverythingRegistry } from "@/common/everything_registry.
|
||||
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "@/common/constants.ts";
|
||||
import { block_value } from "@/common/utils.ts";
|
||||
import type { ModListing } from "@/common/mod_loader.ts";
|
||||
import { read_bmod } from "@/common/bmod.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import type { FluidInstance, Instances, RotatingInstance, Visual } from "@/common/mod_api/client.ts";
|
||||
import { block_visuals, instance_quads, InstanceGroup, pack_model, Visuals } from "@/client/rendering/visuals.ts";
|
||||
import { INSTANCE_FLOATS, INSTANCED_BUFFERS, terrain_shader_src, type Texture } from "@/client/renderer/mod.ts";
|
||||
@@ -492,11 +492,11 @@ Deno.test("client scripts register visuals during setup, for blocks that exist",
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_visuals_" });
|
||||
write_testmod(dir, script);
|
||||
const mod = load_and_check(dir)[0];
|
||||
const bmod = read_bmod(await pack_mod(mod), "testmod.bmod");
|
||||
const packed = read_mod(await pack_mod(mod), "testmod.cubi");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const listing: ModListing = { id: "testmod", name: "Test", version: "1.0.0", sha256: "", file: "", size: 0 };
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods([listing], [bmod]);
|
||||
await load_client_mods([listing], [packed]);
|
||||
};
|
||||
await load(`
|
||||
import type { ClientContext } from "cubi/client";
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import {
|
||||
} from "@/common/mod_data.ts";
|
||||
import { json_object } from "@/common/schema.ts";
|
||||
import { check_references, load_order, type LoadedMod, type ModReport } from "@/common/mod_check.ts";
|
||||
import { png_size, texture_size_problem } from "@/common/bmod.ts";
|
||||
import { png_size, texture_size_problem } from "@/common/mod.ts";
|
||||
import { type TextureJson, validate_texture_json } from "@/common/texture_animation.ts";
|
||||
import { type LootTableJson, validate_loot_table } from "@/common/loot.ts";
|
||||
import { validate_biome } from "@/common/worldgen/biomes.ts";
|
||||
@@ -125,7 +125,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
error(`manifest.json: scripts.${side} ${path} doesn't exist`);
|
||||
}
|
||||
}
|
||||
// cubi/engine needs engine_access, it's checked again on the bundled code when a .bmod loads
|
||||
// cubi/engine needs engine_access, it's checked again on the bundled code when a .cubi loads
|
||||
if (mod.manifest?.engine_access !== true) {
|
||||
const folders = new Set(Object.values(scripts).filter((p) => typeof p === "string").map((p) => dirname(p)));
|
||||
for (const folder of folders) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// converted from the same mod find their textures. a .png.mcmeta becomes the .json next to the png: bworld reads the
|
||||
// same animation format
|
||||
import { join } from "@std/path";
|
||||
import { png_size, texture_size_problem } from "@/common/bmod.ts";
|
||||
import { png_size, texture_size_problem } from "@/common/mod.ts";
|
||||
import { type TextureJson, validate_texture_json } from "@/common/texture_animation.ts";
|
||||
import {
|
||||
DEFAULT_REMAPS,
|
||||
@@ -104,7 +104,7 @@ export function import_textures(input: string, options: ImportOptions = {}): Imp
|
||||
for (const warning of result.warnings) report.warnings.push({ location, warning });
|
||||
json = result.json;
|
||||
}
|
||||
// the limits a .bmod checks, like a title screen's 512×512 panorama being too big
|
||||
// the limits a .cubi checks, like a title screen's 512×512 panorama being too big
|
||||
const too_big = texture_size_problem(size, json);
|
||||
if (too_big) {
|
||||
report.skipped.push({ location, reason: `it ${too_big}` });
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// deno task pack-mod mods/copper_tools [copper_tools.bmod]
|
||||
// builds a mod folder into a .bmod: its data merged into data.json, each script bundled into one module, and its
|
||||
// deno task pack-mod mods/copper_tools [copper_tools.cubi]
|
||||
// builds a mod folder into a .cubi: its data merged into data.json, each script bundled into one module, and its
|
||||
// textures and credits. deno task build does this for every mod in mods/, see docs/modding/gettingstarted/modfiles.md
|
||||
import { basename, dirname, resolve } from "@std/path";
|
||||
import { type Bmod, BMOD_EXTENSION, SCRIPT_SIDES, type ScriptSide, write_bmod } from "@/common/bmod.ts";
|
||||
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 { mod_data } from "@/common/mod_check.ts";
|
||||
@@ -18,10 +18,10 @@ const PLATFORMS: Record<ScriptSide, "deno" | "browser"> = {
|
||||
shared: "browser",
|
||||
};
|
||||
|
||||
// a mod that passed check-mods, as .bmod bytes
|
||||
// a mod that passed check-mods, as .cubi bytes
|
||||
export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>> {
|
||||
const manifest = mod.manifest as unknown as ManifestJson;
|
||||
const scripts: Bmod["scripts"] = {};
|
||||
const scripts: Mod["scripts"] = {};
|
||||
for (const side of SCRIPT_SIDES) {
|
||||
const entry = manifest.scripts?.[side];
|
||||
if (entry) scripts[side] = await bundle_script(mod.dir, `${mod.dir}/${entry}`, PLATFORMS[side]);
|
||||
@@ -33,7 +33,7 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
|
||||
}
|
||||
const texture_json = new Map([...mod.texture_json].sort(([a], [b]) => a.localeCompare(b)));
|
||||
|
||||
return write_bmod({
|
||||
return write_mod({
|
||||
manifest,
|
||||
data: mod_data(mod),
|
||||
scripts,
|
||||
@@ -75,7 +75,7 @@ async function bundle_script(mod_dir: string, entry: string, platform: "deno" |
|
||||
if (import.meta.main) {
|
||||
const [dir, out] = Deno.args;
|
||||
if (!dir) {
|
||||
console.error("usage: deno task pack-mod <mod folder> [output.bmod]");
|
||||
console.error("usage: deno task pack-mod <mod folder> [output.cubi]");
|
||||
Deno.exit(1);
|
||||
}
|
||||
// its siblings are checked too, so references to mods it depends on can be checked
|
||||
@@ -90,7 +90,7 @@ if (import.meta.main) {
|
||||
for (const error of mod.report.errors) console.error(` ${error}`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
const file = out ?? `${basename(folder)}${BMOD_EXTENSION}`;
|
||||
const file = out ?? `${basename(folder)}${MOD_EXTENSION}`;
|
||||
const bytes = await pack_mod(mod);
|
||||
Deno.writeFileSync(file, bytes);
|
||||
console.log(`Packed ${mod.id} into ${file} (${(bytes.length / 1024).toFixed(1)} KB)`);
|
||||
|
||||
Reference in New Issue
Block a user