Flowing water in my voxel terrain

So, I was wondering if I could make flowing water in my voxel terrain… but I don’t know how. So, any help on that would be appreciated!

Water, like in minecraft, is simulated using cellular automata. Essentially, each ‘cell’ or block, is moved individually, following a certain set of rules. The rules for water would be:

  • If block beneath is air, convert block beneath to water
  • Else if block to left/right/back/front is air, convert those to water (with a different level of water)
  • Else, don’t move

The first rule is to allow water to fall.

The second, is to allow water to flow, essentially filling its container by flowing out to its neighbours. As it flows, the amount of water it has needs to decrease. This way, it will terminate when the water can’t flow any further.

Whenever you go through one generation of your automata, you need to create a copy of the data, and only alter the copy, but read from the original. This way, any changes during the simulation won’t affect how the next block will react.