model rendering: make random seed on demand

This commit is contained in:
Bixilon 2023-03-30 13:43:20 +02:00
parent b545d930f4
commit 4a469a9394
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 4 additions and 7 deletions

View File

@ -30,8 +30,9 @@ class WeightedBlockRender(
) : BlockRender {
private fun getModel(random: Random?): BlockRender {
private fun getModel(random: Random?, position: BlockPosition): BlockRender {
if (random == null) return models.first().model
random.setSeed(position.positionHash)
var weightLeft = abs(random.nextLong() % totalWeight)
@ -46,12 +47,11 @@ class WeightedBlockRender(
}
override fun getParticleTexture(random: Random?, position: Vec3i): AbstractTexture? {
random?.setSeed(position.positionHash)
return getModel(random).getParticleTexture(random, position)
return getModel(random, position).getParticleTexture(random, position)
}
override fun render(position: BlockPosition, mesh: WorldMesh, random: Random?, state: BlockState, neighbours: Array<BlockState?>, light: ByteArray, tints: IntArray?): Boolean {
return getModel(random).render(position, mesh, random, state, neighbours, light, tints)
return getModel(random, position).render(position, mesh, random, state, neighbours, light, tints)
}

View File

@ -32,7 +32,6 @@ import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
import de.bixilon.minosoft.data.world.chunk.light.SectionLight
import de.bixilon.minosoft.data.world.chunk.neighbours.ChunkNeighbours
import de.bixilon.minosoft.data.world.positions.BlockPosition
import de.bixilon.minosoft.data.world.positions.BlockPositionUtil.positionHash
import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.models.block.state.render.BlockRender
import de.bixilon.minosoft.gui.rendering.world.entities.BlockEntityRenderer
@ -131,8 +130,6 @@ class SolidCullSectionPreparer(
light[O_UP] = (light[O_UP].toInt() or 0xF0).toByte()
}
random?.setSeed(position.positionHash)
val tints = tintColorCalculator.getAverageBlockTint(chunk, neighbourChunks, state, x, y, z)
var rendered = model.render(position, mesh, random, state, neighbourBlocks, light, tints)