Cavegen: Fix crash when getting biome outside mapchunk #7480
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cavegen: Fix errors when getting biome outside mapchunk
Some cave segments are outside the mapchunk.
Previously, biome was being calculated by a function that uses the noise
maps. Points outside the mapchunk resulted in incorrect noise map indexes
that were sometimes outside the noise map size, causing a crash.
Use either noise maps or point noise calculations depending on point
location.
////////////////////////
Attends to #7272 (comment) and #7272 (comment)
Cavegen gets the biome for each cave segment in order to place biome-defined cave liquids.
See bb3baef , this caused the bug and the crashes. This PR is a partial revert of that.
calcBiomeAtPoint()
was used originally, that function can be used for any point, inside or outside the currently generating mapchunk.getBiomeAtPoint()
is used in current master. It can only be used for X, Z values inside the currently generating mapchunk because it uses the heat and humidity values from the noise maps for the currently generating mapchunk. However it is faster as it does not calculate noise.I just realised that cavegen generates out beyond the mapchunk borders so occasionally the biome is being 'got' for a point just outside the mapchunk.
getBiomeAtPoint()
calculates the index for the noise maps:For a point outside the mapchunk this mostly results in a weird index value that accesses an incorrect position, but sometimes it can result in a negative index or an index larger than the noisemap size, that probably causes rare crashes and probably caused #7272 (comment)
This PR checks X, Z values and uses the fast function if inside the mapchunk and the slower one if outside.