def write_fields(self, packet_buffer):
        VarInt.send(self.map_id, packet_buffer)
        Byte.send(self.scale, packet_buffer)
        if self.context.protocol_version >= 107:
            Boolean.send(self.is_tracking_position, packet_buffer)

        VarInt.send(len(self.icons), packet_buffer)
        for icon in self.icons:
            if self.context.protocol_version >= 373:
                VarInt.send(icon.type, packet_buffer)
            else:
                type_and_direction = (icon.type << 4) & 0xF0
                type_and_direction |= (icon.direction & 0xF)
                UnsignedByte.send(type_and_direction, packet_buffer)
            Byte.send(icon.location[0], packet_buffer)
            Byte.send(icon.location[1], packet_buffer)
            if self.context.protocol_version >= 373:
                UnsignedByte.send(icon.direction, packet_buffer)
            if self.context.protocol_version >= 364:
                Boolean.send(icon.display_name is not None, packet_buffer)
                if icon.display_name is not None:
                    String.send(icon.display_name, packet_buffer)

        UnsignedByte.send(self.width, packet_buffer)
        if self.width:
            UnsignedByte.send(self.height, packet_buffer)
            UnsignedByte.send(self.offset[0], packet_buffer)  # x
            UnsignedByte.send(self.offset[1], packet_buffer)  # z
            VarIntPrefixedByteArray.send(self.pixels, packet_buffer)
Example #2
0
    def write(self, socket, compression_threshold=None):
        packet_buffer = PacketBuffer()
        VarInt.send(self.id, packet_buffer)

        VarInt.send(self.map_id, packet_buffer)
        Byte.send(self.scale, packet_buffer)
        if self.context.protocol_version >= 107:
            Boolean.send(self.is_tracking_position, packet_buffer)

        VarInt.send(len(self.icons), packet_buffer)
        for icon in self.icons:
            type_and_direction = (icon.direction << 4) & 0xF0
            type_and_direction |= (icon.type & 0xF)
            UnsignedByte.send(type_and_direction, packet_buffer)
            Byte.send(icon.location[0], packet_buffer)
            Byte.send(icon.location[1], packet_buffer)

        UnsignedByte.send(self.width, packet_buffer)
        if self.width:
            UnsignedByte.send(self.height, packet_buffer)
            UnsignedByte.send(self.offset[0], packet_buffer)  # x
            UnsignedByte.send(self.offset[1], packet_buffer)  # z
            VarIntPrefixedByteArray.send(self.pixels, packet_buffer)

        self._write_buffer(socket, packet_buffer, compression_threshold)
Example #3
0
    def write_fields(self, packet_buffer):
        VarInt.send(self.map_id, packet_buffer)
        Byte.send(self.scale, packet_buffer)
        if self.context.protocol_version >= 107:
            Boolean.send(self.is_tracking_position, packet_buffer)

        VarInt.send(len(self.icons), packet_buffer)
        for icon in self.icons:
            if self.context.protocol_version >= 373:
                VarInt.send(icon.type, packet_buffer)
            else:
                type_and_direction = (icon.type << 4) & 0xF0
                type_and_direction |= (icon.direction & 0xF)
                UnsignedByte.send(type_and_direction, packet_buffer)
            Byte.send(icon.location[0], packet_buffer)
            Byte.send(icon.location[1], packet_buffer)
            if self.context.protocol_version >= 373:
                UnsignedByte.send(icon.direction, packet_buffer)
            if self.context.protocol_version >= 364:
                Boolean.send(icon.display_name is not None, packet_buffer)
                if icon.display_name is not None:
                    String.send(icon.display_name, packet_buffer)

        UnsignedByte.send(self.width, packet_buffer)
        if self.width:
            UnsignedByte.send(self.height, packet_buffer)
            UnsignedByte.send(self.offset[0], packet_buffer)  # x
            UnsignedByte.send(self.offset[1], packet_buffer)  # z
            VarIntPrefixedByteArray.send(self.pixels, packet_buffer)
Example #4
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 #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(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