Пример #1
0
 def sign_book(self, author, title):
     """Sign current book in hand"""
     book = self._setup_book()
     if book is None:
         return False
     book.nbt["author"] = nbt.TagString(author)
     book.nbt["title"] = nbt.TagString(title)
     # TODO: don't use hard coded id
     book.item_id = 387  # written book
     self.channels.send("MC|BSign", self._pack_book(book))
Пример #2
0
 def encode_extra(packet):
     bbuff = BoundBuffer()
     if packet.data['nbt'] is None:
         packet.data['nbt'] = nbt._TagEnd()
     nbt.TagByte(packet.data['nbt'].id)._render_buffer(bbuff)
     if packet.data['nbt'].id == nbt.TAG_COMPOUND:
         nbt.TagString(packet.data['nbt'].name)._render_buffer(bbuff)
         packet.data['nbt']._render_buffer(bbuff)
     return bbuff.flush()
Пример #3
0
 def decode_extra(packet, bbuff):
     tag_type = datautils.unpack(MC_BYTE, bbuff)
     if tag_type == nbt.TAG_COMPOUND:
         name = nbt.TagString(buffer=bbuff).value
         nbt_data = nbt.TagCompound(buffer=bbuff)
         nbt_data.name = name
         packet.data['nbt'] = nbt_data
     else:
         assert (tag_type == nbt.TAG_END)
         packet.data['nbt'] = None
     return packet
Пример #4
0
 def edit_book(self, pages):
     """Set the pages of current book in hand"""
     book = self._setup_book()
     if book is None:
         return False
     nbtpages = nbt.TagList(nbt.TagString)
     for i, page in enumerate(pages):
         if i >= constants.BOOK_MAXPAGES:
             break
         nbtpages.insert(i, nbt.TagString(page))
     book.nbt["pages"] = nbtpages
     self.channels.send("MC|BEdit", self._pack_book(book))
Пример #5
0
def pack_slot(slot):
    o = pack(MC_SHORT, slot['id'])
    if slot['id'] != -1:
        o += pack(MC_BYTE, slot['amount'])
        o += pack(MC_SHORT, slot['damage'])
        if 'enchants' in slot:
            ench = slot['enchants']
            bbuff = BoundBuffer()
            nbt.TagByte(ench.id)._render_buffer(bbuff)
            nbt.TagString(ench.name)._render_buffer(bbuff)
            ench._render_buffer(bbuff)
            o += bbuff.flush()
        else:
            o += pack(MC_BYTE, 0)
    return o
Пример #6
0
def unpack_slot(bbuff):
    slot = {}
    slot['id'] = unpack(MC_SHORT, bbuff)
    if slot['id'] != -1:
        slot['amount'] = unpack(MC_BYTE, bbuff)
        slot['damage'] = unpack(MC_SHORT, bbuff)
        nbt_start = unpack(MC_BYTE, bbuff)
        if nbt_start > 0:
            if nbt_start != nbt.TAG_COMPOUND:
                return None
            name = nbt.TagString(buffer=bbuff).value
            ench = nbt.TagCompound(buffer=bbuff)
            ench.name = name
            slot['enchants'] = ench
    return slot