mojira.dev
MC-131462

Coordinate math error causes structure not to generate and possibly other issues

The bug

A mistake in coordinate conversion math reduces the likelihood of structures spawning in negative coordinates. This might also cause the /locate command and cartographer maps to direct you to a non-existent structure. It may also be causing other glitches with structures (and other things) along chunk boundaries.

The correct way to find out which structure region a chunk belongs to requires special handling for negative numbers. E.g. for temples with a region size of 32 (pseudocode):

offsetChunk = chunk < 0 ? chunk - 32 + 1 : chunk;
region = offsetChunk / 32;

That puts chunks -32 to -1 in region -1. This is how it's been computed in previous Minecraft versions.

But the new code flipped that +1 to a -1. But then when converting back after selecting the random chunk for structure spawning, it does it the same way it did before.

chunkForStructure = region*32 + random(24);

So, let's say you're chunk -31, 0. You end up in region -2, 0 instead of -1, 0. If the RNG had picked 1, you should have been the lucky chunk and gotten an igloo or something. But instead, it thinks it should put the igloo in chunk -63. But chunk -63 is part of region -3. Any time the RNG ever picks 0 or 1, it cannot generate a structure.

The other changes to structure generation are clearly deliberate, so this appears to be inadvertent.

I believe this was introduced in 18w06a.

Linked issues

Comments 17

Admiral Fwiffo

Here is the exact change.

The 1.12 code is:

if (chunkX < 0) {
  chunkX -= this.maxDistanceBetweenScatteredFeatures - 1;
}

if (chunkZ < 0) {
  chunkZ -= this.maxDistanceBetweenScatteredFeatures - 1;
}
int k = chunkX / this.maxDistanceBetweenScatteredFeatures;
int j = chunkZ / this.maxDistanceBetweenScatteredFeatures;

The 1.13 code is (ignoring some irrelevant differences in where the constants come from):

chunkX = chunkX < 0 ? chunkX - maxDistanceBetweenScatteredFeatures - 1 : chunkX;
chunkZ = chunkZ < 0 ? chunkZ - maxDistanceBetweenScatteredFeatures - 1 : chunkZ;
int k = chunkX / maxDistanceBetweenScatteredFeatures;
int j = chunkZ / maxDistanceBetweenScatteredFeatures;

Subtle!

Put another way:

chunkX -= this.maxDistanceBetweenScatteredFeatures - 1;

is the equivalent of:

chunkX = chunkX < 0 ? chunkX - (maxDistanceBetweenScatteredFeatures - 1) : chunkX;

which when simplified is:

chunkX = chunkX < 0 ? chunkX - maxDistanceBetweenScatteredFeatures + 1 : chunkX;
ProfMobius (Thomas Guimbretiere)

Really good catch and very subtle error.

 

Admiral Fwiffo

This bug was reintroduced in 1.13-pre7.

I was already wondering why some shipwrecks and ocean ruins I knew from older snapshots seemed to be gone lately. I hope this severe world generation problem doesn't get forgotten before we get 1.13 and people all around the globe start new worlds with no updates around for months.

I implore Mojang to consider that a working world generator is essential, especially since it just got a major overhaul and many people will restart at least parts of their world. When a chunk is generated, you can't repair it anymore. Having this working in the proper release and not be touched for a significant amount of time is more important than keeping exactly to some arbitrarily chosen release date.

7 more comments

Right now. It just came out right now!

Admiral Fwiffo

@simon - This bug does not affect dungeons or strongholds at all.

It has a relatively small effect on guardian temples (maybe 1.5% are missing compared with ~25% of shipwrecks and ocean ruins, and about ~8% of villages, witch huts, etc).

1.13 naturally has a lot fewer guardian temples than 1.12 because of the changes in ocean generation. They require deep ocean (any kind of deep ocean) and there is less deep ocean now. There is no such thing as warm deep ocean, so you'll get shallow warm ocean where you might have gotten deep ocean before. Also there is less deep ocean near shorelines for somewhat complicated reasons. So fewer guardian temples is mostly WAI.

Hmm, the ocean ruins I missed seem to be back, but the two shipwrecks I lost are still gone. I guess they just changed the shipwreck algorithm in some previous snapshot.

Admiral Fwiffo

I've verified that this is fixed in 18w30a.

SwirlyLightning

It hasn't fixed /locate

  1. MC-108801 

Admiral Fwiffo

migrated

Confirmed

Minecraft 1.13-pre2, Minecraft 1.13-pre10, Minecraft 1.13

Minecraft 1.13-pre4, Minecraft 18w30a

Retrieved