Revert "Support dimensions with arbitrary directory names."

This reverts commit 90460f89db7ff340c6ebb166c555fd77d302c366.
This commit is contained in:
David Vierra 2012-11-07 22:41:31 -10:00
parent e904341eb7
commit 89648d77a2
3 changed files with 21 additions and 36 deletions

View File

@ -1247,32 +1247,21 @@ class MCInfdevOldLevel(ChunkedLevelMixin, EntityLevel):
for dirname in worldDirs: for dirname in worldDirs:
if dirname.startswith("DIM"): if dirname.startswith("DIM"):
try: try:
intInDirname = re.findall("\\d+", dirname) dimNo = int(dirname[3:])
if len(intInDirname) > 0:
dimNo = int(intInDirname[-1])
else:
dimNo = 999 # identical dimNo should not matter
log.info("Found dimension {0}".format(dirname)) log.info("Found dimension {0}".format(dirname))
dim = MCAlphaDimension(self, dimNo, dirname) dim = MCAlphaDimension(self, dimNo)
self.dimensions[dirname] = dim self.dimensions[dimNo] = dim
except Exception, e: except Exception, e:
log.error(u"Error loading dimension {0}: {1}".format(dirname, e)) log.error(u"Error loading dimension {0}: {1}".format(dirname, e))
def getDimension(self, dimNo, dirname=None): def getDimension(self, dimNo):
if dirname is None:
dirname = "DIM" + str(int(dimNo))
if self.dimNo != 0: if self.dimNo != 0:
return self.parentWorld.getDimension(dimNo, dirname) return self.parentWorld.getDimension(dimNo)
if dimNo == 0: if dimNo in self.dimensions:
return self return self.dimensions[dimNo]
dim = MCAlphaDimension(self, dimNo, create=True)
if dirname in self.dimensions: self.dimensions[dimNo] = dim
return self.dimensions[dirname]
dim = MCAlphaDimension(self, dimNo, dirname, create=True)
self.dimensions[dirname] = dim
return dim return dim
# --- Region I/O --- # --- Region I/O ---
@ -1696,22 +1685,22 @@ class MCInfdevOldLevel(ChunkedLevelMixin, EntityLevel):
class MCAlphaDimension (MCInfdevOldLevel): class MCAlphaDimension (MCInfdevOldLevel):
def __init__(self, parentWorld, dimNo, dirname, create=False): def __init__(self, parentWorld, dimNo, create=False):
filename = parentWorld.worldFolder.getFolderPath(dirname) filename = parentWorld.worldFolder.getFolderPath("DIM" + str(int(dimNo)))
self.parentWorld = parentWorld self.parentWorld = parentWorld
MCInfdevOldLevel.__init__(self, filename, create) MCInfdevOldLevel.__init__(self, filename, create)
self.dimNo = dimNo self.dimNo = dimNo
self.filename = parentWorld.filename self.filename = parentWorld.filename
self.players = parentWorld.players self.players = parentWorld.players
self.playerTagCache = parentWorld.playerTagCache self.playerTagCache = parentWorld.playerTagCache
self.dirname = dirname
@property @property
def root_tag(self): def root_tag(self):
return self.parentWorld.root_tag return self.parentWorld.root_tag
def __str__(self): def __str__(self):
return "MCAlphaDimension({0}, {1} ({2}))".format(self.parentWorld, self.dirname, self.dimNo) return "MCAlphaDimension({0}, {1})".format(self.parentWorld, self.dimNo)
def loadLevelDat(self, create=False, random_seed=None, last_played=None): def loadLevelDat(self, create=False, random_seed=None, last_played=None):
pass pass
@ -1727,7 +1716,7 @@ class MCAlphaDimension (MCInfdevOldLevel):
@property @property
def displayName(self): def displayName(self):
return u"{0} ({1})".format(self.parentWorld.displayName, return u"{0} ({1})".format(self.parentWorld.displayName,
self.dimensionNames.get(self.dimNo, "%s (%d)" % (self.dirname, self.dimNo))) self.dimensionNames.get(self.dimNo, "Dimension %d" % self.dimNo))
def saveInPlace(self, saveSelf=False): def saveInPlace(self, saveSelf=False):
"""saving the dimension will save the parent world, which will save any """saving the dimension will save the parent world, which will save any

View File

@ -139,7 +139,6 @@ class MCLevel(object):
dimNo = 0 dimNo = 0
parentWorld = None parentWorld = None
world = None world = None
directory = None
@classmethod @classmethod
def isLevel(cls, filename): def isLevel(cls, filename):

17
mce.py
View File

@ -1285,12 +1285,13 @@ class mce(object):
dimension [ <dim> ] dimension [ <dim> ]
Load another dimension, a sub-world of this level. Without options, lists Load another dimension, a sub-world of this level. Without options, lists
all of the dimensions found in this world. <dim> can be a number, a all of the dimensions found in this world. <dim> can be a number or one of
directory or one of these keywords: these keywords:
nether, hell, slip: DIM-1 nether, hell, slip: DIM-1
earth, overworld, parent: parent world earth, overworld, parent: parent world
end: DIM1 end: DIM1
""" """
if len(command): if len(command):
if command[0].lower() in ("earth", "overworld", "parent"): if command[0].lower() in ("earth", "overworld", "parent"):
if self.level.parentWorld: if self.level.parentWorld:
@ -1305,14 +1306,10 @@ class mce(object):
elif command[0].lower() == "end": elif command[0].lower() == "end":
dimNo = 1 dimNo = 1
else: else:
dirname = None dimNo = self.readInt(command)
dimNo = None
try:
dimNo = int(command[0])
except ValueError:
dirname = command[0]
self.level = self.level.getDimension(dimNo, dirname) if dimNo in self.level.dimensions:
self.level = self.level.dimensions[dimNo]
return return
if self.level.parentWorld: if self.level.parentWorld:
@ -1320,7 +1317,7 @@ class mce(object):
if len(self.level.dimensions): if len(self.level.dimensions):
print u"Dimensions in {0}:".format(self.level.displayName) print u"Dimensions in {0}:".format(self.level.displayName)
for k in self.level.dimensions.values(): for k in self.level.dimensions:
print "{0}: {1}".format(k, infiniteworld.MCAlphaDimension.dimensionNames.get(k, "Unknown")) print "{0}: {1}".format(k, infiniteworld.MCAlphaDimension.dimensionNames.get(k, "Unknown"))
def _help(self, command): def _help(self, command):