World gen stuff
This commit is contained in:
+29
-1
@@ -13,7 +13,10 @@ import { mod_data } from "@/common/mod_check.ts";
|
||||
import type { ServerModSource } from "@/server/game/load_mods.ts";
|
||||
import { GameServer } from "@/server/game/game_server.ts";
|
||||
import { start_game } from "@/server/game/load_mods.ts";
|
||||
import { apply_config } from "@/server/load_mods.ts";
|
||||
import { apply_config, load_mods } from "@/server/load_mods.ts";
|
||||
import { load_client_mods } from "@/client/mods.ts";
|
||||
import { read_mod } from "@/common/mod.ts";
|
||||
import { pack_mod } from "@/tools/pack_mod.ts";
|
||||
import { AIR_ID, PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
import { decode_level_chunk } from "@/common/chunk_streaming.ts";
|
||||
import { CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
@@ -274,6 +277,31 @@ export function stone_floor(game: GameServer, radius = 3) {
|
||||
}
|
||||
}
|
||||
|
||||
// what the base game's terrain is made of underground, for ores in tests to replace
|
||||
export const GROUND_BLOCKS = "#bworld:raw_rocks";
|
||||
|
||||
// the cubi: textures mods can use without a build
|
||||
export const ENGINE_TEXTURES = ["cubi:missing", ...Array.from({ length: 9 }, (_, i) => `cubi:break_${i}`)];
|
||||
|
||||
// registers a folder of mod sources the way a player gets them: packed, loaded by a server, which adds the blocks
|
||||
// content scripts register, and the copies it serves loaded on the client
|
||||
export async function load_as_player(sources: string) {
|
||||
const folder = Deno.makeTempDirSync({ prefix: "bworld_player_mods_" });
|
||||
try {
|
||||
for (const mod of await load_and_check(sources)) {
|
||||
Deno.writeFileSync(`${folder}/${mod.id}.cubi`, await pack_mod(mod));
|
||||
}
|
||||
const mods = await load_mods(folder, ENGINE_TEXTURES);
|
||||
EverythingRegistry.clear();
|
||||
await load_client_mods(
|
||||
mods.map((mod) => mod.listing),
|
||||
mods.map((mod) => read_mod(mod.client_bytes, mod.listing.file)),
|
||||
);
|
||||
} finally {
|
||||
Deno.removeSync(folder, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
export function copy_dir(from: string, to: string) {
|
||||
if (Deno.statSync(from).isDirectory) {
|
||||
Deno.mkdirSync(to, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user