Entity and block sounds !
This commit is contained in:
@@ -4,11 +4,13 @@
|
||||
// checks between mods: dependencies, load order, and ids one mod uses from another. pure, so the build, check-mods
|
||||
// and the server (on .cubi files) all use it
|
||||
import {
|
||||
BLOCK_SOUNDS,
|
||||
type BlockJson,
|
||||
choice_list,
|
||||
type ClipJson,
|
||||
type EffectJson,
|
||||
entity_category,
|
||||
ENTITY_SOUNDS,
|
||||
type EntityJson,
|
||||
type EntityModelJson,
|
||||
type FluidJson,
|
||||
@@ -193,6 +195,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
const add = (map: Map<string, string[]>, id: string, mod: string) => map.set(id, [...(map.get(id) ?? []), mod]);
|
||||
|
||||
const textures = new Set<string>(engine_textures);
|
||||
const sounds = new Set<string>();
|
||||
// terrain data by kind, then id
|
||||
const worldgen_owners: Record<string, Map<string, string[]>> = {
|
||||
noise: new Map(),
|
||||
@@ -248,6 +251,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
tag_owners.get(json.registry)!.add(json.id);
|
||||
}
|
||||
for (const texture of mod.textures) textures.add(texture);
|
||||
for (const { json } of mod.sounds ?? []) sounds.add(json.id);
|
||||
}
|
||||
|
||||
const mod_ids = new Set(mods.map((mod) => mod.id));
|
||||
@@ -295,6 +299,16 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
}
|
||||
};
|
||||
|
||||
// a block's or entity's "sounds" with none of what it can have, which is a typo
|
||||
const uses_sounds = (file: string, prefix: string, kinds: readonly string[]) => {
|
||||
check_namespace(file, prefix);
|
||||
if (!kinds.some((kind) => sounds.has(`${prefix}/${kind}`))) {
|
||||
errors.push(
|
||||
`${file}: sounds ${prefix} has none of ${kinds.map((kind) => `${prefix}/${kind}`).join(", ")}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
for (const { file, json } of mod.blocks) {
|
||||
if ((block_owners.get(json.id)?.length ?? 0) > 1) {
|
||||
errors.push(`${file}: block ${json.id} is also defined by ${block_owners.get(json.id)!.join(", ")}`);
|
||||
@@ -309,6 +323,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
if (json.item_model) uses(file, json.item_model, "model");
|
||||
if (json.drops) uses(file, json.drops, "item");
|
||||
if (json.loot_table) uses(file, json.loot_table, "loot table");
|
||||
if (json.sounds) uses_sounds(file, json.sounds, BLOCK_SOUNDS);
|
||||
if (json.waterloggable) {
|
||||
uses(file, json.waterloggable, "block");
|
||||
if (block_owners.has(json.waterloggable) && !fluid_blocks.has(json.waterloggable)) {
|
||||
@@ -391,6 +406,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
if (json.model !== undefined) uses(file, json.model, "entity model");
|
||||
uses(file, json.texture, "texture");
|
||||
if (json.loot_table) uses(file, json.loot_table, "loot table");
|
||||
if (json.sounds) uses_sounds(file, json.sounds, ENTITY_SOUNDS);
|
||||
// scripts register behaviors, the server checks them when it starts
|
||||
if (json.behavior?.includes(":")) check_namespace(file, json.behavior);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user