def __init__(self, path, create=False): """ :param path: string, path to file :return: None """ self.path = path if not os.path.exists(path): file(path, 'w').close() self.options = leveldb_mcpe.Options() self.writeOptions = leveldb_mcpe.WriteOptions() self.readOptions = leveldb_mcpe.ReadOptions() if create: self.options.create_if_missing = True # The database will be created once needed first. return needsRepair = False try: with self.world_db() as db: it = db.NewIterator(self.readOptions) it.SeekToFirst() if not db.Get(self.readOptions, it.key()) == it.value(): needsRepair = True it.status() del it except RuntimeError as err: logger.error("Error while opening world database from %s (%s)" % (path, err)) needsRepair = True if needsRepair: logger.info("Trying to repair world %s" % path) try: leveldb_mcpe.RepairWrapper(os.path.join(path, 'db')) except RuntimeError as err: logger.error("Error while repairing world %s %s" % (path, err))
from mclevelbase import ChunkNotPresent, ChunkMalformed import nbt import numpy import struct from infiniteworld import ChunkedLevelMixin, SessionLockLost, AnvilChunkData from level import LightedChunk from contextlib import contextmanager from pymclevel import entity, BoundingBox, Entity, TileEntity logger = logging.getLogger(__name__) leveldb_available = True leveldb_mcpe = None try: import leveldb_mcpe leveldb_mcpe.Options() except Exception as e: leveldb_available = False logger.info( "Error while trying to import leveldb_mcpe, starting without PE support ({0})" .format(e)) leveldb_mcpe = None def loadNBTCompoundList(data, littleEndian=True): """ Loads a list of NBT Compound tags from a bunch of data. Uses sep to determine where the next Compound tag starts. :param data: str, the NBT to load from :param littleEndian: bool. Determines endianness :return: list of TAG_Compounds