Everything we think, feel, do, has an effect.
We attract what we are, not what we ideally desire ourselves to be. Whatever energy you put into the universe is exactly what you will receive back from it. Though I might not be able to entirely explain such a phenomenon, I can say that it is somewhat analogous to Newton's third law of motion or to Quantum Physics. Newton's third law of motion essentially states that every action has an opposite and equal reaction.Though this law is used to describe physical motion, it can also in a sense be used to describe a much broader idea of energy. This is also where quantum physics actually gets involved. In it's most basic form, quantum physics strives to explain the nature of the smallest scale of atomic and subatomic particles, and the vibration and movement of such particles, including all forms of energy of course. In fact, some have even claimed that quantum physics even supports ideas such as "The Law of Attraction". Which as I have said, essentially just states that like energy in the universe attracts like energy.
When I look at some of the things I have been blessed with: love, happiness, success, meaningful friendships, I sometimes shake my head in disbelief at how blessed I am. And sometimes I even catch myself asking how I got so lucky. But the answer is pretty simple. Like energy attracts like energy.
I tend to consider myself a very happy person in general. When I'm not hangry, or deep in thought, you can usually catch me with a smile on my face. Even in the worst of circumstances, I always try to look on the bright side, even when such a thing is difficult to do. Still, even with being as happy of a person as I generally am, I'm only human and life can get me down sometimes and I have to work hard to not allow for negative thoughts to consume me. I actively choose to try and think positively and because of this, I tend to attract positive energy, positive people, and positive situations into my life rather than negative energy, negative people, and negative situations. Because of the way that I think and the positive energy that I project, my reality has been shaped by these two factors.
Regardless of where the idea that you attract the energy that you give comes from, there is a lot of truth behind this way of thinking. While you might not have control over every situation which happens to you, you are in control of how you react, and that's what's even more important.