Skip blocks that don't exist on schematics
This commit is contained in:
@@ -73,7 +73,7 @@ export async function start_game(
|
||||
for (const mod of mods) {
|
||||
for (const schematic of mod.data.schematics ?? []) {
|
||||
try {
|
||||
game.schematics.set(schematic.id!, prepare_schematic(game, schematic));
|
||||
game.schematics.set(schematic.id!, prepare_schematic(game, schematic.id!, schematic));
|
||||
} catch (e) {
|
||||
throw new ModLoadError(mod.listing.id, `schematic ${schematic.id}: ${(e as Error).message}`);
|
||||
}
|
||||
|
||||
@@ -1064,7 +1064,7 @@ export class ModRuntime {
|
||||
register: (id, schematic) => {
|
||||
register.new_id("schematic", id, game().schematics.has(id));
|
||||
try {
|
||||
game().schematics.set(id, prepare_schematic(game(), schematic));
|
||||
game().schematics.set(id, prepare_schematic(game(), id, schematic));
|
||||
} catch (e) {
|
||||
register.fail(`schematic ${id}: ${(e as Error).message}`);
|
||||
}
|
||||
|
||||
@@ -109,8 +109,9 @@ export interface RegisteredSchematic {
|
||||
palette: { id: string; value: number }[];
|
||||
}
|
||||
|
||||
// a copy of the schematic, checked once so placing it can't fail halfway. throws saying what's wrong with it
|
||||
export function prepare_schematic(game: GameServer, json: Schematic): RegisteredSchematic {
|
||||
// a copy of the schematic, checked once so placing it can't fail halfway. blocks that aren't registered are left out,
|
||||
// with a warning. throws saying what's wrong with it
|
||||
export function prepare_schematic(game: GameServer, id: string, json: Schematic): RegisteredSchematic {
|
||||
const problems = schematic_problems(json);
|
||||
if (problems.length > 0) throw new Error(problems.slice(0, 5).join(", "));
|
||||
const schematic = structuredClone(json);
|
||||
@@ -118,10 +119,15 @@ export function prepare_schematic(game: GameServer, json: Schematic): Registered
|
||||
if (volume > MAX_SCHEMATIC_VOLUME) {
|
||||
throw new Error(`a schematic holds up to ${MAX_SCHEMATIC_VOLUME} blocks, and this one is ${volume}`);
|
||||
}
|
||||
const palette = schematic.palette.map(({ id, s }) => {
|
||||
// palette entries whose block isn't registered
|
||||
const missing = new Set<number>();
|
||||
const palette = schematic.palette.map(({ id, s }, i) => {
|
||||
if (id === AIR_ID) return { id, value: AIR };
|
||||
const info = EverythingRegistry.get<BlockRegistry>("blocks", id);
|
||||
if (!info) throw new Error(`it has ${id}, which isn't a block`);
|
||||
if (!info) {
|
||||
missing.add(i);
|
||||
return { id, value: AIR };
|
||||
}
|
||||
return { id, value: value_with_states(game.world.block_ids[id], info, s ?? {}) };
|
||||
});
|
||||
for (const { i, p } of schematic.blocks) {
|
||||
@@ -135,6 +141,11 @@ export function prepare_schematic(game: GameServer, json: Schematic): Registered
|
||||
for (const { id } of schematic.entities) {
|
||||
if (!has_entity_type(id)) throw new Error(`it has ${id}, which isn't an entity`);
|
||||
}
|
||||
if (missing.size > 0) {
|
||||
schematic.blocks = schematic.blocks.filter(({ i }) => !missing.has(i));
|
||||
const ids = [...missing].map((i) => palette[i].id).join(", ");
|
||||
console.warn(`Schematic ${id} has blocks that don't exist, leaving them out: ${ids}`);
|
||||
}
|
||||
return { schematic, palette };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user