did something like that on cc some month ago
waterSim.exe
Basically it's an algorithm called "cellular automata".
It's Array based:
Foreach cell that have water, check the surrounding bottom cell and transfer water if empty.
My example handle communicating vessels (which makes it a bit more complicated, you don't transfert water anymore but mass, and you put exces on top), terraria doesn't.
But anyway it's pretty heavy in a large scale, event in cc.Yann2012-02-07 16:17:12