Formula to calculate pre-hardmode ores

BlueSnakelet

Terrarian
I was messing around with the source code, and I was able to derive a simple formula that can be used to determine which ore will generate for any of the first four tiers (Copper/Tin, Iron/Lead, Silver/Tungsten and Gold/Platinum) in any given seed:

(seed * multi + base) % 2147483647 > 1073741823
  • seed is the numerical seed. It is always an integer between 0 and 2147483647.
  • multi is one of four constants, depending on the tier.
    • 1582116761 for the copper tier.
    • 1676571504 for the iron tier.
    • 1476289907 for the silver tier.
    • 1117239683 for the gold tier.
  • base is one of four constants, depending on the tier.
    • 626863973 for the copper tier.
    • 1003550677 for the iron tier.
    • 1358625013 for the silver tier.
    • 1008269081 for the gold tier.
  • X % Y is the modulo operator.

If the inequality holds true, the world generates with the older ore (Copper, Iron, Silver or Gold). Otherwise, it generates with the newer ore (Tin, Lead, Tungsten or Platinum).

For example: If you want to create a world with the seed 665517289, and you want to find out if it will generate with Copper or Tin, you'd calculate like this:

(665517289 * 1582116761 + 626863973) % 2147483647 > 1073741823

Of course, due to the huge numbers involved you can't calculate it by hand. But you can easily do it by copying an pasting it to an online calculator. Just searching the whole thing on Ecosia worked for me. This inequality is true, so the world will generate with Copper.

Alternatively, you can run an algorithm that calculates all four tiers at once. I wrote a short program in the Kotlin Playground that does just that. You write the seed, and the program says which four ores will generate in that world. For convenience, it supports text seeds and automatically converts them to numerical seeds.

The formula does not work with secret world seeds. Even if you could somehow choose the behind-the-scenes seed, the differences in world generation are likely to throw off the RGN, leading to an incorrect result.

Here's a program that generate random seeds with Copper, Iron, Silver and Gold. Just follow the link and click "▶ Run".

Here's a program that generate random seeds with Tin, Lead, Tungsten and Platinum. Just follow the link and click "▶ Run".
 
The seed 5162020 should have only Tin, Lead, Silver and Gold but for some reason you can find there also Copper, Iron, Tungsten and Platinum! How odd!
That must be some sort of bug in the game.

Clarification: This formula is not what the game uses to determine to ores. It is merely a fine distillation of the precise RNG state the game is in when deciding the ores.

Also, the game only limits itself to one ore per tier in a few cases, most notably with which ore is placed underground to be mined. Other forms of obtaining ore (such as crates) are unaffected, and will generate both ores of a tier.

Also also, this formula was created based on the source code for the current version of Terraria (1.4.4.9). Worlds generated in older versions may generate with different ores.
 
On the seed 5162020 all 8 pre-corruption ores generated naturally in the underground. Both of each tier, not just one.
I am hinting at a joke with the 5162020 seed :p
 
Back
Top Bottom