示例#1
0
def item_type(item):
    """Wrapper to pymclevel Items.findItem() with corrected data"""
    global _ItemTypes
    if _ItemTypes is None:
        from pymclevel.items import items as ItemTypes

        for itemid, maxdamage in (
            (298, 56),  # Leather Cap
            (299, 81),  # Leather_Tunic
            (300, 76),  # Leather_Pants
            (301, 66),  # Leather_Boots
            (302, 166),  # Chainmail_Helmet
            (303, 241),  # Chainmail_Chestplate
            (304, 226),  # Chainmail_Leggings
            (305, 196),  # Chainmail_Boots
            (306, 166),  # Iron_Helmet
            (307, 241),  # Iron_Chestplate
            (308, 226),  # Iron_Leggings
            (309, 196),  # Iron_Boots
            (310, 364),  # Diamond_Helmet
            (311, 529),  # Diamond_Chestplate
            (312, 496),  # Diamond_Leggings
            (313, 430),  # Diamond_Boots
            (314, 78),  # Golden_Helmet
            (315, 87),  # Golden_Chestplate
            (316, 76),  # Golden_Leggings
            (317, 66),  # Golden_Boots
        ):
            ItemTypes.findItem(itemid).maxdamage = maxdamage - 1

        for itemid, stacksize in (
            (58, 64),  # Workbench (Crafting Table)
            (116, 64),  # Enchantment Table
            (281, 64),  # Bowl
            (282, 1),  # Mushroom Stew
            (324, 1),  # Wooden Door
            (337, 64),  # Clay (Ball)
            (344, 16),  # Egg
            (345, 64),  # Compass
            (347, 64),  # Clock
            (368, 16),  # Ender Pearl
            (379, 64),  # Brewing Stand
            (380, 64),  # Cauldron
            (395, 64),  # Empty Map
        ):
            ItemTypes.findItem(itemid).stacksize = stacksize
        for itemtype in ItemTypes.itemtypes.itervalues():
            if itemtype.maxdamage is not None:
                itemtype.stacksize = 1
        _ItemTypes = ItemTypes

    return _ItemTypes.findItem(item["id"].value, item["Damage"].value)
示例#2
0
    def __init__(self, nbt):
        super(Item, self).__init__(nbt, ("id", "Damage", "Count"))
        self.nbt = nbt  # avoid usage

        # Improve upon pymclevel item data
        if self._ItemTypes is None:
            from pymclevel.items import items as ItemTypes

            # Correct damage values for specific items
            for itemid, maxdamage in (
                (298, 56),  # Leather Cap
                (299, 81),  # Leather_Tunic
                (300, 76),  # Leather_Pants
                (301, 66),  # Leather_Boots
                (302, 166),  # Chainmail_Helmet
                (303, 241),  # Chainmail_Chestplate
                (304, 226),  # Chainmail_Leggings
                (305, 196),  # Chainmail_Boots
                (306, 166),  # Iron_Helmet
                (307, 241),  # Iron_Chestplate
                (308, 226),  # Iron_Leggings
                (309, 196),  # Iron_Boots
                (310, 364),  # Diamond_Helmet
                (311, 529),  # Diamond_Chestplate
                (312, 496),  # Diamond_Leggings
                (313, 430),  # Diamond_Boots
                (314, 78),  # Golden_Helmet
                (315, 87),  # Golden_Chestplate
                (316, 76),  # Golden_Leggings
                (317, 66),  # Golden_Boots
            ):
                ItemTypes.findItem(itemid).maxdamage = maxdamage - 1

            # Correct stack size for specific items
            for itemid, stacksize in (
                (58, 64),  # Workbench (Crafting Table)
                (116, 64),  # Enchantment Table
                (281, 64),  # Bowl
                (282, 1),  # Mushroom Stew
                (324, 1),  # Wooden Door
                (337, 64),  # Clay (Ball)
                (344, 16),  # Egg
                (345, 64),  # Compass
                (347, 64),  # Clock
                (368, 16),  # Ender Pearl
                (379, 64),  # Brewing Stand
                (380, 64),  # Cauldron
                (395, 64),  # Empty Map
            ):
                ItemTypes.findItem(itemid).stacksize = stacksize

            # Set stack size for items with durability
            for itemtype in ItemTypes.itemtypes.itervalues():
                if itemtype.maxdamage is not None:
                    itemtype.stacksize = 1

            # Save the corrected data to class attribute
            self._ItemTypes = ItemTypes

        # These should be properties,
        # but for simplicity and performance they're set here
        self.key = (self.id, self.damage)
        self.type = self._ItemTypes.findItem(*self.key)
        self.name = self._name()
        self.description = self._description()
        self.is_armor = self.id in self.armor_ids
示例#3
0
    def _dumpchests(self, command):
        """
    dumpChests [ <filename> ]

    Saves the content and location of every chest in the world to a text file.
    With no filename, saves signs to <worldname>.chests

    Output is delimited by brackets and newlines. A set of coordinates in
    brackets begins a chest, followed by a line for each inventory slot.
    For example:

        [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 pymclevel.items import items

        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 mclevelbase.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")
                    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}:{2}\n".format(itemTag["Count"].value, itemname, itemTag["Damage"].value))
                    else:
                        outFile.write("Empty Chest\n")

            if i % 100 == 0:
                print "Chunk {0}...".format(i)
示例#4
0
    def _dumpchests(self, command):
        """
    dumpChests [ <filename> ]

    Saves the content and location of every chest in the world to a text file.
    With no filename, saves signs to <worldname>.chests

    Output is delimited by brackets and newlines. A set of coordinates in
    brackets begins a chest, followed by a line for each inventory slot.
    For example:

        [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 pymclevel.items import items

        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 mclevelbase.ChunkMalformed:
                continue

            for tileEntity in chunk.TileEntities:
                if tileEntity["id"].value == "Chest":
                    chestCount += 1

                    outFile.write(
                        str([tileEntity[x].value for x in "xyz"]) + "\n")
                    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 as e:
                                itemname = repr(e)
                            outFile.write("{0} {1}:{2}\n".format(
                                itemTag["Count"].value, itemname,
                                itemTag["Damage"].value))
                    else:
                        outFile.write("Empty Chest\n")

            if i % 100 == 0:
                print("Chunk {0}...".format(i))

        print("Dumped {0} chests to {1}".format(chestCount, filename))

        outFile.close()