Skip to content
Browse files

dumpchests now observes items with differing damage values

  • Loading branch information...
1 parent 216bd58 commit 9ca56ea5967813a99758bc78e64511f1682e0e7f @codewarrior0 codewarrior0 committed
Showing with 27 additions and 10 deletions.
  1. +12 −3 items.py
  2. +15 −7 mce.py
View
15 items.py
@@ -291,7 +291,7 @@ def __init__(self, filename = None):
if line[0] == "#": continue;
if line[0] == "~": continue; #groups
stacksize = 64
- damagevalue = 0
+ damagevalue = None
maxdamage = 0
fields = line.split();
@@ -310,15 +310,24 @@ def __init__(self, filename = None):
name = name.replace("_", " ");
imagecoords = imagecoords.split(",");
- self.itemtypes[id] = ItemType(id, name, imagefile, imagecoords, maxdamage, damagevalue, stacksize)
+ self.itemtypes[(id, damagevalue)] = ItemType(id, name, imagefile, imagecoords, maxdamage, damagevalue, stacksize)
except Exception, e:
print "Error reading line:", e
print "Line: ", line
print
self.names = dict((item.name, item.id) for item in self.itemtypes.itervalues())
-
+ def findItem(self, id=0, damage=None):
+ item = self.itemtypes.get((id, damage))
+ if item: return item
+
+ item = self.itemtypes.get((id, None))
+ if item: return item
+
+ raise ItemNotFound, "Item {0}:{1} not found".format(id, damage)
+
+class ItemNotFound(KeyError): pass
items = Items();
View
22 mce.py
@@ -690,13 +690,21 @@ def _dumpchests(self, command):
chestCount += 1;
outFile.write(str(map(lambda x:tileEntity[x].value, "xyz")) + "\n");
- for Item in tileEntity["Items"]:
- 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));
-
+ itemsTag = tileEntity["Items"]
+ if len(itemsTag):
+ for itemTag in itemsTag:
+ try:
+ id = itemTag["id"].value
+ damage = itemTag["Damage"].value
+ item = items.findItem(id, damage)
+ itemname=item.name
+ except KeyError:
+ itemname="Unknown Item {0}".format(itemTag)
+ except Exception, e:
+ itemname = repr(e)
+ outFile.write("{0} {1}\n".format(itemTag["Count"].value,itemname));
+ else:
+ outFile.write("Empty Chest\n")
if i % 100 == 0:
print "Chunk {0}...".format(i)

0 comments on commit 9ca56ea

Please sign in to comment.
Something went wrong with that request. Please try again.