mojira.dev
MC-136886

Finding Nearby Features loads every generated chunk in radius

[Developer Report]

The code that finds the nearest feature in a radius around a position, used by locate, dolphins and treasure maps, is using the wrong method to look up chunks, resulting in every chunk that has been generated to be loaded by the command, crashing servers.

The code never did this pre 1.13, so clearly this was a bug.

 

I traced it down that the wrong getChunk method was used, which forwards to the correct one with the load boolean always set to true

 

Switching it like so still finds structures correctly:

 

 

private StructureStart a(GeneratorAccess generatoraccess, ChunkGenerator<? extends GeneratorSettings> chunkgenerator, SeededRandom seededrandom, long i) {
        if (!chunkgenerator.getWorldChunkManager().a(this)) {
            return StructureGenerator.a;
        } else {
            Long2ObjectMap long2objectmap = chunkgenerator.getStructureStartCache(this);
            StructureStart structurestart = (StructureStart) long2objectmap.get(i);

            if (structurestart != null) {
                return structurestart;
            } else {
                ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i);
                IChunkAccess ichunkaccess = generatoraccess.getChunkProvider().getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z, false, false); // Paper - don't load chunks

                if (ichunkaccess != null) {
                    structurestart = ichunkaccess.a(this.a());
                    if (structurestart != null) {
                        long2objectmap.put(i, structurestart);
                        return structurestart;
                    }
                }

                if (this.a(chunkgenerator, seededrandom, chunkcoordintpair.x, chunkcoordintpair.z)) {
                    StructureStart structurestart1 = this.a(generatoraccess, chunkgenerator, seededrandom, chunkcoordintpair.x, chunkcoordintpair.z);

                    structurestart = structurestart1.b() ? structurestart1 : StructureGenerator.a;
                } else {
                    structurestart = StructureGenerator.a;
                }

                if (structurestart.b()) {
                    generatoraccess.getChunkProvider().a(chunkcoordintpair.x, chunkcoordintpair.z, true).a(this.a(), structurestart);
                }

                long2objectmap.put(i, structurestart);
                return structurestart;
            }
        }
    }

 

Comments 5

Does this still apply to 1.15.2?

Yes, it's the underlying issue of MC-126244
Searching for structures loads/gens every chunk until it hits what it's looking for in a 100 chunk radius

Please check if this is still an issue in 20w17a.

Since MC-126244 is fixed as of 20w17a, please check if this is still an issue in the latest development version.

It is my understanding this is resolved now too.

Aikar

(Unassigned)

Community Consensus

(Unassigned)

Minecraft 1.13.1, 1.15.2, 20w45a, 20w46a, 20w48a

Retrieved