From cba29b2e9a711a668a92ce8f3457e81fea9b8565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 17 Mar 2014 16:57:32 +0100 Subject: [PATCH] make computer state save system more compatible with non-standard use of save/load --- src/main/scala/li/cil/oc/common/SaveHandler.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/scala/li/cil/oc/common/SaveHandler.scala b/src/main/scala/li/cil/oc/common/SaveHandler.scala index cfda336a9..b0e36feae 100644 --- a/src/main/scala/li/cil/oc/common/SaveHandler.scala +++ b/src/main/scala/li/cil/oc/common/SaveHandler.scala @@ -24,6 +24,19 @@ object SaveHandler { def load(dimension: Int, chunk: ChunkCoordIntPair, name: String): Array[Byte] = { if (chunk == null) throw new IllegalArgumentException("chunk is null") + // Use data from 'cache' if possible. This avoids weird things happening + // when writeToNBT+readFromNBT is called by other mods (i.e. this is not + // used to actually save the data to disk). + saveData.get(dimension) match { + case Some(chunks) => chunks.get(chunk) match { + case Some(map) => map.get(name) match { + case Some(data) => return data + case _ => + } + case _ => + } + case _ => + } val path = savePath val dimPath = new io.File(path, dimension.toString) val chunkPath = new io.File(dimPath, s"${chunk.chunkXPos}.${chunk.chunkZPos}")