Move world generation outside the engine and into mods and data files
This commit is contained in:
+44
-3
@@ -30,6 +30,17 @@ import {
|
||||
import type { ModData } from "./mod_loader.ts";
|
||||
import { type LootTableJson, validate_loot_table } from "./loot.ts";
|
||||
import { type BiomeJson, validate_biome } from "./worldgen/biomes.ts";
|
||||
import {
|
||||
type BiomeSourceJson,
|
||||
type DensityFunctionJson,
|
||||
type NoiseJson,
|
||||
type NoiseSettingsJson,
|
||||
validate_biome_source,
|
||||
validate_density_function,
|
||||
validate_noise,
|
||||
validate_noise_settings,
|
||||
} from "./worldgen/data.ts";
|
||||
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";
|
||||
|
||||
@@ -166,10 +177,37 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
tags: checked(raw_data.tags, "tags", validate_tag, problems) as TagJson[],
|
||||
loot_tables: checked(raw_data.loot_tables, "loot_tables", validate_loot_table, problems) as LootTableJson[],
|
||||
biomes: checked(raw_data.biomes, "biomes", validate_biome, problems) as BiomeJson[],
|
||||
noises: checked(raw_data.noises, "noises", validate_noise, problems) as NoiseJson[],
|
||||
density_functions: checked(
|
||||
raw_data.density_functions,
|
||||
"density_functions",
|
||||
validate_density_function,
|
||||
problems,
|
||||
) as DensityFunctionJson[],
|
||||
noise_settings: checked(
|
||||
raw_data.noise_settings,
|
||||
"noise_settings",
|
||||
validate_noise_settings,
|
||||
problems,
|
||||
) as NoiseSettingsJson[],
|
||||
biome_sources: checked(
|
||||
raw_data.biome_sources,
|
||||
"biome_sources",
|
||||
validate_biome_source,
|
||||
problems,
|
||||
) as BiomeSourceJson[],
|
||||
features: checked(raw_data.features, "features", validate_feature, problems) as FeatureJson[],
|
||||
};
|
||||
// a mod only registers ids in its own namespace
|
||||
const registered = [...data.blocks, ...data.models, ...data.items, ...data.entities, ...data.entity_models];
|
||||
for (const { id } of [...registered, ...data.effects, ...data.loot_tables!, ...data.biomes!]) {
|
||||
const worldgen = [
|
||||
...data.noises!,
|
||||
...data.density_functions!,
|
||||
...data.noise_settings!,
|
||||
...data.biome_sources!,
|
||||
...data.features!,
|
||||
];
|
||||
for (const { id } of [...registered, ...data.effects, ...data.loot_tables!, ...data.biomes!, ...worldgen]) {
|
||||
if (typeof id === "string" && id.split(":")[0] !== mod) problems.push(`${id} isn't in this mod's namespace`);
|
||||
}
|
||||
|
||||
@@ -236,12 +274,15 @@ 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, what players get. the server sends them the world
|
||||
// the same mod without its server and worldgen scripts and the terrain's data, 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;
|
||||
return { ...bmod, scripts };
|
||||
const { noises: _n, density_functions: _d, noise_settings: _s, biome_sources: _b, features: _f, ...data } =
|
||||
bmod.data;
|
||||
return { ...bmod, scripts, data };
|
||||
}
|
||||
|
||||
function checked(list: unknown, name: string, validate: (json: unknown) => string[], problems: string[]): unknown[] {
|
||||
|
||||
Reference in New Issue
Block a user