Loading schematics
This commit is contained in:
+6
-2
@@ -50,6 +50,7 @@ import {
|
||||
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";
|
||||
import { type Schematic, validate_schematic } from "./schematic.ts";
|
||||
|
||||
export const MOD_EXTENSION = ".cubi";
|
||||
|
||||
@@ -81,7 +82,7 @@ export class ModError extends Error {
|
||||
// the zip's layout:
|
||||
// manifest.json the mod's manifest, with "main" and "credits" pointing into the zip
|
||||
// data.json every block, model, item, recipe, ore, entity, entity model, effect, fluid, tag, loot
|
||||
// table and biome, and the mod's config
|
||||
// table, biome and schematic, and the mod's config
|
||||
// script.js
|
||||
// textures/<name>.png the texture <mod id>:<name>
|
||||
// textures/<name>.json its animation, if it has one
|
||||
@@ -214,6 +215,7 @@ export function read_mod(bytes: Uint8Array, file: string): Mod {
|
||||
) as BiomeSourceJson[],
|
||||
dimensions: checked(raw_data.dimensions, "dimensions", validate_dimension, problems) as DimensionJson[],
|
||||
features: checked(raw_data.features, "features", validate_feature, problems) as FeatureJson[],
|
||||
schematics: checked(raw_data.schematics, "schematics", validate_schematic, problems) as Schematic[],
|
||||
config: raw_data.config,
|
||||
};
|
||||
if (raw_data.config !== undefined && !is_object(raw_data.config)) {
|
||||
@@ -236,6 +238,7 @@ export function read_mod(bytes: Uint8Array, file: string): Mod {
|
||||
...data.biome_sources!,
|
||||
...data.dimensions!,
|
||||
...data.features!,
|
||||
...data.schematics!,
|
||||
];
|
||||
for (const { id } of [...registered, ...data.loot_tables!, ...data.biomes!, ...worldgen]) {
|
||||
if (typeof id === "string" && id.split(":")[0] !== mod) problems.push(`${id} isn't in this mod's namespace`);
|
||||
@@ -299,7 +302,7 @@ export function read_mod(bytes: Uint8Array, file: string): Mod {
|
||||
return { manifest, data, script, textures, texture_json, credits };
|
||||
}
|
||||
|
||||
// the same mod without the terrain's data and its config, what players get. the server sends them the world. its
|
||||
// the same mod without the terrain's data, its schematics and its config, what players get. the server sends them the world. its
|
||||
// script goes with it whole, and players only run its shared and client phases
|
||||
export function client_copy(mod: Mod): Mod {
|
||||
const {
|
||||
@@ -309,6 +312,7 @@ export function client_copy(mod: Mod): Mod {
|
||||
biome_sources: _b,
|
||||
dimensions: _dim,
|
||||
features: _f,
|
||||
schematics: _sc,
|
||||
config: _c,
|
||||
...data
|
||||
} = mod.data;
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
import { feature_refs, type FeatureJson } from "./worldgen/features.ts";
|
||||
import { cell_height_problem } from "./world_shape.ts";
|
||||
import type { ModData } from "./mod_loader.ts";
|
||||
import type { Schematic } from "./schematic.ts";
|
||||
|
||||
export interface ModReport {
|
||||
id: string;
|
||||
@@ -74,6 +75,8 @@ export interface LoadedMod {
|
||||
biome_sources: { file: string; json: BiomeSourceJson }[];
|
||||
dimensions: { file: string; json: DimensionJson }[];
|
||||
features: { file: string; json: FeatureJson }[];
|
||||
// schematics/<name>.cbsm, decoded and with their ids
|
||||
schematics: { file: string; json: Schematic }[];
|
||||
// config.json's settings, see docs/modding/misc/config.md
|
||||
config?: Record<string, unknown>;
|
||||
textures: string[];
|
||||
@@ -105,6 +108,7 @@ export function mod_data(mod: LoadedMod): ModData {
|
||||
biome_sources: mod.biome_sources.map((b) => b.json),
|
||||
dimensions: mod.dimensions.map((d) => d.json),
|
||||
features: mod.features.map((f) => f.json),
|
||||
schematics: mod.schematics.map((s) => s.json),
|
||||
config: mod.config,
|
||||
};
|
||||
}
|
||||
@@ -503,6 +507,16 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
}
|
||||
if (json.texture !== undefined) uses(file, json.texture, "texture");
|
||||
}
|
||||
// cubi: entities, like dropped items, are the engine's
|
||||
for (const { file, json } of mod.schematics) {
|
||||
for (const { id } of json.palette) uses(file, id, "block");
|
||||
for (const { id } of json.entities) {
|
||||
check_namespace(file, id);
|
||||
if (!id.startsWith("cubi:") && !entity_owners.has(id)) {
|
||||
errors.push(`${file}: entity ${id} doesn't exist`);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const { file, json } of mod.spawns) {
|
||||
check_namespace(file, json.entity);
|
||||
const entity = entity_jsons.get(json.entity);
|
||||
|
||||
@@ -45,6 +45,7 @@ import type { FeatureJson } from "./worldgen/features.ts";
|
||||
import { register_block_item } from "./utils.ts";
|
||||
import { find_model, type ModelFileJson, type ModelJson, resolve_models } from "./block_models.ts";
|
||||
import { loading_mod } from "./hooks.ts";
|
||||
import type { Schematic } from "./schematic.ts";
|
||||
|
||||
// everything a mod's json files hold, merged into one file by the build (build/mods/<id>/<hash>/data.json)
|
||||
export interface ModData {
|
||||
@@ -77,6 +78,8 @@ export interface ModData {
|
||||
dimensions?: DimensionJson[];
|
||||
// data features, see common/worldgen/features.ts. server only too
|
||||
features?: FeatureJson[];
|
||||
// its schematics/<name>.cbsm files, with their ids, see common/schematic.ts. server only too
|
||||
schematics?: Schematic[];
|
||||
// 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>;
|
||||
|
||||
@@ -84,3 +84,8 @@ const schematic_schema = z.object({
|
||||
export function schematic_problems(json: unknown): Problems {
|
||||
return find_problems(schematic_schema, json);
|
||||
}
|
||||
|
||||
// the same for one in a mod's data.json, which has its id: <mod id>:<file name>
|
||||
export function validate_schematic(json: unknown): Problems {
|
||||
return find_problems(schematic_schema.extend({ id }), json);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user