Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Fix fetching biomes during world generation

Open NewwindServer opened this issue 1 year ago • 6 comments

Fixes #11084

getBiome() on LevelReader calls getNoiseBiome(), which itself calls getChunk() in order to get the biome cached inside the chunk. However, calling getChunk() on WorldGenRegion will cause a crash if the chunk isn't found: "Requested chunk unavailable during world generation" This means that features which attempt to fetch biomes during generation (LakeFeature/SnowAndFreezeFeature) can cause the server to crash. This patch ensures that these features are fetching biomes in a way that doesn't call getChunk()

NewwindServer avatar Jul 15 '24 17:07 NewwindServer

Currently running my server with this exact patch, works perfectly and server no longer crashes on LakeFeature. Would love to see this merged!

fucksophie avatar Jul 28 '24 04:07 fucksophie

LakeFeature is deprecated and vanilla has moved away from using it for anything except for lava lakes. The error for unsafe chunk gets you are removing here is an intentional safeguard against bad code, such as that in the dead path in LakeFeature when creating water lakes. While it may appear to 'fix' the problem at hand it is not a proper solution and will cause other more serious problems to go undetected. This should be reported to Mojang if it's reproducible with a datapack. Given the circumstances I don't really think this is something we should care to fix, but if it is it would need to be a targeted change to LakeFeature for the aforementioned reasons.

relevant disussion

jpenilla avatar Jul 28 '24 05:07 jpenilla

This patch works, and stops my datapack heavy server (Terralith, Nullscape, etc...) from crashing. But, at the same time it makes new chunk generation performance x3-x4 worse! Why does it, and how can I make sure performance isn't so bad and it doesn't crash?

fucksophie avatar Jul 29 '24 22:07 fucksophie

This patch works, and stops my datapack heavy server (Terralith, Nullscape, etc...) from crashing. But, at the same time it makes new chunk generation performance x3-x4 worse! Why does it, and how can I make sure performance isn't so bad and it doesn't crash?

Can confirm that this changed code is called very often during world gen and could therefore potentially have a negative performance impact, I will make just the two features which call getBiome() during worldgen (LakeFeature and SnowAndFreezeFeature) use the uncached biome instead of overriding getBiome() entirely on WorldGenRegion.

NewwindServer avatar Jul 31 '24 22:07 NewwindServer

@fucksophie I changed the patch to fix the lake feature in a different way which shouldn't slow down world generation. Test it out and lmk

NewwindServer avatar Jul 31 '24 23:07 NewwindServer

Hi @NewwindServer, can you please create a new issue with proper reproduction steps for 1.21? The issue you're linking that this PR fixes (https://github.com/PaperMC/Paper/issues/11084) was closed due to being incomplete and a deleted user.

codebycam avatar Aug 01 '24 03:08 codebycam