Ejemplo n.º 1
0
    def read(self, file_object):
        self.empty = False
        self.block_count = Short.read(file_object)
        self.bpb = UnsignedByte.read(file_object)
        if self.bpb <= 4:
            self.bpb = 4

        if self.bpb <= 8: # Indirect palette
            self.palette = []
            size = VarInt.read(file_object)
            for i in range(size):
                self.palette.append(VarInt.read(file_object))
        else: # Direct palette
            self.palette = None

        size = VarInt.read(file_object)
        longs = []
        for i in range(size):
            longs.append(UnsignedLong.read(file_object))

        self.blocks = []
        mask = (1 << self.bpb)-1
        for i in range(4096):
            l1 = int((i*self.bpb)/64)
            offset = (i*self.bpb)%64
            l2 = int(((i+1)*self.bpb-1)/64)
            n = longs[l1] >> offset
            if l2>l1:
                n |= longs[l2] << (64-offset)
            n &= mask
            if self.palette:
                n = self.palette[n]
            self.blocks.append(n)
Ejemplo n.º 2
0
    def read(self, file_object):
        self.entity_id = VarInt.read(file_object)
        if self._context.protocol_version >= 49:
            self.objectUUID = UUID.read(file_object)
        type_id = Byte.read(file_object)
        self.type = SpawnObjectPacket.EntityType.get_type_by_id(type_id)

        if self._context.protocol_version >= 100:
            self.x = Double.read(file_object)
            self.y = Double.read(file_object)
            self.z = Double.read(file_object)
        else:
            self.x = Integer.read(file_object)
            self.y = Integer.read(file_object)
            self.z = Integer.read(file_object)

        self.pitch = UnsignedByte.read(file_object)
        self.yaw = UnsignedByte.read(file_object)
        self.data = Integer.read(file_object)

        if self._context.protocol_version < 49:
            if self.data > 0:
                self.velocity_x = Short.read(file_object)
                self.velocity_y = Short.read(file_object)
                self.velocity_z = Short.read(file_object)
        else:
            self.velocity_x = Short.read(file_object)
            self.velocity_y = Short.read(file_object)
            self.velocity_z = Short.read(file_object)
Ejemplo n.º 3
0
    def read(self, file_object):
        self.entity_id = VarInt.read(file_object)
        if self.context.protocol_version >= 49:
            self.object_uuid = UUID.read(file_object)
        self.type_id = Byte.read(file_object)

        xyz_type = Double if self.context.protocol_version >= 100 else Integer
        for attr in 'x', 'y', 'z':
            setattr(self, attr, xyz_type.read(file_object))
        for attr in 'pitch', 'yaw':
            setattr(self, attr, UnsignedByte.read(file_object))

        self.data = Integer.read(file_object)
        if self.context.protocol_version >= 49 or self.data > 0:
            for attr in 'velocity_x', 'velocity_y', 'velocity_z':
                setattr(self, attr, Short.read(file_object))
Ejemplo n.º 4
0
    def read(self, file_object):
        self.entity_id = VarInt.read(file_object)
        if self.context.protocol_version >= 49:
            self.object_uuid = UUID.read(file_object)

        if self.context.protocol_version >= 458:
            self.type_id = VarInt.read(file_object)
        else:
            self.type_id = Byte.read(file_object)

        xyz_type = Double if self.context.protocol_version >= 100 else Integer
        for attr in 'x', 'y', 'z':
            setattr(self, attr, xyz_type.read(file_object))
        for attr in 'pitch', 'yaw':
            setattr(self, attr, UnsignedByte.read(file_object))

        self.data = Integer.read(file_object)
        if self.context.protocol_version >= 49 or self.data > 0:
            for attr in 'velocity_x', 'velocity_y', 'velocity_z':
                setattr(self, attr, Short.read(file_object))
Ejemplo n.º 5
0
    def read(self, file_object):
        self.entity_id = VarInt.read(file_object)
        if self.context.protocol_later_eq(49):
            self.object_uuid = UUID.read(file_object)

        if self.context.protocol_later_eq(458):
            self.type_id = VarInt.read(file_object)
        else:
            self.type_id = Byte.read(file_object)

        xyz_type = Double if self.context.protocol_later_eq(100) else Integer
        for attr in "x", "y", "z":
            setattr(self, attr, xyz_type.read(file_object))
        for attr in "pitch", "yaw":
            setattr(self, attr, Angle.read(file_object))

        self.data = Integer.read(file_object)
        if self.context.protocol_later_eq(49) or self.data > 0:
            for attr in "velocity_x", "velocity_y", "velocity_z":
                setattr(self, attr, Short.read(file_object))
Ejemplo n.º 6
0
 def read(self, file_object):
     self.window_id = UnsignedByte.read(file_object)
     self.count = Short.read(file_object)
     self.slots = [Slot(-1)]*self.count
     for slot_number in range(self.count):
         self.slots[slot_number] = Slot.read(file_object)