diff options
author | Linnea Gräf <nea@nea.moe> | 2025-06-08 01:16:20 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-06-08 01:16:44 +0200 |
commit | af57636ae0a674a11318e95c797218f18f768421 (patch) | |
tree | 38d759c977cdf5ff5093745cc7e2186f2fad258f /src/main/kotlin/features/debug/SoundVisualizer.kt | |
parent | fc4874d1e353e2f5f8c91ebf8a6584b3e70c9f9c (diff) | |
download | Firmament-master.tar.gz Firmament-master.tar.bz2 Firmament-master.zip |
Diffstat (limited to 'src/main/kotlin/features/debug/SoundVisualizer.kt')
-rw-r--r-- | src/main/kotlin/features/debug/SoundVisualizer.kt | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/kotlin/features/debug/SoundVisualizer.kt b/src/main/kotlin/features/debug/SoundVisualizer.kt new file mode 100644 index 0000000..cc14122 --- /dev/null +++ b/src/main/kotlin/features/debug/SoundVisualizer.kt @@ -0,0 +1,65 @@ +package moe.nea.firmament.features.debug + +import net.minecraft.text.Text +import moe.nea.firmament.annotations.Subscribe +import moe.nea.firmament.commands.thenExecute +import moe.nea.firmament.commands.thenLiteral +import moe.nea.firmament.events.CommandEvent +import moe.nea.firmament.events.SoundReceiveEvent +import moe.nea.firmament.events.WorldReadyEvent +import moe.nea.firmament.events.WorldRenderLastEvent +import moe.nea.firmament.util.red +import moe.nea.firmament.util.render.RenderInWorldContext + +object SoundVisualizer { + + var showSounds = false + + var sounds = mutableListOf<SoundReceiveEvent>() + + + @Subscribe + fun onSubCommand(event: CommandEvent.SubCommand) { + event.subcommand("dev") { + thenLiteral("sounds") { + thenExecute { + showSounds = !showSounds + if (!showSounds) { + sounds.clear() + } + } + } + } + } + + @Subscribe + fun onWorldSwap(event: WorldReadyEvent) { + sounds.clear() + } + + @Subscribe + fun onRender(event: WorldRenderLastEvent) { + RenderInWorldContext.renderInWorld(event) { + sounds.forEach { event -> + withFacingThePlayer(event.position) { + text( + Text.literal(event.sound.value().id.toString()).also { + if (event.cancelled) + it.red() + }, + verticalAlign = RenderInWorldContext.VerticalAlign.CENTER, + ) + } + } + } + } + + @Subscribe + fun onSoundReceive(event: SoundReceiveEvent) { + if (!showSounds) return + if (sounds.size > 1000) { + sounds.subList(0, 200).clear() + } + sounds.add(event) + } +} |