Rename bmod to just mod

This commit is contained in:
2026-11-04 22:07:45 -03:00
parent fe0d857021
commit 5baaf0239a
33 changed files with 253 additions and 253 deletions
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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]));
});