Technical Oregen Information

This page collects technical information that isn't really important for gameplay, but is useful for the curious

Ore generation details
Terms:
 * Oremix - A configuration option that describes the dimension it is valid, ores to place, how large, how dense, and the ranges it can appear.
 * Ore center - A chunk that could potentially contain an orevein. Any chunk that satisfies (abs(ChunkX) % 3 == 1, abs(ChunkZ) % 3 == 1). Examples are (1,-1) (22,19) (-124,67) - using chunk X/Z.
 * Orevein - A placed oremix at an ore center.

Analogy
This simple analogy will help explain the old oregen, and how the new oregen in post-2.0 improves on it.

Think of the list of oremixes as a book, with each oremix a chapter. The length of the chapter is equal to the "weight" of the oremix. So the "gold" orevein is 160 pages, but the "mica" orevein only 20. All the chapters for all the dimensions are in the same book.

Old pre 2.0 generation
A random page is opened in the book. If the chapter is for the current dimension, use that vein. Attempt to place all the layers of that vein. If the chapter is not for the current dimension, open to a new random page. Repeat this up to 256 times.

When attempting to place the layers, put the orevein somewhere in the legal range of that oremix.

Place the ores. If this causes requests for new chunks, those chunks are not processed for any ores (even small ores). Details on World Generation Cascading

GT stones (basalt/redgranite/blackgranite/marble) uses a complex method of basically creating a giant ball of rock. This method created tremendous worldgen cascading, since it can create a large ball that goes well beyond currently generated chunks.

Side effects

 * Because the selection algorithm stops once it chooses a valid vein for the dimension, if that vein could not place because it chooses a height that has no stone, that ore center is left empty. This causes very sparse ore, especially in low-lying areas like Twilight Forest. Even the overworld has sparse ores because such a large weight is given to high altitude veins.
 * When worldgen cascade occurs, the new chunks never get any ore veins or small ores. This happens almost all the time with ore veins since they normally fill in a 3x3 to 5x5 chunk area.
 * Noticeable lag when generating a large number of GT stones.

Early 2.0 generation
A RNG between 0-100 is compared against GregTech configuration option oreveinPercentage. Default is 75. If RNG is above oreveinPercentage, no orevein is added at the ore center.

A random page is opened in the book. If the chapter is for the current dimension, use that vein. Attempt to place all the layers of that vein. If the chapter is not for the current dimension, open to a new random page. Repeat this up to 64 times.

When attempting to place the layers, put the orevein somewhere in the legal range of that oremix. If 0 ore is placed, try a new random page. This is tried up to 8 times (8 valid oremixes could not place).

Place the ores. If this causes requests for new chunks, those chunks are not processed for any ores (even small ores).

GT stones same as pre-2.0

Side Effects

 * 25% of ore centers are empty-by-design, and can be tuned via the config file. This is actually a little less than before, which had ~55% empty ore centers.
 * Selection algorithm tries placing up to 8 valid veins for the dimension per ore center. This gives better coverage, especially in Twilight Forest.
 * Worldgen cascade still occurs, and new chunks still never get any ore veins or small ores.
 * Still laggy when generating GT stones.

2.0.2.0+ generation
All generation is now per-chunk, so worldgen cascade no longer happens. This complicates the generation algorithm significantly. This is not for the faint-hearted.

When a new chunk is requested, create a list of all potential ore centers that could affect this chunk (basically any centers within the max vein size of the chunk).

The RNG is now configured to be seeded by the world seed, and chunk X/Z. This guarantees that when these steps are repeated for other chunks, they will have the same results. Compare the list of centers to the generated ore center list. For each of those ore centers not on the list, roll the RNG for oreveinPercentage. If it is empty, add it to the generated ore center list as an empty vein. A random page is opened in the book. If the chapter is for the current dimension, use that vein. Attempt to place the layers of that vein. If the chapter is not for the current dimension, open to a new random page. Repeat this up to 64 times. When attempting to place the layers, put the orevein somewhere in the legal range of that oremix. Place the bottom layer. If 0 ore is placed, try a new random page. This is tried up to 8 times (8 valid oremixes could not place). If at least one ore is placed, add it to the generated ore center list.

If the center is on the generated ore center list, use it to place ores in the current chunk. Again, if the bottom layer places 0 ores, exit early.

When placing ores, offset by +2,+2 so that ores are always placed in generated chunks, and do not activate block updates outside the current chunks.

GT stone generation is also chunkified, and simplified. Support for non-spherical stones is also included. Process is similar to ores.

Side effects

 * World generation speed is much faster. Can now fly horizontally and the worldgen keeps up.
 * Large caverns might miss an orevein in the ceiling.
 * Better in fill.
 * No GT caused worldgen cascading means faster transitions to an ungenerated dimension or new world.
 * Deep Dark can have 2x ore generation without excessive lag. Oremixes are still limited to size=32, size=64 was just too laggy.
 * GT stones are more interesting, with a variety of sizes and shapes. Tuned to have more tall & narrow stones, with wide slabs, vertical curtains, and spheres also possible.

Other things
Because the ore weights per mix are shared across dimensions, but the relative percentage is based on the total weights for a dimension, the same oremix has different chances to appear in a different dimension.

For example, Copper oremix is weight=80, and is present in the Overworld, Nether, End, and Twilight Forest.

So if you are looking for an oremix that is in multiple dimensions, it makes sense to see which dimension has the least total oremix weight.

Bismuth Fix for planets
Use the same book analogy for planetary oregen.

The bug here is that if the chapter was not correct for the planet, the algorithm would simply check the next chapter, continuing until it found a valid chapter for the planet. It only re-rolled when it reached the end of the book. When Bismuth was added to the end of the oremix list, it "captured" all the attempts before it to select a chapter.

A more complete explanation can be found in the ticket