Fabric API

Fabric API

108M Downloads

ClientChunkEvents.CHUNK_LOAD triggers before chunk biomes are fully initialized

wefhy opened this issue ยท 1 comments

commented

I've been trying to solve a bug in my map mod for a few days now. Looks like the problem is that ClientChunkEvents.CHUNK_LOAD triggers after all blocks are properly initialized but before all biomes are properly initialized. It led to a weird patterns (always the same pattern when launching the game consecutively with player at the same place) in biomes. Every biome in both overworld and nether had a pattern of plains biome showing up like this:

image
(nether wastes is red, basalt deltas are gray and plains are green)

The problem was simply solved by launching a thread with a small delay before I started reading the biome data.

Example code:

 ClientChunkEvents.CHUNK_LOAD.register { cw, wc ->
    val heightmapSurface = wc.getHeightmap(Heightmap.Type.WORLD_SURFACE)
    val startX = wc.pos.startX
    val startZ = wc.pos.startZ
    for (posZ in 0 until 16) {
        for (posX in 0 until 16) {
            val surfaceHeight = heightmapSurface[posX, posZ]
            val absolutePos = BlockPos(startX + posX, surfaceHeight, startZ + posZ)
            val biome = cw.biomeAccess.getBiome(absolutePos).value()
        }
    }
}

If you launch the game while being in the nether and put a breakpoint at val biome = ..., some of the values will have biome.category.name being plains instead of nether

commented

I tried this myself, and for some reason this ended up accessing chunk (-1, -1) when getting the biome at position (0, 128, 0) which belongs to chunk (0, 0). Not sure why it's implemented that way in vanilla, but the event is not to blame (the chunk parameter is properly initialized and ready to be queried from the world when the event is dispatched).