@@ -4,7 +4,6 @@ import com.lambda.client.event.events.PacketEvent
44import com.lambda.client.event.events.RenderOverlayEvent
55import com.lambda.client.event.events.RenderWorldEvent
66import com.lambda.client.module.Category
7- import com.lambda.client.module.modules.render.StorageESP
87import com.lambda.client.plugin.api.PluginModule
98import com.lambda.client.util.TickTimer
109import com.lambda.client.util.graphics.ESPRenderer
@@ -14,15 +13,20 @@ import com.lambda.client.util.graphics.font.FontRenderAdapter
1413import com.lambda.client.util.math.CoordinateConverter.asString
1514import com.lambda.client.util.math.VectorUtils.toVec3dCenter
1615import com.lambda.client.util.text.MessageSendHelper
16+ import com.lambda.client.util.threads.defaultScope
17+ import com.lambda.client.util.threads.runSafe
1718import com.lambda.client.util.threads.safeListener
19+ import kotlinx.coroutines.launch
1820import net.minecraft.block.BlockNote
1921import net.minecraft.network.play.server.SPacketBlockAction
2022import net.minecraft.util.math.BlockPos
2123import net.minecraftforge.event.world.NoteBlockEvent
24+ import net.minecraftforge.fml.common.gameevent.TickEvent
2225import org.lambda.util.Note
2326import org.lwjgl.opengl.GL11
2427import java.util.*
2528import java.util.concurrent.ConcurrentHashMap
29+ import kotlin.coroutines.coroutineContext
2630
2731internal object NoteESP : PluginModule(
2832 name = " NoteESP" ,
@@ -31,15 +35,13 @@ internal object NoteESP : PluginModule(
3135 pluginMain = MusicToolsPlugin
3236)
3337
34- // TODO: remove rendering when block is broken
35-
3638{
3739 private val page by setting(" Page" , Page .SETTINGS )
3840
39- private val boxRange by setting(" Render Range for box" , 32 , 0 .. 265 , 4 , { (renderMode == RenderMode . RANGE || renderMode == RenderMode . TUNINGMODE ) && page == Page .SETTINGS }, description = " Range for Rendering of the box" )
40- private val textRange by setting(" Render Range for text " , 32 , 0 .. 256 , 4 , { (renderMode == RenderMode . RANGE || renderMode == RenderMode . TUNINGMODE ) && page == Page .SETTINGS }, description = " Range for Rendering of the text" )
41- private val renderMode by setting(" Rendering " , RenderMode . RANGE , { page == Page .SETTINGS }, description = " Changes Render Mode " )
42- private val tuningRange by setting(" Tuning Range" , 2 , 2 .. 6 , 1 , { renderMode == RenderMode . TUNINGMODE && page == Page .SETTINGS }, description = " Rendering for Y Level below feet" )
41+ private val boxRange by setting(" Render Range for box" , 32 , 0 .. 265 , 4 , { page == Page .SETTINGS }, description = " Range for Rendering of the box" )
42+ private val textRange by setting(" Render Range for text" , 32 , 0 .. 256 , 4 , { page == Page .SETTINGS }, description = " Range for Rendering of the text" )
43+ private val tuning by setting(" Tuning Mode " , false , { page == Page .SETTINGS }, description = " Selectively renders only relevant layers " )
44+ private val tuningRange by setting(" Tuning Range" , 2 , 2 .. 6 , 1 , { tuning && page == Page .SETTINGS }, description = " Rendering for Y Level below feet" )
4345 private val reset = setting(" Reset" , false , { page == Page .SETTINGS }, description = " Resets cached notes" )
4446 private val debug by setting(" Debug" , false , { page == Page .SETTINGS }, description = " Debug messages in chat" )
4547
@@ -53,8 +55,8 @@ internal object NoteESP : PluginModule(
5355
5456 private val cachedMusicData = ConcurrentHashMap <BlockPos , MusicData >()
5557 private val renderer = ESPRenderer ()
56- // private val updateTimer = TickTimer()
57- // private const val updateDelay = 1000
58+ private val updateTimer = TickTimer ()
59+ private const val updateDelay = 1000L
5860
5961 private enum class Page {
6062 SETTINGS , RENDER
@@ -64,10 +66,6 @@ internal object NoteESP : PluginModule(
6466 DEFAULT , RAINBOW
6567 }
6668
67- enum class RenderMode {
68- RANGE , TUNINGMODE
69- }
70-
7169 // reset button
7270 init {
7371 reset.consumers.add { _, it ->
@@ -95,79 +93,61 @@ internal object NoteESP : PluginModule(
9593 }
9694 }
9795
96+ safeListener<TickEvent .ClientTickEvent > { event ->
97+ if (event.phase != TickEvent .Phase .START || ! updateTimer.tick(updateDelay)) return @safeListener
98+ defaultScope.launch {
99+ runSafe {
100+ cachedMusicData
101+ .filter { world.getBlockState(it.key).block !is BlockNote }
102+ .forEach { cachedMusicData.remove(it.key) }
103+ }
104+ }
105+ }
106+
98107 // renders box
99108 safeListener<RenderWorldEvent > {
100109 renderer.aFilled = if (filled) alphaFilled else 0
101110 renderer.aOutline = if (outline) alphaOutline else 0
102111 renderer.thickness = thickness
103112
104- cachedMusicData.forEach {
105- if (renderMode == RenderMode .RANGE ) {
106- if (player.getPositionEyes(1f ).distanceTo(it.key.toVec3dCenter()) < boxRange) {
107- renderer.add(it.key, it.value.color)
108- }
109- }
110- if (renderMode == RenderMode .TUNINGMODE ) {
111- if ((it.key.y > player.getPositionEyes(1f ).y.toInt() - tuningRange - 2 ) &&
112- (player.getPositionEyes(1f ).distanceTo(it.key.toVec3dCenter()) < boxRange)) {
113- renderer.add(it.key, it.value.color)
114- }
115- }
113+ var renderData = cachedMusicData.filter { player.positionVector.distanceTo(it.key.toVec3dCenter()) < boxRange }
114+
115+ if (tuning) {
116+ renderData = renderData.filter { it.key.y > player.posY - tuningRange }
116117 }
118+
119+ renderData.forEach { renderer.add(it.key, it.value.color) }
120+
117121 renderer.render(true )
118122 }
119123
120124 // renders text overlay
121125 safeListener<RenderOverlayEvent > {
122126 GlStateUtils .rescaleActual()
123127
124- cachedMusicData.forEach { it ->
125- if (renderMode == RenderMode .RANGE ) {
126- if (player.getPositionEyes(1f ).distanceTo(it.key.toVec3dCenter()) < textRange) {
127- GL11 .glPushMatrix()
128-
129- val screenPos = ProjectionUtils .toScreenPos(it.key.toVec3dCenter())
130-
131- GL11 .glTranslated(screenPos.x, screenPos.y, 0.0 )
132- GL11 .glScalef(textScale * 2f , textScale * 2f , 1f )
133-
134- val centerValue = FontRenderAdapter .getStringWidth(it.value.note.ordinal.toString()) / - 2f
135- val centerKey = FontRenderAdapter .getStringWidth(it.value.instrument.name) / - 2f
128+ var renderData = cachedMusicData.filter { player.positionVector.distanceTo(it.key.toVec3dCenter()) < textRange }
136129
137- FontRenderAdapter .drawString(it.value.note.ordinal.toString(), centerValue, 0f , color = it.value.color)
138- FontRenderAdapter .drawString(it.value.instrument.name.lowercase().replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale .getDefault()) else it.toString() }, centerKey, FontRenderAdapter .getFontHeight(), color = it.value.color)
130+ if (tuning) {
131+ renderData = renderData.filter { it.key.y > player.posY - tuningRange }
132+ }
139133
140- GL11 .glPopMatrix()
141- }
142- }
143- if (renderMode == RenderMode .TUNINGMODE ) {
144- if ((it.key.y > player.getPositionEyes(1f ).y.toInt() - tuningRange - 2 ) &&
145- (player.getPositionEyes(1f ).distanceTo(it.key.toVec3dCenter()) < boxRange)) {
146- GL11 .glPushMatrix()
134+ renderData.forEach { musicDataEntry ->
135+ GL11 .glPushMatrix()
147136
148- val screenPos = ProjectionUtils .toScreenPos(it .key.toVec3dCenter())
137+ val screenPos = ProjectionUtils .toScreenPos(musicDataEntry .key.toVec3dCenter())
149138
150- GL11 .glTranslated(screenPos.x, screenPos.y, 0.0 )
151- GL11 .glScalef(textScale * 2f , textScale * 2f , 1f )
139+ GL11 .glTranslated(screenPos.x, screenPos.y, 0.0 )
140+ GL11 .glScalef(textScale * 2f , textScale * 2f , 1f )
152141
153- val centerValue = FontRenderAdapter .getStringWidth(it .value.note.ordinal.toString()) / - 2f
154- val centerKey = FontRenderAdapter .getStringWidth(it .value.instrument.name) / - 2f
142+ val centerValue = FontRenderAdapter .getStringWidth(musicDataEntry .value.note.ordinal.toString()) / - 2f
143+ val centerKey = FontRenderAdapter .getStringWidth(musicDataEntry .value.instrument.name) / - 2f
155144
156- FontRenderAdapter .drawString(it .value.note.ordinal.toString(), centerValue, 0f , color = it .value.color)
157- FontRenderAdapter .drawString(it .value.instrument.name.lowercase().replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale .getDefault()) else it.toString() }, centerKey, FontRenderAdapter .getFontHeight(), color = it .value.color)
145+ FontRenderAdapter .drawString(musicDataEntry .value.note.ordinal.toString(), centerValue, 0f , color = musicDataEntry .value.color)
146+ FontRenderAdapter .drawString(musicDataEntry .value.instrument.name.lowercase().replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }, centerKey, FontRenderAdapter .getFontHeight(), color = musicDataEntry .value.color)
158147
159- GL11 .glPopMatrix()
160- }
161- }
148+ GL11 .glPopMatrix()
162149 }
163150 }
164- // safeListener<RenderWorldEvent> {
165- // renderer.render(false)
166- //
167- // if (updateTimer.tick(updateDelay.toLong())) {
168- // updateRenderer()
169- // }
170- // }
171151 }
172152
173153 private class MusicData (val note : Note , val instrument : NoteBlockEvent .Instrument ) {
0 commit comments