@@ -24,6 +24,7 @@ import com.lambda.event.events.TickEvent
2424import com.lambda.event.events.WorldEvent
2525import com.lambda.event.listener.SafeListener.Companion.listen
2626import com.lambda.event.listener.SafeListener.Companion.listenConcurrently
27+ import com.lambda.event.listener.UnsafeListener.Companion.listenConcurrentlyUnsafe
2728import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
2829import com.lambda.graphics.RenderMain
2930import com.lambda.graphics.mc.RegionRenderer
@@ -45,9 +46,9 @@ import java.util.concurrent.ConcurrentLinkedDeque
4546class ChunkedRenderer (
4647 owner : Any ,
4748 name : String ,
48- depthTest : SafeContext . () -> Boolean ,
49- pauseUpdates : SafeContext . () -> Boolean ,
50- private val update : RenderBuilder .(ClientWorld , FastVector ) -> Unit
49+ depthTest : () -> Boolean ,
50+ pauseUpdates : () -> Boolean ,
51+ private val update : RenderBuilder .(FastVector ) -> Unit
5152) : AbstractRenderer(name, depthTest) {
5253 private val chunkMap = ConcurrentHashMap <Long , ChunkData >()
5354
@@ -61,8 +62,9 @@ class ChunkedRenderer(
6162 private val uploadQueue = ConcurrentLinkedDeque < () -> Unit > ()
6263
6364 init {
64- owner.listen <WorldEvent .BlockUpdate .Client > { event ->
65+ owner.listenUnsafe <WorldEvent .BlockUpdate .Client > { event ->
6566 val pos = event.pos
67+ val world = mc.world ? : return @listenUnsafe
6668 world.getWorldChunk(pos)?.chunkData?.markDirty()
6769
6870 val xInChunk = pos.x and 15
@@ -76,23 +78,23 @@ class ChunkedRenderer(
7678
7779 owner.listenUnsafe<WorldEvent .ChunkEvent .Load > { event -> event.chunk.chunkData.markDirty() }
7880 owner.listenUnsafe<WorldEvent .ChunkEvent .Unload > { chunkMap.remove(it.chunk.chunkKey)?.clearData() }
79- owner.listen <WorldEvent .Player . Leave > { rebuild () }
81+ owner.listenUnsafe <WorldEvent .Leave > { clear () }
8082
81- owner.listenConcurrently <TickEvent .Pre > {
82- if (pauseUpdates()) return @listenConcurrently
83+ owner.listenConcurrentlyUnsafe <TickEvent .Pre > {
84+ if (pauseUpdates()) return @listenConcurrentlyUnsafe
8385 val queueSize = rebuildQueue.size
8486 val polls = minOf(StyleEditor .rebuildsPerTick, queueSize)
8587 val depth = depthTest()
8688 repeat(polls) { rebuildQueue.poll()?.rebuild(depth) }
8789 }
8890
89- owner.listen <TickEvent .Pre > {
91+ owner.listenUnsafe <TickEvent .Pre > {
9092 val polls = minOf(StyleEditor .uploadsPerTick, uploadQueue.size)
9193 repeat(polls) { uploadQueue.poll()?.invoke() }
9294 }
9395
94- owner.listen <RenderEvent .RenderWorld > { render() }
95- owner.listen <RenderEvent .RenderScreen > { renderScreen() }
96+ owner.listenUnsafe <RenderEvent .RenderWorld > { render() }
97+ owner.listenUnsafe <RenderEvent .RenderScreen > { renderScreen() }
9698 }
9799
98100 private fun getChunkKey (chunkX : Int , chunkZ : Int ) =
@@ -170,7 +172,7 @@ class ChunkedRenderer(
170172 for (x in chunk.pos.startX.. chunk.pos.endX) {
171173 for (z in chunk.pos.startZ.. chunk.pos.endZ) {
172174 for (y in chunk.bottomY.. chunk.height) {
173- update(scope, chunk.world as ? ClientWorld ? : continue , fastVectorOf(x, y, z))
175+ update(scope, fastVectorOf(x, y, z))
174176 }
175177 }
176178 }
@@ -184,9 +186,9 @@ class ChunkedRenderer(
184186 companion object {
185187 fun Any.chunkedRenderer (
186188 name : String ,
187- depthTest : SafeContext . () -> Boolean = { false },
188- pauseUpdates : SafeContext . () -> Boolean = { false },
189- update : RenderBuilder .(ClientWorld , FastVector ) -> Unit
189+ depthTest : () -> Boolean = { false },
190+ pauseUpdates : () -> Boolean = { false },
191+ update : RenderBuilder .(FastVector ) -> Unit
190192 ) = ChunkedRenderer (this , name, depthTest, pauseUpdates, update).also { renderer ->
191193 (this as ? Module )?.let { module ->
192194 module.onEnable { renderer.rebuild() }
0 commit comments