added createChest command and supporting function chestWithItemID

This commit is contained in:
David Vierra 2010-10-21 18:47:01 -10:00
parent 3eed2fe689
commit 25ad51c8cb
2 changed files with 42 additions and 1 deletions

20
mce.py
View File

@ -24,6 +24,7 @@ class mce(object):
{commandPrefix}export <filename> <sourcePoint> <sourceSize>
{commandPrefix}import <filename> <destPoint> [noair] [nowater]
{commandPrefix}createChest <point> <item> [ <count> ]
{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 <point> <item> [ <count> ]
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

View File

@ -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