Source code of http://www.terrariaonline.com/threads/116001/