Beispiel #1
0
 def _saveTileEntities(self, db):
   data = nbt.DataWriter()
   for subchunk in self.subchunks:
     if subchunk is None:
       continue
     for x in range(16):
       for y in range(16):
         for z in range(16):
           block = subchunk.getBlock(x, y, z)
           if block.nbt is not None: # Add back the correct position.
             block.nbt.add(nbt.TAG_Int("x", subchunk.x * 16 + x))
             block.nbt.add(nbt.TAG_Int("y", subchunk.y * 16 + y))
             block.nbt.add(nbt.TAG_Int("z", subchunk.z * 16 + z))
             nbt.encode(block.nbt, data)
   ldb.put(db, self.keyBase + b"1", data.get())
Beispiel #2
0
def pack(data_type, data):
    if data_type in data_types:
        format = data_types[data_type]
        return pack_real(format[0], data)

    if data_type == "string8":
        return pack("short", len(data)) + data
    if data_type == "string16":
        return pack("short", len(data)) + data.encode("utf-16be")
    if data_type == "slot":
        o = pack("short", data["id"])
        if data["id"] > 0:
            o += pack("byte", data["amount"])
            o += pack("short", data["damage"])
            if data["id"] in enchantable:
                if "enchantment_data" in data:

                    o += pack("short", len(data["enchantment_data"]))
                    o += data["enchantment_data"]

                elif "enchantments" in data:
                    ench = nbt.encode(data["enchantments"])
                    ench = nbt.compress(ench)
                    o += pack("short", len(ench))
                    o += ench
                else:
                    o += pack("short", -1)

        return o
    if data_type == "metadata":
        o = ""
        for key, tmp in data:
            ty, val = tmp
            x = key | (ty << 5)
            o += pack("ubyte", x)

            if ty == 0:
                o += pack("byte", val)
            if ty == 1:
                o += pack("short", val)
            if ty == 2:
                o += pack("int", val)
            if ty == 3:
                o += pack("float", val)
            if ty == 4:
                o += pack("string16", val)
            if ty == 5:
                o += pack("short", val["id"])
                o += pack("byte", val["count"])
                o += pack("short", val["damage"])
            if ty == 6:
                for i in range(3):
                    o += pack("int", val[i])
        o += pack("byte", 127)
        return o
Beispiel #3
0
  def save(self, db, force=False):
    if self.dirty or force:
      data = struct.pack("<BB", self.version, len(self.blocks))
      for i in range(len(self.blocks)):
        palette, blockIDs = self._savePalette(i)
        data += self._saveBlocks(len(palette), blockIDs)
        data += struct.pack("<I", len(palette))
        for block in palette:
          data += nbt.encode(block)

      key = struct.pack("<iicB", self.x, self.z, b'/', self.y)
      ldb.put(db, key, data)
Beispiel #4
0
def pack(data_type, data):
    if data_type in data_types:
        format = data_types[data_type]
        return pack_real(format[0], data)
    
    if data_type == "string8": return pack("short", len(data)) + data
    if data_type == "string16": return pack("short", len(data)) + data.encode('utf-16be')
    if data_type == "slot":
        o = pack('short', data['id'])
        if data['id'] > 0:
            o += pack('byte',  data['amount'])
            o += pack('short', data['damage'])
            if data['id'] in enchantable:
                if 'enchantment_data' in data:

                    o += pack('short', len(data['enchantment_data']))
                    o += data['enchantment_data']

                elif 'enchantments' in data:
                    ench = nbt.encode(data['enchantments'])
                    ench = nbt.compress(ench)
                    o += pack('short', len(ench))
                    o += ench
                else:
                    o += pack('short', -1)
                
        return o
    if data_type == "metadata":
        o = ''
        for key, tmp in data:
            ty, val = tmp
            x = key | (ty << 5)
            o += pack('ubyte', x)

            if ty == 0: o += pack('byte', val) 
            if ty == 1: o += pack('short', val) 
            if ty == 2: o += pack('int', val) 
            if ty == 3: o += pack('float', val) 
            if ty == 4: o += pack('string16', val)
            if ty == 5:
                o += pack('short', val['id'])
                o += pack('byte',  val['count'])
                o += pack('short', val['damage'])
            if ty == 6:
                for i in range(3):
                    o += pack('int', val[i])
        o += pack('byte', 127)
        return o
Beispiel #5
0
 def _saveEntities(self, db):
   data = nbt.DataWriter()
   for entity in self.entities:
     nbt.encode(entity, data)
   ldb.put(db, self.keyBase + b"2", data.get())