Does anybody know how Terraria keeps such good FPS? There are millions of blocks and water tiles,
countless particles torches, etc. How did they do that? Any ideas? Thanks.
This was answered in the thread already. Terraria (most likely) uses chunks and processes everything within those chunks while ignoring everything that is outside of said chunks. So the world is basically active around the player (+some extra) but everything else sort of gets frozen, doesn´t create particles/enemies etc. and thus takes basically no processing power. So yes, there are millions of tiles but it doesn´t matter. Even if you would put trillions in, only a specific amount of them is ever needed around the player.
In terms of water, I really don´t know how one could do it. I found this though
Along with the code
I think there is a fair chance that you´d be able to translate this into Events or JS (or webassembly?), though it will likely be slower AND it is not optimized for chunking and such.