Fix for issue #973

This is a "quick-and-dirty fix", you may improve it as I'm novice in Python.
Repeated code can be moved into a function, and I may have missed some textures, as I tested only textures defined by my favorite texture pack.