From 20ab0da66cf88650c5dbf4dbe7abca94935eda8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20=C5=A0m=C4=93di=C5=86=C5=A1?= Date: Wed, 19 Dec 2018 20:56:24 +0200 Subject: [PATCH] tempWorldForLevel(): Fix passing seed to temporary world. --- src/mceditlib/minecraft_server.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/mceditlib/minecraft_server.py b/src/mceditlib/minecraft_server.py index cdc3a176..37870cec 100644 --- a/src/mceditlib/minecraft_server.py +++ b/src/mceditlib/minecraft_server.py @@ -28,6 +28,7 @@ import urllib from mceditlib import worldeditor +from mceditlib.anvil.adapter import AnvilWorldAdapter from mceditlib.exceptions import ChunkNotPresent from mceditlib.directories import appSupportDir from mceditlib.util import exhaust @@ -317,11 +318,12 @@ def createReadme(self): def tempWorldForLevel(self, level): # tempDir = tempfile.mkdtemp("mclevel_servergen") - tempDir = os.path.join(self.worldCacheDir, self.jarStorage.checksumForVersion(self.serverVersion), str(level.RandomSeed)) + seed = level.getWorldMetadata().RandomSeed + tempDir = os.path.join(self.worldCacheDir, self.jarStorage.checksumForVersion(self.serverVersion), str(seed)) propsFile = os.path.join(tempDir, "server.properties") properties = readProperties(propsFile) - tempWorld = self.tempWorldCache.get((self.serverVersion, level.RandomSeed)) + tempWorld = self.tempWorldCache.get((self.serverVersion, seed)) if tempWorld is None: if not os.path.exists(tempDir): @@ -332,12 +334,14 @@ def tempWorldForLevel(self, level): worldName = properties.setdefault("level-name", worldName) tempWorldDir = os.path.join(tempDir, worldName) - tempWorld = worldeditor.WorldEditor(tempWorldDir, create=not os.path.exists(tempWorldDir), random_seed=level.RandomSeed) + tempWorld = worldeditor.WorldEditor(tempWorldDir, create=not os.path.exists(tempWorldDir), adapterClass=AnvilWorldAdapter) + tempWorld.getWorldMetadata().RandomSeed = seed + tempWorld.adapter.syncToDisk() # Write updated seed to level.dat tempWorld.close() tempWorldRO = worldeditor.WorldEditor(tempWorldDir, readonly=True) - self.tempWorldCache[self.serverVersion, level.RandomSeed] = tempWorldRO + self.tempWorldCache[self.serverVersion, seed] = tempWorldRO if level.dimNo == 0: properties["allow-nether"] = "false"