diff --git a/mce.py b/mce.py index c6eade6..6562f67 100755 --- a/mce.py +++ b/mce.py @@ -24,6 +24,7 @@ class mce(object): {commandPrefix}export {commandPrefix}import [noair] [nowater] + {commandPrefix}createChest [ ] {commandPrefix}analyze Player commands: @@ -82,6 +83,8 @@ class mce(object): "export", "import", + "createchest", + "player", "spawn", @@ -340,6 +343,23 @@ class mce(object): self.needsSave = True; print "Replaced {0} blocks.".format("all" if box is None else box.volume) + def _createchest(self, command): + """ + createChest [ ] + + Create a chest filled with the specified item. + Stacks are 64 if count is not given. + """ + point = self.readPoint(command) + itemID = self.readInt(command) + count = 64; + if len(command): + count = self.readInt(command) + + chest = mclevel.MCSchematic.chestWithItemID(itemID, count); + self.level.copyBlocksFrom(chest, chest.getWorldBounds(), point); + self.needsSave = True; + def _analyze(self, command): """ analyze diff --git a/mclevel.py b/mclevel.py index 841152b..9916f7c 100644 --- a/mclevel.py +++ b/mclevel.py @@ -1225,6 +1225,26 @@ class MCSchematic (MCLevel): assert isinstance(entityTag, TAG_Compound) self.TileEntities.append(entityTag); + @classmethod + def chestWithItemID(self, itemID, count=64, damage=0): + """ Creates a chest with a stack of 'itemID' in each slot. + Optionally specify the count of items in each stack. Pass a negative + value for damage to create unnaturally sturdy tools. """ + root_tag = TAG_Compound(); + invTag = TAG_List(); + root_tag["Inventory"] = invTag + for slot in range(9, 36): + itemTag = TAG_Compound(); + itemTag["Slot"] = TAG_Byte(slot) + itemTag["Count"] = TAG_Byte(count) + itemTag["id"] = TAG_Short(itemID) + itemTag["Damage"] = TAG_Short(damage) + invTag.append(itemTag); + + chest = INVEditChest(root_tag, ""); + + return chest; + class INVEditChest(MCSchematic): Width = 1 Height = 1 @@ -1233,6 +1253,7 @@ class INVEditChest(MCSchematic): Data = array([[[0]]], 'uint8'); Entities = TAG_List(); + def __init__(self, root_tag, filename): if filename: @@ -1249,7 +1270,7 @@ class INVEditChest(MCSchematic): for item in list(root_tag["Inventory"]): slot = item["Slot"].value - if slot < 9 or slot > 36: + if slot < 9 or slot >= 36: root_tag["Inventory"].remove(item) else: item["Slot"].value -= 9 # adjust for different chest slot indexes