fix wrong noise biome height cache corruption

BiomeSectionDataProvider was accessed with the in section height, that is not the height we want to use for the biome noise
This commit is contained in:
Moritz Zwerger 2024-02-29 23:58:50 +01:00
parent e5c2d79f17
commit 580258943b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 8 additions and 6 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger * Copyright (C) 2020-2024 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -23,7 +23,6 @@ import de.bixilon.minosoft.data.world.biome.accessor.noise.NoiseBiomeAccessor
import de.bixilon.minosoft.data.world.biome.accessor.noise.VoronoiBiomeAccessor import de.bixilon.minosoft.data.world.biome.accessor.noise.VoronoiBiomeAccessor
import de.bixilon.minosoft.data.world.chunk.chunk.Chunk import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
import de.bixilon.minosoft.data.world.positions.BlockPosition import de.bixilon.minosoft.data.world.positions.BlockPosition
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inSectionHeight
import de.bixilon.minosoft.gui.rendering.util.VecUtil.sectionHeight import de.bixilon.minosoft.gui.rendering.util.VecUtil.sectionHeight
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_19W36A import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_19W36A
@ -46,7 +45,7 @@ class WorldBiomes(val world: World) : BiomeAccessor {
fun getBiome(x: Int, y: Int, z: Int, chunk: Chunk): Biome? { fun getBiome(x: Int, y: Int, z: Int, chunk: Chunk): Biome? {
val noise = this.noise ?: return chunk.biomeSource.get(x, y, z) val noise = this.noise ?: return chunk.biomeSource.get(x, y, z)
chunk[y.sectionHeight]?.let { return it.biomes[x, y.inSectionHeight, z] } // access cache chunk[y.sectionHeight]?.let { return it.biomes[x, y, z] } // access cache
return noise.get(x, y, z, chunk) return noise.get(x, y, z, chunk)
} }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger * Copyright (C) 2020-2024 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -17,12 +17,14 @@ import de.bixilon.kutil.concurrent.lock.Lock
import de.bixilon.minosoft.data.registries.biomes.Biome import de.bixilon.minosoft.data.registries.biomes.Biome
import de.bixilon.minosoft.data.world.chunk.ChunkSection import de.bixilon.minosoft.data.world.chunk.ChunkSection
import de.bixilon.minosoft.data.world.container.SectionDataProvider import de.bixilon.minosoft.data.world.container.SectionDataProvider
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inSectionHeight
class BiomeSectionDataProvider( class BiomeSectionDataProvider(
lock: Lock? = null, lock: Lock? = null,
val section: ChunkSection, val section: ChunkSection,
) : SectionDataProvider<Biome?>(lock, false) { ) : SectionDataProvider<Biome?>(lock, false) {
@Deprecated("Wrong y coordinate for biomes")
override fun get(index: Int): Biome? { override fun get(index: Int): Biome? {
var biome = super.get(index) var biome = super.get(index)
if (biome != null) return biome if (biome != null) return biome
@ -32,10 +34,11 @@ class BiomeSectionDataProvider(
} }
override fun get(x: Int, y: Int, z: Int): Biome? { override fun get(x: Int, y: Int, z: Int): Biome? {
var biome = super.get(x, y, z) val inSectionY = y.inSectionHeight
var biome = super.get(x, inSectionY, z)
if (biome != null) return biome if (biome != null) return biome
biome = section.chunk.world.biomes.noise?.get(x, y, z, section.chunk) biome = section.chunk.world.biomes.noise?.get(x, y, z, section.chunk)
unsafeSet(x, y, z, biome) unsafeSet(x, inSectionY, z, biome)
return biome return biome
} }
} }