Cain became angry when God 'did not have regard' for his offering. The Bible doesn't say who Cain was angry with, except that he was angry. His countenance fell.
God doesn't even mention the offerings when he addresses Cain, he just asks him why he is angry- telling him that if he does well his face will be lifted, if he does not do well- sin is waiting for him. God warns Cain and gives him advice on how to deal with his anger.
What astounded me was God's interjection.
God created a perfect world, with people who hadn't sinned and their community was perfect, between humans and between God and humans. Until humans sinned.
Adam and Eve were kicked out of the garden, but they remained together, having their relationship and started a family. Eve says that it was through God's help that Cain was born; community was being restored.
And then Cain is angry, and him not being at peace, even with himself (we don't know who he was angry with) put the peace and wholeness of the community at risk.
So God addresses this before there is a problem; God is proactive and preventative (our criminal justice approach tends to be reactive).