fix not having a seed crashing the server on startup
This commit is contained in:
parent
d3ebe1518d
commit
9231ce85d6
1 changed files with 7 additions and 1 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue