@staticmethod
def set_fold_lvl(block, val):
    """
        Sets the block fold level.

        :param block: block to modify
        :param val: The new fold level [0-7]
        """
    if block is None:
        return
    state = block.userState()
    if state == -1:
        state = 0
    if val >= 1023:
        val = 1023
    state &= 2080440319
    state |= val << 16
    block.setUserState(state)
