The easiest way to determine the mood of your cat is to watch their tail. A contented or confident cat will walk with their tail held high and raise their tail as you stroke their back. If they are lying down, the tail may twitch a little but will largely remain still. A trembling tail (especially if combined with a desire to rub their face and chin against you) is a sign of great affection and happiness. If he is holding his tail high and then flicks the end of his tail, he is acknowledging you but is otherwise engaged and to busy to stop for a chat.
When a cat holds his tail diagonally up from his body, he is less happy and possibly feeling nervous, while a tail held low is a sign of displeasure or fear. If his tail is held upright, but the end is deflected off to one side, he may be friendly towards you, but unsure of whether you are friendly towards him, whereas if his tail sticks horizontally out from his body but the end droops down, he may be feeling defensive but preparing to attack you.
Many cats twitch the ends of their tails when hunting or playing, but if the twitching becomes more violent it is likely that the cat is becoming angry or unsettled. If you are stroking your cat and his tail twitches violently or thumps then he is becoming annoyed and is not enjoying your attention and you should leave him alone for a while. If he puffs his tail up, he is feeling threatened or has had a shock and is trying to make himself look bigger in order to get you (or another animal) to leave him alone. He may also turn his body side on and the hair on his back may stand on end
Some cats, such as the Manx, do not have a tail. However, they will move the small stump that they do have around as it t was a tail and so you can still determine their mood by paying close attention.