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.

Related issues

Comments

migrated

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!

migrated

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;
migrated

Really good catch and very subtle error.

 

migrated

This bug was reintroduced in 1.13-pre7.

migrated

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.

migrated

Yes, unless coordinates for the new structures are handled separately, shipwrecks and ocean ruins would be impacted more greatly because of their smaller region size. There would be ~25% fewer shipwrecks and ocean ruins overall (and all the missing ones would be in negative X or Z coordinates).

migrated

This is a nasty regression. Thanks for catching it up. It is now fixed again.

migrated

I apologize for not noticing until literally the last minute.

migrated

The question is when 1.13.1 is scheduled for, seeing how this is a major world generation fix preferable to be out as soon as possible.

migrated

Yes this correct. I can confirm this is the case. i too am getting this problem in my world. far less dungeons are being generated and this is also the case for guardian temples.

 

I am using the 1.13 release and when i look at the 1.12.2 for every 1 dungeons in 1.13 there is 4 in 1.12.2 this from me looking at my seed and writing down the locations then flying to those chunks and looking around

qwerty23495

It's already fixed. Confirm for 18w30a when it is released.

migrated

thanks Matthew For info 🙂 Please were can i see the problems that have been fixed with the next roll out and the date we can expect them.

Again many thanks for replying so quickly.

qwerty23495

Right now. It just came out right now!

migrated

@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.

migrated

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.

migrated

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

migrated

It hasn't fixed /locate

  1. MC-108801 

migrated

migrated

Confirmed

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

Minecraft 1.13-pre4, Minecraft 18w30a

Retrieved