UNFINISHED!!!!!

I have been meaning to write this post for a good while, but never really got around to it. However, we are here, we are now, so might as well.

Backstory

Back in 2021, I did a MC server with 5-6 of my friends. Of course, as any good SMP goes, we started messing around and creating core memories. That world wa probably the MC world I had advanced the furthest in at that point of time - I had a full trading hall, a lot of buildings around, and most of my friends were active (nowadays I can barely get 3 of my friends to get on).

Unfortunately, at that time, the fifth column had started their attack on the whole MC community - they were scanning the whole IPv4 space, looking for servers with an open 25565 port, on which a valid minecraft server was hosted. Then, they checked for each of them if the server was offline. As luck would have it, my server was in offline mode, because my broke ass friends didn't have paid minecraft at the time. Of course, this meant that they just logged in as my nickname (offline servers let you do that), and basically /fill ~-20 ~-20 ~-20 ~20 ~20 ~20 air'd the piss out of the server.

I was quite bummed about this, because it was my favourite world to play on, and I hadn't backed up the world at all. This of course teached me an important lesson of backing up my stuff (lies) and guarding the public services I host (pure bullshit, it is a matter of when, not if I get hacked).

A light of hope

Of course, as any server goes, we had a lot of screenshots of the server. This was my first glimmer of hope that I could theoretically reverse-engineer the seed from terrain features. However, the terrain was too heavily modified and there wasn't really anything usable. The best I could do is to do a bad reconstruction of some of the buildings.

Then, however, I found it.

Map 1

Map 2

Map 3

Map 4

Map 5

Map 6

Map 7

Map 8

One of my friends that had played for a while on the server was messing with a client-side mod that exposed the exact locations of structures from maps villagers sold. As luck would have it, my trading hall had 4 cartographers, which sold 8 maps. At the time I just wrote the screenshots he sent me as kinda useless, as I wasn't in a rush to go to a woodland mansion or a burried treasure. I would however not realise that those screenshots were the sole reason I managed to find the seed of the world.

reveng-mc - the star of the show

When I discovered these screenshots, I immediatly went spelunking in Minecraft's code, studying how the structure generation works. Of course, I will not show actual MC code, but there is a really simple algorithm that determines if a structure is going to start from a certain chunk. As luck would have it, the villagers' maps reveal the exact seed chunk of a structure.

Another trick up my sleeve is that only the bottom 48 bits of a 64-bit seed determine where structures generate (because of how java random numbers generate). This meant that instead of walking the 64-bit space (a task for several supercomputers), I needed to walk just the 48-bit space, which is feasible for a reasonably fast GPU (which I have).

I managed to throw together some terrible C++ OpenCL code that walks the whole 48-bit seed space and printf's (yes, I know, atrocious, but works) the seed if it potentially generates all 8 structures.

Of course, my first version, which I wrote back in 2023 didn't work as I had messed up something. However, I rewrote it in late 2024.

The feeling I felt as the program printed SEED 173383753059004 cannot be contained in text alone. I had finally seen a light at the end of the tunnel.

The second piece of the story

Now, we still have 16 bits to figure out. At this point, I figured that I'd again brute-force it - if I just hooked into minecraft's code and just walked the whole 16-bit space, combining it with the already found lower 48 bits, and testing if the world actaully generated the 8 structures (just because Minecraft considers generating a structure on a chunk, it needs to validate that the terrain and biomes are appropriate).

Some of the unspeakable sins I had to commit against the programming gods were monkey-patching the MinecraftServer class, as apparently generating a single chunk requires you to run a full server with a valid player list and a loaded resource pack (Minecraft's code is a tangled mess). However, a lot of dubious Java code later, I managed to trick Minecraft's code into brute-forcing the upper 16 bits.

At this point my thought process was that either way, no more than 100s of seeds were going to generate those 8 structures in those exact spots. However, as luck would have it, about 40 minutes in, I got a SEED 2453227805786426044 notification.

I held my breath, entered the seed into a fresh "Create world" minecraft screen, and this greated my eyes:

Raw world

We are not done yet

Of course, at this point, I only had the raw world, witohut all of mine and my friends' builds