[SPIGOT-6348] World#isChunkGenerated false positives Created: 07/Feb/21  Updated: 08/Feb/21

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Azim Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: 1.16.4, bug, world

Attachments: PNG File file[1].png     PNG File image-2021-02-08-00-08-08-857.png    
Version: git-Spigot-a93cbb1-7a6c3c9 (1.16.4-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

code, where i check if chunk exists
event listener for chunk population event which fires after my checks are happening
what shows up in console when i feed it 64x64 chunks area:

what ends up being generated and rendered by my plugin (expected - only area in the middle aka spawn chunks)



 Comments   
Comment by Azim [ 08/Feb/21 ]

Paper has a neat solution for that:
https://papermc.io/javadocs/paper/1.16/org/bukkit/World.html#getChunkAtAsync-int-int-boolean-

works exactly as my usecase needs it, so i guess i'm tightening my plugin's userbase to paper now 

Comment by blablubbabc [ 08/Feb/21 ]

> Then why is it called isChunkGenerated instead of isChunkExist or something?
Minecraft has changed a lot since this API was initially written and implemented. I haven't checked, but these multiple chunk generation stages probably didn't exist in previous Minecraft versions. So back then, checking if the chunk exists would probably check if the chunk is 'generated', whereas on current Minecraft versions this is no longer the case. The same goes for changes in Minecraft's chunk loading behavior (i.e. that automatic loading of nearby chunks).

Figuring out these differences between version to version and trying to match the old API to the new Minecraft behavior is difficult, especially for this chunk loading related code. And since no one proposed a suitable solution yet (i.e. noone had the motivation or urgent enough need to look through the underlying Minecraft code on this and propose a suitable solution), this was never changed and instead kept as it is right now.

> Effectively it means i'll have to use nms or check all chunks in 2-chunk radius to get what i want from it?
There is a pending PR that changes the behavior of isChunkGenerated to check if the chunk has already been fully generated. But it is still pending review. And even if it is added to Spigot, you will probably still have to check the surrounding chunks yourself then in order to avoid generating further chunks around it.
Edit: Actually, if you only load the chunk via getChunkAt, then you probably don't need to check the neighboring chunks and can ignore everything I said about that. I was referring to the loadChunk method. The issue with isChunkGenerated not working as expected, however, still applies.

Comment by Azim [ 08/Feb/21 ]

Then why is it called isChunkGenerated instead of isChunkExist or something?
Effectively it means i'll have to use nms or check all chunks in 2-chunk radius to get what i want from it?

Comment by blablubbabc [ 08/Feb/21 ]

Maybe related: https://hub.spigotmc.org/jira/browse/SPIGOT-4862

You also have to check the 2 surrounding chunks if they are also already generated. Minecraft will also trigger their generation whenever you load a single chunk.
Edit: This might actually be a 1 chunk radius now (1.16.5). Not sure if this changed since 1.14 (when I last tested this).

Edit: And the other problematic thing that might affect you, also mentioned in that other ticket, and which might explain why you get the populate event for that chunk after you have checked if it has been generated, is that isChunkGenerated might currently only check if the chunk already 'exists', i.e. if the generation of the chunk has been started, not whether it has already been fully generated (there are different chunk generation stages in Minecraft; loading the chunk will promote it to 'fully generated' which then triggers the remaining chunk generation stages, including block population).

Generated at Sat Apr 05 09:53:23 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.