I have 4 mammilaria that bloom dependably throughout the spring and summer. I have never done anything special to them to encourage blooms. I feed them with a standard plant food in the spring (I used Schultz's this year.) Cacti just bloom when they finally get old enough, I think. I have 3 that haven't bloomed yet. I'm still waiting on them.
Other than that, I keep them in a west window, but the window is protected by an awning in the summer. On very hot days, I move them away from the window. (The intense sun coming through the window in the summer can burn them.)
Here is a link to a good page on mammilaria:
https://www.mammillarias.net/
And here is a tiny, not-very-good pic of one of mine. (I was just playing with the camera.

)
[img]https://i252.photobucket.com/albums/hh27/Kisal_photos/100_0136_2.jpg[/img]