Refactor: Change chunk.save() into chunk.getSavedData(). Remove world._saveChunk.
World.saveInPlace now checks chunk.dirty before saving the chunk.
This commit is contained in:
parent
75ae4a35e6
commit
124e3389cd
@ -11,6 +11,7 @@ from math import floor
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import zlib
|
import zlib
|
||||||
@ -135,7 +136,6 @@ class AnvilChunk(LightedChunk):
|
|||||||
self.root_tag = chunkTag
|
self.root_tag = chunkTag
|
||||||
|
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
self.save()
|
|
||||||
|
|
||||||
def _load(self, root_tag):
|
def _load(self, root_tag):
|
||||||
self.root_tag = root_tag
|
self.root_tag = root_tag
|
||||||
@ -153,37 +153,37 @@ class AnvilChunk(LightedChunk):
|
|||||||
|
|
||||||
arr[..., y:y + 16] = secarray.swapaxes(0, 2)
|
arr[..., y:y + 16] = secarray.swapaxes(0, 2)
|
||||||
|
|
||||||
def save(self):
|
def savedTagData(self):
|
||||||
""" does not recalculate any data or light """
|
""" does not recalculate any data or light """
|
||||||
|
|
||||||
if self.dirty:
|
debug(u"Saving chunk: {0}".format(self))
|
||||||
debug(u"Saving chunk: {0}".format(self))
|
self.sanitizeBlocks()
|
||||||
self.sanitizeBlocks()
|
|
||||||
|
|
||||||
sections = nbt.TAG_List()
|
sections = nbt.TAG_List()
|
||||||
for y in range(0, self.Height, 16):
|
for y in range(0, self.Height, 16):
|
||||||
sec = nbt.TAG_Compound()
|
sec = nbt.TAG_Compound()
|
||||||
for name in "Blocks", "Data", "SkyLight", "BlockLight":
|
for name in "Blocks", "Data", "SkyLight", "BlockLight":
|
||||||
|
|
||||||
arr = getattr(self, name)
|
arr = getattr(self, name)
|
||||||
secarray = arr[..., y:y + 16].swapaxes(0, 2)
|
secarray = arr[..., y:y + 16].swapaxes(0, 2)
|
||||||
if name == "Blocks":
|
if name == "Blocks":
|
||||||
if not secarray.any():
|
if not secarray.any():
|
||||||
break # detect empty sections here
|
break # detect empty sections here
|
||||||
else:
|
else:
|
||||||
secarray = packNibbleArray(secarray)
|
secarray = packNibbleArray(secarray)
|
||||||
|
|
||||||
sec[name] = nbt.TAG_Byte_Array(array(secarray))
|
sec[name] = nbt.TAG_Byte_Array(array(secarray))
|
||||||
|
|
||||||
if len(sec):
|
if len(sec):
|
||||||
sec["Y"] = nbt.TAG_Byte(y / 16)
|
sec["Y"] = nbt.TAG_Byte(y / 16)
|
||||||
sections.append(sec)
|
sections.append(sec)
|
||||||
|
|
||||||
|
self.root_tag["Level"]["Sections"] = sections
|
||||||
|
data = self.root_tag.save(compressed=False)
|
||||||
|
del self.root_tag["Level"]["Sections"]
|
||||||
|
debug(u"Saved chunk {0}".format(self))
|
||||||
|
return data
|
||||||
|
|
||||||
self.root_tag["Level"]["Sections"] = sections
|
|
||||||
self.world._saveChunk(self)
|
|
||||||
self.dirty = False
|
|
||||||
del self.root_tag["Level"]["Sections"]
|
|
||||||
debug(u"Saved chunk {0}".format(self))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def materials(self):
|
def materials(self):
|
||||||
@ -1266,9 +1266,13 @@ class MCInfdevOldLevel(ChunkedLevelMixin, EntityLevel):
|
|||||||
dirtyChunkCount = 0
|
dirtyChunkCount = 0
|
||||||
if self._loadedChunks:
|
if self._loadedChunks:
|
||||||
for chunk in self._loadedChunks.itervalues():
|
for chunk in self._loadedChunks.itervalues():
|
||||||
|
cx, cz = chunk.chunkPosition
|
||||||
if chunk.dirty:
|
if chunk.dirty:
|
||||||
|
data = chunk.savedTagData()
|
||||||
dirtyChunkCount += 1
|
dirtyChunkCount += 1
|
||||||
chunk.save()
|
self.worldFolder.saveChunk(cx, cz, data)
|
||||||
|
chunk.dirty = False
|
||||||
|
|
||||||
|
|
||||||
for path, tag in self.playerTagCache.iteritems():
|
for path, tag in self.playerTagCache.iteritems():
|
||||||
tag.save(path)
|
tag.save(path)
|
||||||
@ -1424,10 +1428,6 @@ class MCInfdevOldLevel(ChunkedLevelMixin, EntityLevel):
|
|||||||
def getChunkData(self, cx, cz):
|
def getChunkData(self, cx, cz):
|
||||||
return self.worldFolder.readChunk(cx, cz)
|
return self.worldFolder.readChunk(cx, cz)
|
||||||
|
|
||||||
def _saveChunk(self, chunk):
|
|
||||||
cx, cz = chunk.chunkPosition
|
|
||||||
self.worldFolder.saveChunk(cx, cz, chunk.root_tag.save(compressed=False))
|
|
||||||
|
|
||||||
def dirhash(self, n):
|
def dirhash(self, n):
|
||||||
return self.dirhashes[n % 64]
|
return self.dirhashes[n % 64]
|
||||||
|
|
||||||
|
1
mce.py
1
mce.py
@ -873,7 +873,6 @@ class mce(object):
|
|||||||
if entitiesRemoved:
|
if entitiesRemoved:
|
||||||
chunk.chunkChanged(False)
|
chunk.chunkChanged(False)
|
||||||
|
|
||||||
chunk.save()
|
|
||||||
|
|
||||||
if len(removedEntities) == 0:
|
if len(removedEntities) == 0:
|
||||||
print "No entities to remove."
|
print "No entities to remove."
|
||||||
|
@ -388,7 +388,6 @@ class MCServerChunkGenerator(object):
|
|||||||
chunk.root_tag = tempChunk.root_tag
|
chunk.root_tag = tempChunk.root_tag
|
||||||
chunk.dirty = True
|
chunk.dirty = True
|
||||||
|
|
||||||
chunk.save()
|
|
||||||
|
|
||||||
|
|
||||||
def generateChunkInLevel(self, level, cx, cz):
|
def generateChunkInLevel(self, level, cx, cz):
|
||||||
|
Reference in New Issue
Block a user