fix not having a seed crashing the server on startup

This commit is contained in:
Holly Stubbs 2023-12-05 20:07:32 +00:00
parent d3ebe1518d
commit 9231ce85d6
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E

View file

@ -22,11 +22,17 @@ import { PacketTimeUpdate } from "./packets/TimeUpdate";
import { HillyGenerator } from "./generators/Hilly"; import { HillyGenerator } from "./generators/Hilly";
import { NetherGenerator } from "./generators/Nether"; import { NetherGenerator } from "./generators/Nether";
import { PacketWindowItems } from "./packets/WindowItems"; import { PacketWindowItems } from "./packets/WindowItems";
import { getRandomValues } from "crypto";
const chunkFrom = -15; const chunkFrom = -15;
const chunkTo = 15; const chunkTo = 15;
const chunkCount = Math.abs(chunkFrom * 2) * (chunkTo * 2); const chunkCount = Math.abs(chunkFrom * 2) * (chunkTo * 2);
function getRandomSeed() {
const arr = new Uint32Array(1);
return getRandomValues(arr)[0];
}
export class MinecraftServer { export class MinecraftServer {
private static readonly PROTOCOL_VERSION = 14; private static readonly PROTOCOL_VERSION = 14;
private static readonly TICK_RATE = 20; private static readonly TICK_RATE = 20;
@ -108,7 +114,7 @@ export class MinecraftServer {
this.clients = new FunkyArray<string, MPClient>(); this.clients = new FunkyArray<string, MPClient>();
// Convert seed if needed // Convert seed if needed
let worldSeed = typeof(this.config.seed) === "string" ? this.hashCode(this.config.seed) : this.config.seed; let worldSeed = typeof(this.config.seed) === "string" ? this.hashCode(this.config.seed) : typeof(this.config.seed) === "number" ? this.config.seed : getRandomSeed();
// Init save manager and load seed from it if possible // Init save manager and load seed from it if possible
this.saveManager = new WorldSaveManager(this.config, [0, -1], worldSeed); this.saveManager = new WorldSaveManager(this.config, [0, -1], worldSeed);