Example #1
0
    def read(self, file_object):
        self.map_id = VarInt.read(file_object)
        self.scale = Byte.read(file_object)

        if self.context.protocol_version >= 107:
            self.is_tracking_position = Boolean.read(file_object)
        else:
            self.is_tracking_position = True

        icon_count = VarInt.read(file_object)
        self.icons = []
        for i in range(icon_count):
            type, direction = divmod(UnsignedByte.read(file_object), 16)
            x = Byte.read(file_object)
            z = Byte.read(file_object)
            icon = MapPacket.MapIcon(type, direction, (x, z))
            self.icons.append(icon)
        self.width = UnsignedByte.read(file_object)
        if self.width:
            self.height = UnsignedByte.read(file_object)
            x = Byte.read(file_object)
            z = Byte.read(file_object)
            self.offset = (x, z)
            self.pixels = VarIntPrefixedByteArray.read(file_object)
        else:
            self.height = 0
            self.offset = None
            self.pixels = None
Example #2
0
 def read(self, file_object):
     self.x = Float.read(file_object)
     self.y = Float.read(file_object)
     self.z = Float.read(file_object)
     self.radius = Float.read(file_object)
     records_count = Integer.read(file_object)
     self.records = []
     for i in range(records_count):
         rec_x = Byte.read(file_object)
         rec_y = Byte.read(file_object)
         rec_z = Byte.read(file_object)
         record = ExplosionPacket.Record(rec_x, rec_y, rec_z)
         self.records.append(record)
     self.player_motion_x = Float.read(file_object)
     self.player_motion_y = Float.read(file_object)
     self.player_motion_z = Float.read(file_object)
Example #3
0
 def read(self, file_object):
     self.x = Float.read(file_object)
     self.y = Float.read(file_object)
     self.z = Float.read(file_object)
     self.radius = Float.read(file_object)
     records_count = Integer.read(file_object)
     self.records = []
     for i in range(records_count):
         rec_x = Byte.read(file_object)
         rec_y = Byte.read(file_object)
         rec_z = Byte.read(file_object)
         record = ExplosionPacket.Record(rec_x, rec_y, rec_z)
         self.records.append(record)
     self.player_motion_x = Float.read(file_object)
     self.player_motion_y = Float.read(file_object)
     self.player_motion_z = Float.read(file_object)
Example #4
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)
Example #5
0
    def read(self, file_object):
        self.map_id = VarInt.read(file_object)
        self.scale = Byte.read(file_object)

        if self.context.protocol_in_range(107, PRE | 6):
            self.is_tracking_position = Boolean.read(file_object)
        elif self.context.protocol_earlier(107):
            self.is_tracking_position = True

        if self.context.protocol_later_eq(452):
            self.is_locked = Boolean.read(file_object)
        else:
            self.is_locked = False

        if self.context.protocol_later_eq(PRE | 6):
            self.is_tracking_position = Boolean.read(file_object)

        icon_count = VarInt.read(file_object)
        self.icons = []
        for i in range(icon_count):
            if self.context.protocol_later_eq(373):
                type = VarInt.read(file_object)
            else:
                type, direction = divmod(UnsignedByte.read(file_object), 16)
            x = Byte.read(file_object)
            z = Byte.read(file_object)
            if self.context.protocol_later_eq(373):
                direction = UnsignedByte.read(file_object)
            if self.context.protocol_later_eq(364):
                has_name = Boolean.read(file_object)
                display_name = String.read(file_object) if has_name else None
            else:
                display_name = None
            icon = MapPacket.MapIcon(type, direction, (x, z), display_name)
            self.icons.append(icon)

        self.width = UnsignedByte.read(file_object)
        if self.width:
            self.height = UnsignedByte.read(file_object)
            x = Byte.read(file_object)
            z = Byte.read(file_object)
            self.offset = (x, z)
            self.pixels = VarIntPrefixedByteArray.read(file_object)
        else:
            self.height = 0
            self.offset = None
            self.pixels = None
Example #6
0
 def read_with_context(file_object, context):
     if context.protocol_version >= 201:
         value = Float.read(file_object)
     else:
         value = Byte.read(file_object)
     if context.protocol_version < 204:
         value /= 63.5
     return value
 def read_with_context(file_object, context):
     if context.protocol_later_eq(201):
         value = Float.read(file_object)
     else:
         value = Byte.read(file_object)
     if context.protocol_earlier(204):
         value /= 63.5
     return value
Example #8
0
    def read(self, file_object):
        self.map_id = VarInt.read(file_object)
        self.scale = Byte.read(file_object)

        if self.context.protocol_version >= 107:
            self.is_tracking_position = Boolean.read(file_object)
        else:
            self.is_tracking_position = True

        if self.context.protocol_version >= 452:
            self.is_locked = Boolean.read(file_object)
        else:
            self.is_locked = False

        icon_count = VarInt.read(file_object)
        self.icons = []
        for i in range(icon_count):
            if self.context.protocol_version >= 373:
                type = VarInt.read(file_object)
            else:
                type, direction = divmod(UnsignedByte.read(file_object), 16)
            x = Byte.read(file_object)
            z = Byte.read(file_object)
            if self.context.protocol_version >= 373:
                direction = UnsignedByte.read(file_object)
            if self.context.protocol_version >= 364:
                has_name = Boolean.read(file_object)
                display_name = String.read(file_object) if has_name else None
            else:
                display_name = None
            icon = MapPacket.MapIcon(type, direction, (x, z), display_name)
            self.icons.append(icon)

        self.width = UnsignedByte.read(file_object)
        if self.width:
            self.height = UnsignedByte.read(file_object)
            x = Byte.read(file_object)
            z = Byte.read(file_object)
            self.offset = (x, z)
            self.pixels = VarIntPrefixedByteArray.read(file_object)
        else:
            self.height = 0
            self.offset = None
            self.pixels = None
Example #9
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))
Example #10
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))
Example #11
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))
Example #12
0
 def read(cls, file_object):
     return cls(*(Byte.read(file_object) for i in range(3)))