From 9231ce85d6be88e760aac45e0241b510b080c4c2 Mon Sep 17 00:00:00 2001 From: Holly Date: Tue, 5 Dec 2023 20:07:32 +0000 Subject: [PATCH] fix not having a seed crashing the server on startup --- server/MinecraftServer.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/MinecraftServer.ts b/server/MinecraftServer.ts index 72f520d..1b1e84c 100644 --- a/server/MinecraftServer.ts +++ b/server/MinecraftServer.ts @@ -22,11 +22,17 @@ import { PacketTimeUpdate } from "./packets/TimeUpdate"; import { HillyGenerator } from "./generators/Hilly"; import { NetherGenerator } from "./generators/Nether"; import { PacketWindowItems } from "./packets/WindowItems"; +import { getRandomValues } from "crypto"; const chunkFrom = -15; const chunkTo = 15; const chunkCount = Math.abs(chunkFrom * 2) * (chunkTo * 2); +function getRandomSeed() { + const arr = new Uint32Array(1); + return getRandomValues(arr)[0]; +} + export class MinecraftServer { private static readonly PROTOCOL_VERSION = 14; private static readonly TICK_RATE = 20; @@ -108,7 +114,7 @@ export class MinecraftServer { this.clients = new FunkyArray(); // 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 this.saveManager = new WorldSaveManager(this.config, [0, -1], worldSeed);