In PR #9 I started documenting the different hash functions used by the minecraft code. But that's incomplete so I'm opening this issue.
A hash function in this context is how the world seed is combined with the x and z coordinates in order to seed to PRNG. For example, the old nether fortress algorithm:
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
{
int x = chunkX >> 4;
int z = chunkZ >> 4;
this.rand.setSeed((long)(x ^ z << 4) ^ this.worldObj.getSeed());
this.rand.nextInt();
if (this.rand.nextInt(3) != 0) {
return false;
} else if (chunkX != (x << 4) + 4 + this.rand.nextInt(8)) {
return false;
} else if (chunkZ != (z << 4) + 4 + this.rand.nextInt(8)) {
return false;
} else {
return true;
}
}
In this case, the hash function would be (long)(x ^ (z << 4)) ^ worldSeed, where x and z are the chunk coordinate divided by 16, or the block coordinate divided by 256.
Conventional wisdom says that nether fortresses align along the z-axis, and that can be easily verified using tools like AMIDST. Is that just because the x coordinate is checked before the z coordinate? Or is it just because of the weak hash function?
The goal is to write a document that answers the questions:
Why do some minecraft structures generate in strips? (nether fortresses before 1.16, and shipwrecks before 1.16)
Given the coordinates of one structure, is it possible to generate a list of coordinates of nearby structures? Is there any the optimal direction to maximize the probability of finding another structure?
Are there any patterns that can be used to find chunks with a high or low probability of generating specific structures?
Given one structure, is it possible to find a different world seed with the same structure? At the same location or at a different location?
Is there any hash function that is faster than the ones used and doesn't have any of this problems?
If someone finds an answer to any of this questions, feel free to reply with a link or whatever.
The following is just a copy of the work-in-progress docs/hash_functions.md:
slime_hash
The hash used to calculate slime chunks results in some interesting patterns, which can be seen in this visualization:
In PR #9 I started documenting the different hash functions used by the minecraft code. But that's incomplete so I'm opening this issue.
A hash function in this context is how the world seed is combined with the x and z coordinates in order to seed to PRNG. For example, the old nether fortress algorithm:
source: minecraftforum
In this case, the hash function would be
(long)(x ^ (z << 4)) ^ worldSeed
, wherex
andz
are the chunk coordinate divided by 16, or the block coordinate divided by 256.Conventional wisdom says that nether fortresses align along the z-axis, and that can be easily verified using tools like AMIDST. Is that just because the x coordinate is checked before the z coordinate? Or is it just because of the weak hash function?
The goal is to write a document that answers the questions:
If someone finds an answer to any of this questions, feel free to reply with a link or whatever.
The following is just a copy of the work-in-progress
docs/hash_functions.md
:slime_hash
The hash used to calculate slime chunks results in some interesting patterns, which can be seen in this visualization:
https://badel2.github.io/slime_seed_finder/slime_map.html (press generate and then run, red = no slime chunk, green = yes slime chunk)
And then the algorithm is just:
So what happens if x and z are 0? Then
slimeSeed = worldSeed ^ E
. But that's not useful at all.Only x 0? Only z 0?
If x and z are equal?
If x and z are small?
If x and z are large?
Note that x only affects the lower 32 bits.
Some collisions?
Some tricks to find big areas full of slime chunks?
Visualization of
nextInt(10)%2
?structure_hash
For burried treasures, the constants are: