Skip to content

Commit 0befec9

Browse files
committed
Added ColorScheme, instrument overlay, range and fixed block selection
1 parent bdf03d4 commit 0befec9

File tree

7 files changed

+70
-103
lines changed

7 files changed

+70
-103
lines changed

src/main/kotlin/org/lambda/ExampleCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.lambda.client.command.ClientCommand
44
import com.lambda.client.manager.managers.FriendManager
55
import com.lambda.client.util.text.MessageSendHelper
66

7-
object ExampleCommand: ClientCommand(
7+
object ExampleCommand : ClientCommand(
88
name = "example",
99
description = "Example friend command"
1010
) {

src/main/kotlin/org/lambda/ExampleLabelHud.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.lambda
33
import com.lambda.client.event.SafeClientEvent
44
import com.lambda.client.plugin.api.PluginLabelHud
55

6-
internal object ExampleLabelHud: PluginLabelHud(
6+
internal object ExampleLabelHud : PluginLabelHud(
77
name = "ExampleLabelHud",
88
category = Category.MISC,
99
description = "Simple hud example",

src/main/kotlin/org/lambda/ExampleModule.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import net.minecraft.entity.Entity
1010
import net.minecraft.network.play.client.CPacketUseEntity
1111
import net.minecraft.util.EnumHand
1212

13-
internal object ExampleModule: PluginModule(
13+
internal object ExampleModule : PluginModule(
1414
name = "ExampleModule",
1515
category = Category.MISC,
1616
description = "Example module which mounts entities using packets",
@@ -58,15 +58,15 @@ internal object ExampleModule: PluginModule(
5858
it != player.ridingEntity
5959
}.minByOrNull {
6060
player.getDistanceSq(it)
61-
} ?.let {
61+
}?.let {
6262
if (maxReach == 0.0f || player.getDistance(it) <= maxReach) {
6363
sendChatMessage("$chatName Mounting: ${it.name}@${it.positionVector}")
6464
connection.sendPacket(CPacketUseEntity(it, EnumHand.MAIN_HAND))
6565
} else {
6666
sendChatMessage("$chatName Closest entity too far away: ${it.name}@${it.positionVector.distanceTo(player.positionVector)}")
6767
}
6868
} ?: run {
69-
sendChatMessage("$chatName Can't find any Entity in world.")
70-
}
69+
sendChatMessage("$chatName Can't find any Entity in world.")
70+
}
7171
}
7272
}

src/main/kotlin/org/lambda/MusicToolsPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.lambda
22

33
import com.lambda.client.plugin.api.Plugin
44

5-
internal object MusicToolsPlugin: Plugin() {
5+
internal object MusicToolsPlugin : Plugin() {
66

77
override fun onLoad() {
88
// Load any modules, commands, or HUD elements here

src/main/kotlin/org/lambda/NoteESP.kt

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,35 @@ import com.lambda.client.event.events.PacketEvent
44
import com.lambda.client.event.events.RenderOverlayEvent
55
import com.lambda.client.event.events.RenderWorldEvent
66
import com.lambda.client.module.Category
7-
import com.lambda.client.module.modules.render.Search
8-
import com.lambda.client.module.modules.render.Search.setting
97
import com.lambda.client.plugin.api.PluginModule
108
import com.lambda.client.util.graphics.ESPRenderer
119
import com.lambda.client.util.graphics.GlStateUtils
1210
import com.lambda.client.util.graphics.ProjectionUtils
1311
import com.lambda.client.util.graphics.font.FontRenderAdapter
1412
import com.lambda.client.util.math.CoordinateConverter.asString
15-
import com.lambda.client.util.math.VectorUtils.distanceTo
13+
import com.lambda.client.util.math.VectorUtils.toVec3d
1614
import com.lambda.client.util.math.VectorUtils.toVec3dCenter
1715
import com.lambda.client.util.text.MessageSendHelper
16+
import com.lambda.client.util.threads.safeListener
1817
import com.lambda.event.listener.listener
19-
import net.minecraft.block.state.IBlockState
20-
import net.minecraft.init.Blocks
21-
import net.minecraft.init.SoundEvents
18+
import net.minecraft.block.BlockNote
2219
import net.minecraft.network.play.server.SPacketBlockAction
23-
import net.minecraft.network.play.server.SPacketSoundEffect
24-
import net.minecraft.util.SoundEvent
2520
import net.minecraft.util.math.BlockPos
26-
import net.minecraft.util.math.Vec3d
27-
import net.minecraft.world.chunk.Chunk
2821
import net.minecraftforge.event.world.NoteBlockEvent
22+
import org.lambda.ExampleLabelHud.updateText
2923
import org.lambda.util.Note
3024
import org.lwjgl.opengl.GL11
31-
import java.awt.Color
3225
import java.util.concurrent.ConcurrentHashMap
33-
import javax.sound.midi.Instrument
34-
import kotlin.math.log2
35-
import kotlin.math.roundToInt
3626

37-
internal object NoteESP: PluginModule(
27+
internal object NoteESP : PluginModule(
3828
name = "NoteESP",
3929
category = Category.RENDER,
4030
description = "Shows note block pitch",
4131
pluginMain = MusicToolsPlugin
4232
)
4333

44-
//TODO: no listener for non note blocks > i already did that? i dont see where
4534
//TODO: render only for own y to own y - 2 > vague ideas, but i have no idea how
4635
//TODO: range for rendering > found something in the search module but have no idea how to adapt this
47-
//TODO: 1.12.2 color mode of the rendering > no idea how to tell him to use the default colors
48-
//TODO: add instrument to rendering > no idea how. do i need another concurrenthashmap for that? i at least managed to render a second line on the block
4936
//TODO: remove rendering when block is broken > no idea how to check regularly if the block is still there
5037

5138
{
@@ -60,73 +47,78 @@ internal object NoteESP: PluginModule(
6047
private val reset = setting("Reset", false, description = "Resets cached notes")
6148
private val debug by setting("Debug", false, description = "Debug messages in chat")
6249

63-
private val cachedNotes = ConcurrentHashMap<BlockPos, Note>()
50+
private val cachedMusicData = ConcurrentHashMap<BlockPos, MusicData>()
6451
private val renderer = ESPRenderer()
6552

6653
enum class ColorScheme {
6754
DEFAULT, RAINBOW
6855
}
56+
6957
// reset button
7058
init {
7159
reset.consumers.add { _, it ->
7260
if (it) {
73-
cachedNotes.clear()
61+
cachedMusicData.clear()
7462
}
7563
false
7664
}
65+
7766
//listens to played note block
78-
listener<PacketEvent.Receive> { event ->
67+
safeListener<PacketEvent.Receive> { event ->
7968
if (event.packet is SPacketBlockAction) {
8069
val packet = (event.packet as SPacketBlockAction)
8170

82-
val instrument = NoteBlockEvent.Instrument.values()[packet.data1]
83-
val note = Note.values()[packet.data2]
71+
if (world.getBlockState(packet.blockPosition).block is BlockNote) {
72+
val instrument = NoteBlockEvent.Instrument.values()[packet.data1]
73+
val note = Note.values()[packet.data2]
8474

85-
cachedNotes[packet.blockPosition] = note
75+
cachedMusicData[packet.blockPosition] = MusicData(note, instrument)
8676

87-
if (debug) {
88-
MessageSendHelper.sendChatMessage("Instrument: ${instrument.name} Pos: (${packet.blockPosition.asString()}) Pitch: ${note.name}")
77+
if (debug) {
78+
MessageSendHelper.sendChatMessage("Instrument: ${instrument.name} Pos: (${packet.blockPosition.asString()}) Pitch: ${note.name}")
79+
}
8980
}
9081
}
9182
}
9283

9384
//renders box
94-
listener<RenderWorldEvent> {
85+
safeListener<RenderWorldEvent> {
9586
renderer.aFilled = if (filled) alphaFilled else 0
9687
renderer.aOutline = if (outline) alphaOutline else 0
9788
renderer.thickness = thickness
9889

99-
cachedNotes.forEach {
100-
// when(colorScheme){
101-
// ColorScheme.DEFAULT -> {
102-
// renderer.add(it.key, it.value.default)
103-
// }
104-
// ColorScheme.RAINBOW -> {
105-
renderer.add(it.key, it.value.rainbow)
106-
// }
107-
// }
90+
cachedMusicData.forEach {
91+
if (player.getPositionEyes(1f).distanceTo(it.key.toVec3dCenter()) < range) {
92+
renderer.add(it.key, it.value.color)
93+
}
10894
}
10995
renderer.render(true)
11096
}
97+
11198
//renders text overlay
11299
listener<RenderOverlayEvent> {
113100
GlStateUtils.rescaleActual()
114101

115-
cachedNotes.forEach {
102+
cachedMusicData.forEach {
116103
GL11.glPushMatrix()
117104

118105
val screenPos = ProjectionUtils.toScreenPos(it.key.toVec3dCenter())
119106

120107
GL11.glTranslated(screenPos.x, screenPos.y, 0.0)
121108
GL11.glScalef(textScale * 2f, textScale * 2f, 1f)
122109

123-
val centerValue = FontRenderAdapter.getStringWidth(it.value.ordinal.toString()) / -2f
124-
val centerKey = FontRenderAdapter.getStringWidth(it.key.toString()) / -2f
125-
FontRenderAdapter.drawString(it.value.ordinal.toString(), centerValue, 0f, color = it.value.rainbow)
126-
FontRenderAdapter.drawString(it.key.toString(), centerKey, +10f, color = it.value.rainbow)
110+
val centerValue = FontRenderAdapter.getStringWidth(it.value.note.ordinal.toString()) / -2f
111+
val centerKey = FontRenderAdapter.getStringWidth(it.value.instrument.name) / -2f
112+
113+
FontRenderAdapter.drawString(it.value.note.ordinal.toString(), centerValue, 0f, color = it.value.color)
114+
FontRenderAdapter.drawString(it.value.instrument.name, centerKey, FontRenderAdapter.getFontHeight(), color = it.value.color)
127115

128116
GL11.glPopMatrix()
129117
}
130118
}
131119
}
120+
121+
private class MusicData(val note: Note, val instrument: NoteBlockEvent.Instrument) {
122+
val color = if (colorScheme == ColorScheme.DEFAULT) note.default else note.rainbow
123+
}
132124
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package org.lambda.util
2+
3+
enum class Instrument

src/main/kotlin/org/lambda/util/Note.kt

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,30 @@ package org.lambda.util
22

33
import com.lambda.client.util.color.ColorHolder
44

5-
enum class Note(val rainbow: ColorHolder) {
6-
F_SHARP_LOW(ColorHolder(119, 215, 0)),
7-
G_LOW(ColorHolder(149, 192, 0)),
8-
G_SHARP_LOW(ColorHolder(178, 165, 0)),
9-
A_LOW(ColorHolder(204, 134, 0)),
10-
A_SHARP_LOW(ColorHolder(226, 101, 0)),
11-
B_LOW(ColorHolder(243, 65, 0)),
12-
C_LOW(ColorHolder(252, 30, 0)),
13-
C_SHARP_LOW(ColorHolder(254, 0, 15)),
14-
D_LOW(ColorHolder(247, 0, 51)),
15-
D_SHARP_LOW(ColorHolder(232, 0, 90)),
16-
E_LOW(ColorHolder(207, 0, 131)),
17-
F_LOW(ColorHolder(174, 0, 169)),
18-
F_SHARP_HIGH(ColorHolder(134, 0, 204)),
19-
G_HIGH(ColorHolder(91, 0, 231)),
20-
G_SHARP_HIGH(ColorHolder(45, 0, 249)),
21-
A_HIGH(ColorHolder(2, 10, 254)),
22-
A_SHARP_HIGH(ColorHolder(0, 55, 246)),
23-
B_HIGH(ColorHolder(0, 104, 224)),
24-
C_HIGH(ColorHolder(0, 154, 188)),
25-
C_SHARP_HIGH(ColorHolder(0, 198, 141)),
26-
D_HIGH(ColorHolder(0, 233, 88)),
27-
D_SHARP_HIGH(ColorHolder(0, 252, 33)),
28-
E_HIGH(ColorHolder(31, 252, 0)),
29-
F_HIGH(ColorHolder(89, 232, 0)),
30-
F_SHARP_SUPER_HIGH(ColorHolder(148, 193, 0))
31-
}
32-
33-
//enum class Note(val default: ColorHolder) {
34-
// F_SHARP_LOW(ColorHolder(85, 221, 192)),
35-
// G_LOW(ColorHolder(126, 196, 177)),
36-
// G_SHARP_LOW(ColorHolder(164, 164, 171)),
37-
// A_LOW(ColorHolder(196, 126, 177)),
38-
// A_SHARP_LOW(ColorHolder(221, 85, 192)),
39-
// B_LOW(ColorHolder(237, 44, 218)),
40-
// C_LOW(ColorHolder(243, 6, 6)),
41-
// C_SHARP_LOW(ColorHolder(237, 218, 44)),
42-
// D_LOW(ColorHolder(221, 192, 85)),
43-
// D_SHARP_LOW(ColorHolder(196, 177, 126)),
44-
// E_LOW(ColorHolder(164, 171, 164)),
45-
// F_LOW(ColorHolder(126, 177, 196)),
46-
// F_SHARP_HIGH(ColorHolder(85, 192, 221)),
47-
// G_HIGH(ColorHolder(44, 218, 237)),
48-
// G_SHARP_HIGH(ColorHolder(6, 6, 243)),
49-
// A_HIGH(ColorHolder(218, 44, 237)),
50-
// A_SHARP_HIGH(ColorHolder(192, 85, 221)),
51-
// B_HIGH(ColorHolder(177, 126, 196)),
52-
// C_HIGH(ColorHolder(171, 164, 164)),
53-
// C_SHARP_HIGH(ColorHolder(177, 196, 126)),
54-
// D_HIGH(ColorHolder(192, 221, 85)),
55-
// D_SHARP_HIGH(ColorHolder(218, 237, 44)),
56-
// E_HIGH(ColorHolder(6, 243, 6)),
57-
// F_HIGH(ColorHolder(44, 237, 218)),
58-
// F_SHARP_SUPER_HIGH(ColorHolder(85, 221, 192))
59-
//}
5+
enum class Note(val default: ColorHolder, val rainbow: ColorHolder) {
6+
F_SHARP_LOW(ColorHolder(85, 221, 192), ColorHolder(119, 215, 0)),
7+
G_LOW(ColorHolder(126, 196, 177), ColorHolder(149, 192, 0)),
8+
G_SHARP_LOW(ColorHolder(164, 164, 171), ColorHolder(178, 165, 0)),
9+
A_LOW(ColorHolder(196, 126, 177), ColorHolder(204, 134, 0)),
10+
A_SHARP_LOW(ColorHolder(221, 85, 192), ColorHolder(226, 101, 0)),
11+
B_LOW(ColorHolder(237, 44, 218), ColorHolder(243, 65, 0)),
12+
C_LOW(ColorHolder(243, 6, 6), ColorHolder(252, 30, 0)),
13+
C_SHARP_LOW(ColorHolder(237, 218, 44), ColorHolder(254, 0, 15)),
14+
D_LOW(ColorHolder(221, 192, 85), ColorHolder(247, 0, 51)),
15+
D_SHARP_LOW(ColorHolder(196, 177, 126), ColorHolder(232, 0, 90)),
16+
E_LOW(ColorHolder(164, 171, 164), ColorHolder(207, 0, 131)),
17+
F_LOW(ColorHolder(126, 177, 196), ColorHolder(174, 0, 169)),
18+
F_SHARP_HIGH(ColorHolder(85, 192, 221), ColorHolder(134, 0, 204)),
19+
G_HIGH(ColorHolder(44, 218, 237), ColorHolder(91, 0, 231)),
20+
G_SHARP_HIGH(ColorHolder(6, 6, 243), ColorHolder(45, 0, 249)),
21+
A_HIGH(ColorHolder(218, 44, 237), ColorHolder(2, 10, 254)),
22+
A_SHARP_HIGH(ColorHolder(192, 85, 221), ColorHolder(0, 55, 246)),
23+
B_HIGH(ColorHolder(177, 126, 196), ColorHolder(0, 104, 224)),
24+
C_HIGH(ColorHolder(171, 164, 164), ColorHolder(0, 154, 188)),
25+
C_SHARP_HIGH(ColorHolder(177, 196, 126), ColorHolder(0, 198, 141)),
26+
D_HIGH(ColorHolder(192, 221, 85), ColorHolder(0, 233, 88)),
27+
D_SHARP_HIGH(ColorHolder(218, 237, 44), ColorHolder(0, 252, 33)),
28+
E_HIGH(ColorHolder(6, 243, 6), ColorHolder(31, 252, 0)),
29+
F_HIGH(ColorHolder(44, 237, 218), ColorHolder(89, 232, 0)),
30+
F_SHARP_SUPER_HIGH(ColorHolder(85, 221, 192), ColorHolder(148, 193, 0))
31+
}

0 commit comments

Comments
 (0)