aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-03-10 19:29:33 +0100
committerGitHub <noreply@github.com>2024-03-10 19:29:33 +0100
commit6b19f73c526fc4bbb196b7b547750ebe60feb76d (patch)
treef9a875b184c78916a6c7064edcb35cc3a862749c /src/main/java
parent498afd58e3405d473107e08a3b1891f93f76a96a (diff)
downloadskyhanni-6b19f73c526fc4bbb196b7b547750ebe60feb76d.tar.gz
skyhanni-6b19f73c526fc4bbb196b7b547750ebe60feb76d.tar.bz2
skyhanni-6b19f73c526fc4bbb196b7b547750ebe60feb76d.zip
Debug Feature: Added TrackSoundsCommand (#855)
Co-authored-by: Linnea Gräf <nea@nea.moe> Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/PlaySoundEvent.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt181
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt92
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt2
7 files changed, 113 insertions, 181 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 55b2f94c3..35e86fbb1 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -365,6 +365,7 @@ import at.hannibal2.skyhanni.test.TestExportTools
import at.hannibal2.skyhanni.test.TestShowSlotNumber
import at.hannibal2.skyhanni.test.WorldEdit
import at.hannibal2.skyhanni.test.command.CopyNearbyParticlesCommand
+import at.hannibal2.skyhanni.test.command.TrackSoundsCommand
import at.hannibal2.skyhanni.test.hotswap.HotswapSupport
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.EntityOutlineRenderer
@@ -773,6 +774,7 @@ class SkyHanniMod {
loadModule(SkyHanniDebugsAndTests())
loadModule(FixGhostEntities)
loadModule(CopyNearbyParticlesCommand)
+ loadModule(TrackSoundsCommand)
loadModule(ButtonOnPause())
loadModule(PacketTest)
loadModule(TestBingo)
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index e0a9a74b6..d01a4a8c3 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -69,6 +69,7 @@ import at.hannibal2.skyhanni.test.command.CopyNearbyParticlesCommand
import at.hannibal2.skyhanni.test.command.CopyScoreboardCommand
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.test.command.TestChatCommand
+import at.hannibal2.skyhanni.test.command.TrackSoundsCommand
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -408,6 +409,10 @@ object Commands {
"Copies entities in the specified radius around the player to the clipboard"
) { CopyNearbyEntitiesCommand.command(it) }
registerCommand(
+ "shtracksounds",
+ "Tracks the sounds for the specified duration (in seconds) and copies it to the clipboard"
+ ) { TrackSoundsCommand.command(it) }
+ registerCommand(
"shcopytablist",
"Copies the tab list data to the clipboard"
) { TabListData.copyCommand(it) }
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java
index 927ef8676..480d2955e 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.config.features.dev;
+import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind;
@@ -111,4 +112,7 @@ public class DebugConfig {
@ConfigOption(name = "SkyBlock Area", desc = "Show your current area in SkyBlock while f3 is open.")
@ConfigEditorBoolean
public boolean currentAreaDebug = true;
+
+ @Expose
+ public Position trackSoundPosition = new Position(0, 0);
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/PlaySoundEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/PlaySoundEvent.kt
index 123d5e881..2f793ff28 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/PlaySoundEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/PlaySoundEvent.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.events
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
+import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.LorenzVec
import net.minecraftforge.fml.common.eventhandler.Cancelable
@@ -9,4 +10,11 @@ class PlaySoundEvent(val soundName: String, val location: LorenzVec, val pitch:
LorenzEvent() {
val distanceToPlayer by lazy { location.distanceToPlayer() }
+ override fun toString(): String {
+ return "PlaySoundEvent(soundName='$soundName', pitch=$pitch, volume=$volume, location=${location.round(1)}, distanceToPlayer=${
+ distanceToPlayer.round(
+ 1
+ )
+ })"
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
index c6b734a78..b2b6bccb3 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
@@ -12,7 +12,6 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
-import at.hannibal2.skyhanni.events.PlaySoundEvent
import at.hannibal2.skyhanni.events.ReceiveParticleEvent
import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest
import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames
@@ -501,186 +500,6 @@ class SkyHanniDebugsAndTests {
}
@SubscribeEvent
- fun onSoundPlay(event: PlaySoundEvent) {
-// val location = event.location
-// val distance = location.distanceToPlayer()
-// val soundName = event.soundName
-// val pitch = event.pitch
-// val volume = event.volume
-
- // background music
-// if (soundName == "note.harp") {
-//// if (distance < 2) {
-//
-//
-// //Wilderness
-// val list = mutableListOf<Float>()
-//// list.add(0.4920635)
-//// list.add(0.74603176)
-//// list.add(0.8888889)
-//// list.add(1.1746032)
-//// list.add(1.7777778)
-//// list.add(0.5873016)
-//// list.add(1f)
-//// list.add(1.4920635)
-//// list.add(0.4920635)
-//// list.add(1.8730159)
-//// list.add(0.82539684)
-//// list.add(1.1111112)
-//// list.add(1.6666666)
-//// list.add(0.5555556)
-//// list.add(0.6984127)
-//// list.add(0.93650794)
-//// list.add(1.4126984)
-//// list.add(1.3333334)
-//// list.add(1.5873016)
-//
-// if (pitch in list) {
-// if (Minecraft.getMinecraft().thePlayer.isSneaking) {
-// event.isCanceled = true
-// }
-// return
-// }
-// }
-
- // diana ancestral spade
-// if (soundName == "note.harp") {
-// val list = mutableListOf<Float>()
-// list.add(0.52380955f)
-// list.add(0.5555556f)
-// list.add(0.6031746f)
-// list.add(0.63492066f)
-// list.add(0.6825397f)
-// list.add(0.71428573f)
-// list.add(0.7619048f)
-// list.add(0.7936508f)
-// list.add(0.84126985f)
-// list.add(0.8888889f)
-// list.add(0.9206349f)
-// list.add(0.96825397f)
-// list.add(1.476191f)
-// list.add(1.476191f)
-// list.add(0.50793654f)
-// list.add(0.6507937f)
-// list.add(0.6984127f)
-// list.add(0.74603176f)
-// list.add(0.93650794f)
-// list.add(0.984127f)
-// list.add(1.968254f)
-// list.add(0.4920635f)
-// list.add(1.1587307f)
-// list.add(1.1587301f)
-// list.add(1.2857143f)
-// list.add(1.4126984f)
-// list.add(1.6825397f)
-// list.add(1.8095238f)
-// list.add(1.9365079f)
-// list.add(1.4920635f)
-// list.add(1.5396825f)
-// list.add(0.8730159f)
-// list.add(1.2539682f)
-// list.add(1.4285715f)
-// list.add(1.6190476f)
-// list.add(1.4920635f)
-// list.add(0.9047619f)
-// list.add(1.1111112f)
-// list.add(1.3174603f)
-// list.add(1.5238096f)
-// list.add(1.7301587f)
-//
-// list.add(0.5873016f)
-// list.add(0.61904764f)
-// list.add(0.6666667f)
-// list.add(0.73015875f)
-// list.add(0.7777778f)
-// list.add(0.8095238f)
-// list.add(0.8095238f)
-// list.add(0.82539684f)
-//
-// list.add(0.5714286f)
-// list.add(0.85714287f)
-// list.add(1.3174603f)
-// list.add(1.9523809f)
-// list.add(1.1428572f)
-// list.add(1.2063493f)
-// list.add(1.2698413f)
-// list.add(1.6349206f)
-// list.add(1.2380953f)
-// list.add(1.7936507f)
-// list.add(1.9841269f)
-// list.add(1.1746032f)
-// list.add(1.3492063f)
-// list.add(1.6984127f)
-// list.add(1.8571428f)
-//
-// if (pitch in list) {
-// return
-// }
-// }
-
- // use ancestral spade
-// if (soundName == "mob.zombie.infect") {
-// if (pitch == 1.968254f) {
-// if (volume == 0.3f) {
-// ChatUtils.chat("used ancestral spade!")
-// return
-// }
-// }
-// }
-
- // wither shield activated
-// if (soundName == "mob.zombie.remedy") {
-// if (pitch == 0.6984127f) {
-// if (volume == 1f) {
-// return
-// }
-// }
-// }
-
- // wither shield cooldown over
-// if (soundName == "random.levelup") {
-// if (pitch == 3f) {
-// if (volume == 1f) {
-// return
-// }
-// }
-// }
-
- // teleport (hyp or aote)
-// if (soundName == "mob.endermen.portal") {
-// if (pitch == 1f && volume == 1f) {
-// return
-// }
-// }
-
- // hyp wither impact
-// if (soundName == "random.explode") {
-// if (pitch == 1f && volume == 1f) {
-// return
-// }
-// }
-
- // pick coins up
-// if (soundName == "random.orb") {
-// if (pitch == 1.4920635f && volume == 1f) {
-// return
-// }
-// }
-
-// if (soundName == "game.player.hurt") return
-// if (soundName.startsWith("step.")) return
-
-// if (soundName != "mob.chicken.plop") return
-
-// println("")
-// println("PlaySoundEvent")
-// println("soundName: $soundName")
-// println("distance: $distance")
-// println("pitch: ${pitch}f")
-// println("volume: ${volume}f")
- }
-
- @SubscribeEvent
fun onParticlePlay(event: ReceiveParticleEvent) {
// val particleType = event.type
// val distance = LocationUtils.playerLocation().distance(event.location).round(2)
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt
new file mode 100644
index 000000000..7b0fcddbd
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt
@@ -0,0 +1,92 @@
+package at.hannibal2.skyhanni.test.command
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.PlaySoundEvent
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.util.concurrent.ConcurrentLinkedDeque
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.seconds
+
+object TrackSoundsCommand {
+
+ private var cutOfTime: SimpleTimeMark = SimpleTimeMark.farPast()
+ private var startTime: SimpleTimeMark = SimpleTimeMark.farPast()
+
+ private val sounds = ConcurrentLinkedDeque<Pair<Duration, PlaySoundEvent>>()
+
+ private var isRecording = false
+
+ private val position get() = SkyHanniMod.feature.dev.debug.trackSoundPosition
+
+ private var display: List<Renderable> = emptyList()
+
+ fun command(args: Array<String>) {
+ if (args.firstOrNull() == "end") {
+ if (!isRecording) {
+ ChatUtils.userError("Nothing to end")
+ } else {
+ cutOfTime = SimpleTimeMark.now()
+ }
+ return
+ }
+ if (isRecording) {
+ ChatUtils.userError(
+ "Still tracking sounds, wait for the other tracking to complete before starting a new one, " +
+ "or type §e/shtracksounds end §cto end it prematurely"
+ )
+ return
+ }
+ isRecording = true
+ sounds.clear()
+ startTime = SimpleTimeMark.now()
+ cutOfTime = args.firstOrNull()?.toInt()?.seconds?.let {
+ ChatUtils.chat("Now started tracking sounds for ${it.inWholeSeconds} Seconds")
+ it.fromNow()
+ } ?: run {
+ ChatUtils.chat("Now started tracking sounds until manually ended")
+ SimpleTimeMark.farFuture()
+ }
+ }
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!isRecording) return
+
+ display = sounds.takeWhile { startTime.passedSince() - it.first < 3.0.seconds }
+ .take(10).reversed().map {
+ Renderable.string("§3" + it.second.soundName + " §8p:" + it.second.pitch + " §7v:" + it.second.volume)
+ }
+
+ // The function must run after cutOfTime has passed to ensure thread safety
+ if (cutOfTime.passedSince() <= 0.1.seconds) return
+ val string = sounds.reversed().joinToString("\n") { "Time: ${it.first.inWholeMilliseconds} ${it.second}" }
+ val counter = sounds.size
+ OSUtils.copyToClipboard(string)
+ ChatUtils.chat("$counter sounds copied into the clipboard!")
+ sounds.clear()
+ isRecording = false
+ }
+
+ @SubscribeEvent
+ fun onSoundEvent(event: PlaySoundEvent) {
+ if (cutOfTime.isInPast()) return
+ if (event.soundName == "game.player.hurt" && event.pitch == 0f && event.volume == 0f) return // remove random useless sound
+ if (event.soundName == "") return // sound with empty name aren't useful
+ event.distanceToPlayer // Need to call to initialize Lazy
+ sounds.addFirst(startTime.passedSince() to event)
+ }
+
+ @SubscribeEvent
+ fun onRender(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (cutOfTime.isInPast()) return
+ position.renderRenderables(display, posLabel = "Track sound log")
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt
index 621f2fd5e..784eb85ec 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt
@@ -41,6 +41,8 @@ value class SimpleTimeMark(private val millis: Long) : Comparable<SimpleTimeMark
fun farPast() = SimpleTimeMark(0)
fun farFuture() = SimpleTimeMark(Long.MAX_VALUE)
+ fun Duration.fromNow() = now() + this
+
fun Long.asTimeMark() = SimpleTimeMark(this)
fun SkyBlockTime.asTimeMark() = SimpleTimeMark(toMillis())
}