Implement main game as a mod
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { AIR, CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, ID_MASK } from "$/common/constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { generate_raw_chunk, RawChunk } from "$/common/generation.ts";
|
||||
import { generate_raw_chunk, RawChunk, WorldgenSetup } from "$/common/generation.ts";
|
||||
import { Container } from "$/common/inventory.ts";
|
||||
import { AIR_ID, BlockChange } from "$/common/protocol.ts";
|
||||
import { chunk_key } from "$/common/utils.ts";
|
||||
@@ -18,6 +18,8 @@ export interface Tile {
|
||||
z: number;
|
||||
data: Record<string, unknown>;
|
||||
containers: Record<string, Container>;
|
||||
// a mod block's data, what BlockRef.data holds
|
||||
mod_data?: unknown;
|
||||
}
|
||||
|
||||
export function position_key(x: number, y: number, z: number) {
|
||||
@@ -28,6 +30,7 @@ export function position_key(x: number, y: number, z: number) {
|
||||
export class ServerWorld {
|
||||
readonly seed: string;
|
||||
readonly block_ids: Record<string, number> = {};
|
||||
readonly worldgen: WorldgenSetup | undefined;
|
||||
|
||||
// what generation made, and the final blocks with neighbors' leaves and player changes applied
|
||||
#raw = new LruMap<number, RawChunk>(RAW_CACHE_SIZE);
|
||||
@@ -42,8 +45,9 @@ export class ServerWorld {
|
||||
|
||||
on_block_change?: (x: number, y: number, z: number, id: string) => void;
|
||||
|
||||
constructor(seed: string) {
|
||||
constructor(seed: string, worldgen?: WorldgenSetup) {
|
||||
this.seed = seed;
|
||||
this.worldgen = worldgen;
|
||||
EverythingRegistry.get_registry<BlockRegistry>("blocks").forEach((block, nid) => {
|
||||
this.block_ids[block.id] = nid;
|
||||
});
|
||||
@@ -131,7 +135,7 @@ export class ServerWorld {
|
||||
const key = chunk_key(chunk_x, chunk_z);
|
||||
let raw = this.#raw.get(key);
|
||||
if (!raw) {
|
||||
raw = generate_raw_chunk(chunk_x, chunk_z, this.seed, this.block_ids);
|
||||
raw = generate_raw_chunk(chunk_x, chunk_z, this.seed, this.block_ids, this.worldgen);
|
||||
this.#raw.set(key, raw);
|
||||
}
|
||||
return raw;
|
||||
|
||||
Reference in New Issue
Block a user