Mod config
This commit is contained in:
+17
-5
@@ -12,6 +12,7 @@ import {
|
||||
type EntityJson,
|
||||
type EntityModelJson,
|
||||
ID_PATTERN,
|
||||
is_object,
|
||||
type ItemJson,
|
||||
type ManifestJson,
|
||||
type OreJson,
|
||||
@@ -80,7 +81,7 @@ export class BmodError extends Error {
|
||||
// the zip's layout:
|
||||
// manifest.json the mod's manifest, with "scripts" and "credits" pointing into the zip
|
||||
// data.json every block, model, item, recipe, ore, entity, entity model, effect, tag, loot table and
|
||||
// biome
|
||||
// biome, and the mod's config
|
||||
// scripts/<side>.js
|
||||
// textures/<name>.png the texture <mod id>:<name>
|
||||
// textures/<name>.json its animation, if it has one
|
||||
@@ -200,7 +201,11 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
problems,
|
||||
) as BiomeSourceJson[],
|
||||
features: checked(raw_data.features, "features", validate_feature, problems) as FeatureJson[],
|
||||
config: raw_data.config,
|
||||
};
|
||||
if (raw_data.config !== undefined && !is_object(raw_data.config)) {
|
||||
problems.push("data.json: config must be an object");
|
||||
}
|
||||
// a mod only registers ids in its own namespace
|
||||
const registered = [...data.blocks, ...data.models, ...data.items, ...data.entities, ...data.entity_models];
|
||||
const worldgen = [
|
||||
@@ -277,14 +282,21 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
return { manifest, data, scripts, textures, texture_json, credits };
|
||||
}
|
||||
|
||||
// the same mod without its server and worldgen scripts and the terrain's data, what players get. the server sends
|
||||
// them the world
|
||||
// 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 };
|
||||
delete scripts.server;
|
||||
delete scripts.worldgen;
|
||||
const { noises: _n, density_functions: _d, noise_settings: _s, biome_sources: _b, features: _f, ...data } =
|
||||
bmod.data;
|
||||
const {
|
||||
noises: _n,
|
||||
density_functions: _d,
|
||||
noise_settings: _s,
|
||||
biome_sources: _b,
|
||||
features: _f,
|
||||
config: _c,
|
||||
...data
|
||||
} = bmod.data;
|
||||
return { ...bmod, scripts, data };
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@ export type { EventSignal, Face, Id, ItemStack, ModInfo, Position, Season, TagAp
|
||||
|
||||
export interface ServerContext {
|
||||
mod: ModInfo;
|
||||
// the mod's settings: its config.json's "config", with the server's changes from config/<mod id>.json. the same
|
||||
// for the whole time the server runs. see docs/modding/misc/config.md
|
||||
// deno-lint-ignore no-explicit-any
|
||||
readonly config: any;
|
||||
components: ComponentRegistry; // only during setup
|
||||
commands: CommandRegistry; // only during setup
|
||||
events: { before: ServerBeforeEvents; after: ServerAfterEvents };
|
||||
|
||||
@@ -67,6 +67,8 @@ export interface LoadedMod {
|
||||
noise_settings: { file: string; json: NoiseSettingsJson }[];
|
||||
biome_sources: { file: string; json: BiomeSourceJson }[];
|
||||
features: { file: string; json: FeatureJson }[];
|
||||
// config.json's settings, see docs/modding/misc/config.md
|
||||
config?: Record<string, unknown>;
|
||||
textures: string[];
|
||||
// absolute paths by texture id
|
||||
texture_files: Map<string, string>;
|
||||
@@ -94,6 +96,7 @@ export function mod_data(mod: LoadedMod): ModData {
|
||||
noise_settings: mod.noise_settings.map((n) => n.json),
|
||||
biome_sources: mod.biome_sources.map((b) => b.json),
|
||||
features: mod.features.map((f) => f.json),
|
||||
config: mod.config,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,9 @@ export interface ModData {
|
||||
biome_sources?: BiomeSourceJson[];
|
||||
// data features, see common/worldgen/features.ts. server only too
|
||||
features?: FeatureJson[];
|
||||
// the mod's settings, its config.json's "config", with the server's changes once the server loads it. server only
|
||||
// too, see docs/modding/misc/config.md
|
||||
config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
// a mod as the server lists it to clients, in load order: the .bmod players download, without its server script
|
||||
|
||||
Reference in New Issue
Block a user