@@ -3,16 +3,20 @@ package com.lambda.client.module.modules.render
33import com.lambda.client.LambdaMod
44import com.lambda.client.event.SafeClientEvent
55import com.lambda.client.event.events.PacketEvent
6+ import com.lambda.client.event.events.RenderRadarEvent
67import com.lambda.client.event.events.RenderWorldEvent
78import com.lambda.client.module.Category
89import com.lambda.client.module.Module
10+ import com.lambda.client.util.BaritoneUtils
911import com.lambda.client.util.EntityUtils.getInterpolatedPos
1012import com.lambda.client.util.FolderUtils
1113import com.lambda.client.util.TickTimer
1214import com.lambda.client.util.TimeUnit
1315import com.lambda.client.util.color.ColorHolder
1416import com.lambda.client.util.graphics.GlStateUtils
1517import com.lambda.client.util.graphics.LambdaTessellator
18+ import com.lambda.client.util.graphics.RenderUtils2D
19+ import com.lambda.client.util.math.Vec2d
1620import com.lambda.client.util.text.MessageSendHelper
1721import com.lambda.client.util.threads.safeListener
1822import com.lambda.client.util.math.VectorUtils.distanceTo
@@ -43,6 +47,9 @@ object NewChunks : Module(
4347) {
4448 private val relative by setting(" Relative" , false , description = " Renders the chunks at relative Y level to player" )
4549 private val renderMode by setting(" Render Mode" , RenderMode .BOTH )
50+ private val chunkGridColor by setting(" Grid Color" , ColorHolder (255 , 0 , 0 , 100 ), true , { renderMode != RenderMode .WORLD })
51+ private val distantChunkColor by setting(" Distant Chunk Color" , ColorHolder (100 , 100 , 100 , 100 ), true , { renderMode != RenderMode .WORLD }, " Chunks that are not in render distance and not in baritone cache" )
52+ private val newChunkColor by setting(" New Chunk Color" , ColorHolder (255 , 0 , 0 , 100 ), true , { renderMode != RenderMode .WORLD })
4653 private val saveNewChunks by setting(" Save New Chunks" , false )
4754 private val saveOption by setting(" Save Option" , SaveOption .EXTRA_FOLDER , { saveNewChunks })
4855 private val saveInRegionFolder by setting(" In Region" , false , { saveNewChunks })
@@ -106,6 +113,42 @@ object NewChunks : Module(
106113 GlStateUtils .depth(true )
107114 }
108115
116+ safeListener<RenderRadarEvent > {
117+ if (renderMode == RenderMode .WORLD ) return @safeListener
118+
119+ val playerOffset = Vec2d ((player.posX - (player.chunkCoordX shl 4 )), (player.posZ - (player.chunkCoordZ shl 4 )))
120+ val chunkDist = (it.radius * it.scale).toInt() shr 4
121+
122+ for (chunkX in - chunkDist.. chunkDist) {
123+ for (chunkZ in - chunkDist.. chunkDist) {
124+ val pos0 = getChunkPos(chunkX, chunkZ, playerOffset, it.scale)
125+ val pos1 = getChunkPos(chunkX + 1 , chunkZ + 1 , playerOffset, it.scale)
126+
127+ if (isSquareInRadius(pos0, pos1, it.radius)) {
128+ val chunk = world.getChunk(player.chunkCoordX + chunkX, player.chunkCoordZ + chunkZ)
129+ val isCachedChunk =
130+ BaritoneUtils .primary?.worldProvider?.currentWorld?.cachedWorld?.isCached(
131+ (player.chunkCoordX + chunkX) shl 4 , (player.chunkCoordZ + chunkZ) shl 4
132+ ) ? : false
133+
134+ if (! chunk.isLoaded && ! isCachedChunk) {
135+ RenderUtils2D .drawRectFilled(it.vertexHelper, pos0, pos1, distantChunkColor)
136+ }
137+ RenderUtils2D .drawRectOutline(it.vertexHelper, pos0, pos1, 0.3f , chunkGridColor)
138+ }
139+ }
140+ }
141+
142+ chunks.keys.forEach { chunk ->
143+ val pos0 = getChunkPos(chunk.x - player.chunkCoordX, chunk.z - player.chunkCoordZ, playerOffset, it.scale)
144+ val pos1 = getChunkPos(chunk.x - player.chunkCoordX + 1 , chunk.z - player.chunkCoordZ + 1 , playerOffset, it.scale)
145+
146+ if (isSquareInRadius(pos0, pos1, it.radius)) {
147+ RenderUtils2D .drawRectFilled(it.vertexHelper, pos0, pos1, newChunkColor)
148+ }
149+ }
150+ }
151+
109152 safeListener<PacketEvent .PostReceive > { event ->
110153 if (event.packet is SPacketChunkData
111154 && ! event.packet.isFullChunk
@@ -284,6 +327,17 @@ object NewChunks : Module(
284327 return ending.toIntOrNull() != null
285328 }
286329
330+ // p2.x > p1.x and p2.y > p1.y is assumed
331+ private fun isSquareInRadius (p1 : Vec2d , p2 : Vec2d , radius : Float ): Boolean {
332+ val x = if (p1.x + p2.x > 0 ) p2.x else p1.x
333+ val y = if (p1.y + p2.y > 0 ) p2.y else p1.y
334+ return Vec2d (x, y).length() < radius
335+ }
336+
337+ private fun getChunkPos (x : Int , z : Int , playerOffset : Vec2d , scale : Float ): Vec2d {
338+ return Vec2d ((x shl 4 ).toDouble(), (z shl 4 ).toDouble()).minus(playerOffset).div(scale.toDouble())
339+ }
340+
287341 private fun saveNewChunk (log : PrintWriter ? , data : String ) {
288342 log!! .println (data)
289343 }
0 commit comments