Repetitive thoughts and actions build pathways in the mind, and those grooves get greased through further repetition.
That’s how bad habits and good habits are created. The best way to deal with that is to create an environment that makes good habits easier and bad habits harder.
Start by eliminating distractions and bad influences.