detect INVEdit inv files as chest schematics

This commit is contained in:
David Vierra 2010-09-18 01:54:59 -10:00
parent 97650fc6ad
commit e254ceaae6

View File

@ -655,10 +655,15 @@ class MCLevel:
print "Detected Schematic." print "Detected Schematic."
return MCSchematic(root_tag=root_tag, filename=filename) return MCSchematic(root_tag=root_tag, filename=filename)
if(root_tag.name == '' and loadInfinite): if(root_tag.name == ''):
print "Detected Infdev level.dat" if ("Inventory" in root_tag):
print "Detected INVEdit inventory file"
return INVEditChest(root_tag=root_tag, filename=filename);
return MCInfdevOldLevel(root_tag=root_tag, filename=filename); if ("Data" in root_tag and loadInfinite):
print "Detected Infdev level.dat"
return MCInfdevOldLevel(root_tag=root_tag, filename=filename);
raise IOError, "Cannot detect file type." raise IOError, "Cannot detect file type."
@ -1084,6 +1089,54 @@ class MCSchematic (MCLevel):
assert isinstance(entityTag, TAG_Compound) assert isinstance(entityTag, TAG_Compound)
self.TileEntities.append(entityTag); self.TileEntities.append(entityTag);
class INVEditChest(MCSchematic):
Width = 1
Height = 1
Length = 1
Blocks = array([[[materials.materialNamed("Chest")]]], 'uint8');
Data = array([[[0]]], 'uint8');
Entities = TAG_List();
def __init__(self, root_tag, filename):
if filename:
self.filename = filename
if None is root_tag:
try:
root_tag = nbt.load(filename)
except IOError,e:
print "Failed to load file ", e
else:
assert root_tag, "Must have either root_tag or filename"
self.filename = None
for item in list(root_tag["Inventory"]):
slot = item["Slot"].value
if slot < 9 or slot > 36:
root_tag["Inventory"].remove(item)
else:
item["Slot"].value -= 9 # adjust for different chest slot indexes
self.root_tag = root_tag;
@decompress_first
def getTileEntities(self):
chestTag = TAG_Compound();
chestTag["id"] = TAG_String("Chest")
chestTag["Items"] = self.root_tag["Inventory"]
chestTag["x"] = TAG_Int(0);
chestTag["y"] = TAG_Int(0);
chestTag["z"] = TAG_Int(0);
return TAG_List([chestTag], name="TileEntities")
TileEntities = property(getTileEntities);
class ChunkNotPresent(Exception): pass class ChunkNotPresent(Exception): pass
class ChunkMalformed(ChunkNotPresent): pass class ChunkMalformed(ChunkNotPresent): pass
@ -2838,8 +2891,16 @@ def testSchematics():
pass pass
schematic.copyBlocksFrom(level, BoundingBox((0,0,0), (64,64,64,)), (0,0,0) ) schematic.copyBlocksFrom(level, BoundingBox((0,0,0), (64,64,64,)), (0,0,0) )
def testINVEditChests():
invFile = MCLevel.fromFile("unnamed.inv");
print "Blocks: ", invFile.Blocks
print "Data: ", invFile.Data
print "Entities: ", invFile.Entities
print "TileEntities: ", invFile.TileEntities
#raise SystemExit;
def testmain(): def testmain():
testINVEditChests();
testSchematics(); testSchematics();
testIndevLevels(); testIndevLevels();
testAlphaLevels(); testAlphaLevels();