Skip to content

Commit bbb7649

Browse files
committed
Init MusicTools and added NoteESP
1 parent 4606326 commit bbb7649

7 files changed

Lines changed: 154 additions & 10 deletions

File tree

settings.gradle

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal object ExampleLabelHud: PluginLabelHud(
77
name = "ExampleLabelHud",
88
category = Category.MISC,
99
description = "Simple hud example",
10-
pluginMain = ExamplePlugin
10+
pluginMain = MusicToolsPlugin
1111
) {
1212
private val prefix by setting("Prefix", "Hello")
1313
private val suffix by setting("Suffix", "World")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal object ExampleModule: PluginModule(
1414
name = "ExampleModule",
1515
category = Category.MISC,
1616
description = "Example module which mounts entities using packets",
17-
pluginMain = ExamplePlugin
17+
pluginMain = MusicToolsPlugin
1818
) {
1919
private val maxReach by setting("Max Reach", 4.9f, 0.0f..8.0f, 0.1f, description = "Player's Max Reach")
2020
private val mountEntity = setting("Mount Entity", false, description = "Mounts the saved entity or falls back to the closest one")

src/main/kotlin/org/lambda/ExamplePlugin.kt renamed to src/main/kotlin/org/lambda/MusicToolsPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package org.lambda
22

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

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

77
override fun onLoad() {
88
// Load any modules, commands, or HUD elements here
9-
modules.add(ExampleModule)
9+
modules.add(NoteESP)
1010
commands.add(ExampleCommand)
1111
hudElements.add(ExampleLabelHud)
1212
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.lambda
2+
3+
import com.lambda.client.event.events.PacketEvent
4+
import com.lambda.client.event.events.RenderOverlayEvent
5+
import com.lambda.client.event.events.RenderWorldEvent
6+
import com.lambda.client.module.Category
7+
import com.lambda.client.plugin.api.PluginModule
8+
import com.lambda.client.util.graphics.ESPRenderer
9+
import com.lambda.client.util.graphics.GlStateUtils
10+
import com.lambda.client.util.graphics.ProjectionUtils
11+
import com.lambda.client.util.graphics.font.FontRenderAdapter
12+
import com.lambda.client.util.math.CoordinateConverter.asString
13+
import com.lambda.client.util.math.VectorUtils.toVec3dCenter
14+
import com.lambda.client.util.text.MessageSendHelper
15+
import com.lambda.event.listener.listener
16+
import net.minecraft.init.SoundEvents
17+
import net.minecraft.network.play.server.SPacketSoundEffect
18+
import net.minecraft.util.SoundEvent
19+
import net.minecraft.util.math.BlockPos
20+
import net.minecraftforge.event.world.NoteBlockEvent
21+
import org.lambda.util.Note
22+
import org.lwjgl.opengl.GL11
23+
import java.util.concurrent.ConcurrentHashMap
24+
import kotlin.math.log2
25+
import kotlin.math.roundToInt
26+
27+
internal object NoteESP: PluginModule(
28+
name = "NoteESP",
29+
category = Category.RENDER,
30+
description = "Shows note block pitch",
31+
pluginMain = MusicToolsPlugin
32+
) {
33+
private val filled by setting("Filled", true, description = "Renders surfaces")
34+
private val outline by setting("Outline", true, description = "Renders outline")
35+
private val alphaFilled by setting("Alpha Filled", 26, 0..255, 1, { filled }, description = "Alpha for surfaces")
36+
private val alphaOutline by setting("Alpha Outline", 26, 0..255, 1, { outline }, description = "Alpha for outline")
37+
private val thickness by setting("Outline Thickness", 2f, .25f..4f, .25f, { outline })
38+
private val textScale by setting("Text Scale", 1f, .0f..4f, .25f)
39+
private val reset = setting("Reset", false, description = "Resets cached notes")
40+
private val debug by setting("Debug", false, description = "Debug messages in chat")
41+
42+
private val cachedNotes = ConcurrentHashMap<BlockPos, Note>()
43+
private val renderer = ESPRenderer()
44+
45+
init {
46+
reset.consumers.add { _, it ->
47+
if (it) {
48+
cachedNotes.clear()
49+
}
50+
false
51+
}
52+
53+
listener<PacketEvent.Receive> { event ->
54+
if (event.packet is SPacketSoundEffect) {
55+
val packet = (event.packet as SPacketSoundEffect)
56+
57+
val instrument = getInstrument(packet.sound) ?: return@listener
58+
val pos = BlockPos(packet.x, packet.y, packet.z)
59+
val note = Note.values()[(log2(packet.pitch.toDouble()) * 12.0).roundToInt() + 12]
60+
61+
cachedNotes[pos] = note
62+
63+
if (debug) {
64+
MessageSendHelper.sendChatMessage("Instrument: ${instrument.name} Pos: (${packet.x},${packet.y},${packet.z}) Pitch: ${note.name}")
65+
}
66+
}
67+
}
68+
69+
listener<RenderWorldEvent> {
70+
renderer.aFilled = if (filled) alphaFilled else 0
71+
renderer.aOutline = if (outline) alphaOutline else 0
72+
renderer.thickness = thickness
73+
74+
cachedNotes.forEach {
75+
renderer.add(it.key, it.value.color)
76+
}
77+
78+
renderer.render(true)
79+
}
80+
81+
listener<RenderOverlayEvent> {
82+
GlStateUtils.rescaleActual()
83+
84+
cachedNotes.forEach {
85+
GL11.glPushMatrix()
86+
87+
val screenPos = ProjectionUtils.toScreenPos(it.key.toVec3dCenter())
88+
89+
GL11.glTranslated(screenPos.x, screenPos.y, 0.0)
90+
GL11.glScalef(textScale * 2f, textScale * 2f, 1f)
91+
92+
val center = FontRenderAdapter.getStringWidth(it.value.ordinal.toString()) / -2f
93+
FontRenderAdapter.drawString(it.value.ordinal.toString(), center, 0f, color = it.value.color)
94+
95+
GL11.glPopMatrix()
96+
}
97+
}
98+
}
99+
100+
private fun getInstrument(soundEvent: SoundEvent): NoteBlockEvent.Instrument? {
101+
return when (soundEvent) {
102+
SoundEvents.BLOCK_NOTE_HARP -> NoteBlockEvent.Instrument.PIANO
103+
SoundEvents.BLOCK_NOTE_BASEDRUM -> NoteBlockEvent.Instrument.BASSDRUM
104+
SoundEvents.BLOCK_NOTE_SNARE -> NoteBlockEvent.Instrument.SNARE
105+
SoundEvents.BLOCK_NOTE_HAT -> NoteBlockEvent.Instrument.CLICKS
106+
SoundEvents.BLOCK_NOTE_BASS -> NoteBlockEvent.Instrument.BASSGUITAR
107+
SoundEvents.BLOCK_NOTE_FLUTE -> NoteBlockEvent.Instrument.FLUTE
108+
SoundEvents.BLOCK_NOTE_BELL -> NoteBlockEvent.Instrument.BELL
109+
SoundEvents.BLOCK_NOTE_GUITAR -> NoteBlockEvent.Instrument.GUITAR
110+
SoundEvents.BLOCK_NOTE_CHIME -> NoteBlockEvent.Instrument.CHIME
111+
SoundEvents.BLOCK_NOTE_XYLOPHONE -> NoteBlockEvent.Instrument.XYLOPHONE
112+
else -> null
113+
}
114+
}
115+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.lambda.util
2+
3+
import com.lambda.client.util.color.ColorHolder
4+
5+
enum class Note(val color: 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+
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
2-
"name": "ExamplePlugin",
2+
"name": "MusicTools",
33
"version": "1.0",
44
"authors": [
5-
"me",
6-
"you"
5+
"EnigmA_008"
76
],
8-
"description": "Example implementation of a plugin for Lambda.",
7+
"description": "Helps with note block stuff.",
98
"url": "",
109
"min_api_version": "3.0",
1110
"required_plugins": [],
12-
"main_class": "ExamplePlugin",
11+
"main_class": "org.lambda.MusicToolsPlugin",
1312
"hot_reload": true
1413
}

0 commit comments

Comments
 (0)