From 1633ba1dad1b8a2eda4a02c63ec66b5da162ecaf Mon Sep 17 00:00:00 2001 From: Jean-Yves Faye Date: Sun, 27 Feb 2011 16:29:20 +0100 Subject: [PATCH 1/3] Added dumpchests command which dump all chests in the world with their contents --- mce.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/mce.py b/mce.py index 5e4ecf6..0628c32 100755 --- a/mce.py +++ b/mce.py @@ -42,6 +42,7 @@ class mce(object): Entity commands: {commandPrefix}removeEntities [ ] {commandPrefix}dumpSigns [ ] + {commandPrefix}dumpChests [ ] Chunk commands: {commandPrefix}createChunks @@ -98,6 +99,7 @@ class mce(object): "removeentities", "dumpsigns", + "dumpchests", "createchunks", "deletechunks", @@ -607,7 +609,63 @@ class mce(object): print "Dumped {0} signs to {1}".format(signCount, filename); outFile.close(); + + def _dumpchests(self, command): + """ + dumpChests [ ] + + Saves the content and location of every chest in the world to a text file. + With no filename, saves signs to .chests + + Output is newline-delimited. 5 lines per sign. Coordinates are + on the first line, followed by a line by item slot For example: + + [229, 118, -15] + 64 Cobblestone + 32 Glass + Empty + [...] + Empty + Coordinates are ordered the same as point inputs: + [North/South, Down/Up, East/West] + + """ + if len(command): + filename = command[0] + else: + filename = self.level.displayName + ".chests" + + outFile = file(filename, "w"); + + print "Dumping chests..." + chestCount = 0; + + for i, cPos in enumerate(self.level.allChunks): + try: + chunk = self.level.getChunk(*cPos); + except mclevel.ChunkMalformed: + continue; + + for tileEntity in chunk.TileEntities: + if tileEntity["id"].value == "Chest": + chestCount += 1; + + outFile.write(str(map(lambda x:tileEntity[x].value, "xyz")) + "\n"); +# for i in range(26): +# outFile.write(tileEntity["Text{0}".format(i+1)].value + "\n"); + for Item in tileEntity["Items"]: + outFile.write(str(Item["Count"].value) + " " + str(Item["id"].value) + "\n"); + + if i % 100 == 0: + print "Chunk {0}...".format(i) + + chunk.unload(); + + print "Dumped {0} signs to {1}".format(chestCount, filename); + + outFile.close(); + def _removeentities(self, command): """ removeEntities [ [except] [ [ ... ] ] ] From 498eeb33a79b7e86137e43892e1c157b56c41a5c Mon Sep 17 00:00:00 2001 From: Jean-Yves Faye Date: Sun, 27 Feb 2011 16:52:30 +0100 Subject: [PATCH 2/3] Added item name instead of id and clean up --- mce.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/mce.py b/mce.py index 0628c32..f2cff08 100755 --- a/mce.py +++ b/mce.py @@ -618,19 +618,18 @@ class mce(object): With no filename, saves signs to .chests Output is newline-delimited. 5 lines per sign. Coordinates are - on the first line, followed by a line by item slot For example: + on the first line, followed by a line by inventory slot For example: - [229, 118, -15] - 64 Cobblestone - 32 Glass - Empty - [...] - Empty + [222, 51, 22] + 2 String + 3 String + 3 Iron bar Coordinates are ordered the same as point inputs: [North/South, Down/Up, East/West] """ + from items import items if len(command): filename = command[0] else: @@ -650,12 +649,10 @@ class mce(object): for tileEntity in chunk.TileEntities: if tileEntity["id"].value == "Chest": chestCount += 1; - + outFile.write(str(map(lambda x:tileEntity[x].value, "xyz")) + "\n"); -# for i in range(26): -# outFile.write(tileEntity["Text{0}".format(i+1)].value + "\n"); for Item in tileEntity["Items"]: - outFile.write(str(Item["Count"].value) + " " + str(Item["id"].value) + "\n"); + outFile.write(str(Item["Count"].value) + " " + items.itemtypes[Item["id"].value].name + "\n"); if i % 100 == 0: print "Chunk {0}...".format(i) From 1539fb59d7ccfbec0327babc5345ad164b142666 Mon Sep 17 00:00:00 2001 From: Jean-Yves Faye Date: Sun, 27 Feb 2011 19:39:09 +0100 Subject: [PATCH 3/3] Added exception for unknown items in id to name conversion --- mce.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mce.py b/mce.py index f2cff08..ecfb8a9 100755 --- a/mce.py +++ b/mce.py @@ -652,14 +652,19 @@ class mce(object): outFile.write(str(map(lambda x:tileEntity[x].value, "xyz")) + "\n"); for Item in tileEntity["Items"]: - outFile.write(str(Item["Count"].value) + " " + items.itemtypes[Item["id"].value].name + "\n"); + try: + itemname=items.itemtypes[Item["id"].value].name + except KeyError: + itemname="Unknown Item {0}".format(Item["id"].value) + outFile.write("{0} {1}\n".format(Item["Count"].value,itemname)); + if i % 100 == 0: print "Chunk {0}...".format(i) chunk.unload(); - print "Dumped {0} signs to {1}".format(chestCount, filename); + print "Dumped {0} chests to {1}".format(chestCount, filename); outFile.close();