diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-05-26 21:49:16 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-26 13:49:16 +0200 |
commit | a568266ec91e8ddbc8b8dc86ece9b2803eda5a9e (patch) | |
tree | 851fac54976c90b999e83c29b6abaef87f521417 /src/main/java | |
parent | e78e440df6c071b2023c19ea311305e643378fb4 (diff) | |
download | skyhanni-a568266ec91e8ddbc8b8dc86ece9b2803eda5a9e.tar.gz skyhanni-a568266ec91e8ddbc8b8dc86ece9b2803eda5a9e.tar.bz2 skyhanni-a568266ec91e8ddbc8b8dc86ece9b2803eda5a9e.zip |
Backend: Track particles command (#1787)
Diffstat (limited to 'src/main/java')
8 files changed, 162 insertions, 93 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 2e5502e60..66065bcb6 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -452,8 +452,8 @@ import at.hannibal2.skyhanni.test.TestCopyRngMeterValues 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.ErrorManager +import at.hannibal2.skyhanni.test.command.TrackParticlesCommand import at.hannibal2.skyhanni.test.command.TrackSoundsCommand import at.hannibal2.skyhanni.test.hotswap.HotswapSupport import at.hannibal2.skyhanni.utils.ChatUtils @@ -946,13 +946,11 @@ class SkyHanniMod { loadModule(QuiverDisplay()) loadModule(QuiverWarning()) - init() - // test stuff loadModule(SkyHanniDebugsAndTests()) loadModule(FixGhostEntities) - loadModule(CopyNearbyParticlesCommand) loadModule(TrackSoundsCommand) + loadModule(TrackParticlesCommand) loadModule(ButtonOnPause()) loadModule(PacketTest) loadModule(TestBingo) @@ -963,8 +961,9 @@ class SkyHanniMod { loadModule(TestShowSlotNumber()) loadModule(SkyHanniDebugsAndTests) loadModule(WorldEdit) - PreInitFinishedEvent().postAndCatch() loadModule(MobDebug()) + init() + PreInitFinishedEvent().postAndCatch() } @Mod.EventHandler diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index f4f870b72..824726e35 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -225,6 +225,7 @@ class ConfigManager { // debug features "features.dev.DebugConfig.trackSoundPosition", + "features.dev.DebugConfig.trackParticlePosition", "features.dev.DevConfig.debugPos", "features.dev.DevConfig.debugLocationPos", "features.dev.DevConfig.debugItemPos", 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 184549a34..ddadb8177 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -72,9 +72,9 @@ import at.hannibal2.skyhanni.test.command.CopyActionBarCommand import at.hannibal2.skyhanni.test.command.CopyBossbarCommand import at.hannibal2.skyhanni.test.command.CopyItemCommand import at.hannibal2.skyhanni.test.command.CopyNearbyEntitiesCommand -import at.hannibal2.skyhanni.test.command.CopyNearbyParticlesCommand import at.hannibal2.skyhanni.test.command.CopyScoreboardCommand import at.hannibal2.skyhanni.test.command.TestChatCommand +import at.hannibal2.skyhanni.test.command.TrackParticlesCommand import at.hannibal2.skyhanni.test.command.TrackSoundsCommand import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.ChatUtils @@ -476,6 +476,10 @@ object Commands { "Tracks the sounds for the specified duration (in seconds) and copies it to the clipboard" ) { TrackSoundsCommand.command(it) } registerCommand( + "shtrackparticles", + "Tracks the particles for the specified duration (in seconds) and copies it to the clipboard" + ) { TrackParticlesCommand.command(it) } + registerCommand( "shcopytablist", "Copies the tab list data to the clipboard" ) { TabListData.copyCommand(it) } @@ -495,10 +499,6 @@ object Commands { "shcopyitem", "Copies information about the item in hand to the clipboard" ) { CopyItemCommand.command() } - registerCommand( - "shcopyparticles", - "Copied information about the particles that spawn in the next 50ms to the clipboard" - ) { CopyNearbyParticlesCommand.command(it) } registerCommand("shtestpacket", "Logs incoming and outgoing packets to the console") { PacketTest.command(it) } registerCommand( "shtestmessage", 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 6be8812b8..db2aa868b 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 @@ -144,4 +144,8 @@ public class DebugConfig { // Does not have a config element! @Expose public Position trackSoundPosition = new Position(0, 0); + + // Also does not have a config element! + @Expose + public Position trackParticlePosition = new Position(0, 0); } diff --git a/src/main/java/at/hannibal2/skyhanni/events/ReceiveParticleEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ReceiveParticleEvent.kt index 68f42f43b..ef296326d 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/ReceiveParticleEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/ReceiveParticleEvent.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.minecraft.util.EnumParticleTypes import net.minecraftforge.fml.common.eventhandler.Cancelable @@ -18,4 +19,16 @@ class ReceiveParticleEvent( LorenzEvent() { val distanceToPlayer by lazy { location.distanceToPlayer() } + + override fun toString(): String { + return "ReceiveParticleEvent(type='$type', location=${location.round(1)}, count=$count, speed=$speed, offset=${ + offset.round( + 1 + ) + }, longDistance=$longDistance, particleArgs=${particleArgs.contentToString()}, distanceToPlayer=${ + distanceToPlayer.round( + 1 + ) + })" + } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyParticlesCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyParticlesCommand.kt deleted file mode 100644 index 2ca9bce5b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyParticlesCommand.kt +++ /dev/null @@ -1,72 +0,0 @@ -package at.hannibal2.skyhanni.test.command - -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.ChatUtils -import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.round -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.OSUtils -import at.hannibal2.skyhanni.utils.toLorenzVec -import net.minecraft.network.play.server.S2APacketParticles -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -// Note: Each particle is copied anywhere between 1-3 times. Different each time. Shouldn't affect using this for debugging or developing -object CopyNearbyParticlesCommand { - - private var searchRadius = 0 - private var saveNextTick = false - private var searchTime: Long = 0 - private val resultList = mutableListOf<String>() - private var tickTime: Long = 0 - private var counter = 0 - - fun command(args: Array<String>) { - searchRadius = 10 - if (args.size == 1) { - searchRadius = args[0].toInt() - } - saveNextTick = true - searchTime = System.currentTimeMillis() - resultList.clear() - counter = 0 - tickTime = 0L - } - - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { - if (!saveNextTick) return - // command was sent in or around a tick so skipping the tick - if (System.currentTimeMillis() <= searchTime + 5) return - - if (resultList.isEmpty() && tickTime == 0L) tickTime = System.currentTimeMillis() - - if (System.currentTimeMillis() > tickTime + 30) { - if (counter == 0) ChatUtils.chat("No particles found nearby, try a larger search radius") else { - val string = resultList.joinToString("\n") - OSUtils.copyToClipboard(string) - ChatUtils.chat("$counter particles copied into the clipboard!") - } - saveNextTick = false - return - } - - val packet = event.packet - if (packet is S2APacketParticles) { - val location = packet.toLorenzVec().round(2) - if (LocationUtils.playerLocation().distance(location) > searchRadius) return - val offset = LorenzVec(packet.xOffset, packet.yOffset, packet.zOffset).round(2) - resultList.add("particle type: ${packet.particleType}") - resultList.add("particle location: $location") - resultList.add("distance from player: ${LocationUtils.playerLocation().distance(location).round(2)}") - resultList.add("particle offset: $offset") - resultList.add("is long distance: ${packet.isLongDistance}") - resultList.add("particle count: ${packet.particleCount}") - resultList.add("particle speed: ${packet.particleSpeed}") - resultList.add("particle arguments: ${packet.particleArgs.asList()}") - resultList.add("") - resultList.add("") - counter++ - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/TrackParticlesCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/TrackParticlesCommand.kt new file mode 100644 index 000000000..de5b25a92 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/test/command/TrackParticlesCommand.kt @@ -0,0 +1,123 @@ +package at.hannibal2.skyhanni.test.command + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.ReceiveParticleEvent +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText +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 TrackParticlesCommand { + + private var cutOffTime = SimpleTimeMark.farPast() + private var startTime = SimpleTimeMark.farPast() + + private val particles = ConcurrentLinkedDeque<Pair<Duration, ReceiveParticleEvent>>() + + private var isRecording = false + + private val position get() = SkyHanniMod.feature.dev.debug.trackParticlePosition + + private var display: List<Renderable> = emptyList() + private var worldParticles: Map<LorenzVec, List<ReceiveParticleEvent>> = emptyMap() + + fun command(args: Array<String>) { + if (args.firstOrNull() == "end") { + if (!isRecording) { + ChatUtils.userError("Nothing to end") + } else { + cutOffTime = SimpleTimeMark.now() + } + return + } + if (isRecording) { + ChatUtils.userError( + "Still tracking particles, wait for the other tracking to complete before starting a new one, " + + "or type §e/shtrackparticles end §cto end it prematurely" + ) + return + } + isRecording = true + particles.clear() + startTime = SimpleTimeMark.now() + cutOffTime = args.firstOrNull()?.toInt()?.seconds?.let { + ChatUtils.chat("Now started tracking particles for ${it.inWholeSeconds} Seconds") + it.fromNow() + } ?: run { + ChatUtils.chat("Now started tracking particles until manually ended") + SimpleTimeMark.farFuture() + } + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isRecording) return + + val particlesToDisplay = particles.takeWhile { startTime.passedSince() - it.first < 3.seconds } + + display = particlesToDisplay + .take(10).reversed().map { + Renderable.string("§3" + it.second.type + " §8c:" + it.second.count + " §7s:" + it.second.speed) + } + worldParticles = particlesToDisplay.map { it.second }.groupBy { it.location } + + // The function must run after cutOffTime has passed to ensure thread safety + if (cutOffTime.passedSince() <= 0.1.seconds) return + val string = particles.reversed().joinToString("\n") { "Time: ${it.first.inWholeMilliseconds} ${it.second}" } + val counter = particles.size + OSUtils.copyToClipboard(string) + ChatUtils.chat("$counter particles copied into the clipboard!") + particles.clear() + isRecording = false + } + + @SubscribeEvent + fun onReceiveParticle(event: ReceiveParticleEvent) { + if (cutOffTime.isInPast()) return + event.distanceToPlayer // Need to call to initialize Lazy + particles.addFirst(startTime.passedSince() to event) + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { + if (cutOffTime.isInPast()) return + position.renderRenderables(display, posLabel = "Track particles log") + } + + @SubscribeEvent + fun onWorldRender(event: LorenzRenderWorldEvent) { + if (cutOffTime.isInPast()) return + worldParticles.forEach { (key, value) -> + if (value.size != 1) { + event.drawDynamicText(key, "§e${value.size} particles", 0.8) + + var offset = -0.2 + value.groupBy { it.type }.forEach { (particleType, particles) -> + event.drawDynamicText(key.up(offset), "§7§l$particleType §7(§e${particles.size}§7)", 0.8) + offset -= 0.2 + } + } else { + val particle = value.first() + + event.drawDynamicText(key, "§7§l${particle.type}", 0.8) + event.drawDynamicText( + key.up(-0.2), + "§7C: §e${particle.count} §7S: §a${particle.speed.round(2)}", + scaleMultiplier = 0.8 + ) + } + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt index 4742bd45d..a2acc1042 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.PlaySoundEvent import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText @@ -21,8 +22,8 @@ import kotlin.time.Duration.Companion.seconds object TrackSoundsCommand { - private var cutOfTime: SimpleTimeMark = SimpleTimeMark.farPast() - private var startTime: SimpleTimeMark = SimpleTimeMark.farPast() + private var cutOffTime = SimpleTimeMark.farPast() + private var startTime = SimpleTimeMark.farPast() private val sounds = ConcurrentLinkedDeque<Pair<Duration, PlaySoundEvent>>() @@ -38,7 +39,7 @@ object TrackSoundsCommand { if (!isRecording) { ChatUtils.userError("Nothing to end") } else { - cutOfTime = SimpleTimeMark.now() + cutOffTime = SimpleTimeMark.now() } return } @@ -52,7 +53,7 @@ object TrackSoundsCommand { isRecording = true sounds.clear() startTime = SimpleTimeMark.now() - cutOfTime = args.firstOrNull()?.toInt()?.seconds?.let { + cutOffTime = args.firstOrNull()?.toInt()?.seconds?.let { ChatUtils.chat("Now started tracking sounds for ${it.inWholeSeconds} Seconds") it.fromNow() } ?: run { @@ -65,7 +66,7 @@ object TrackSoundsCommand { fun onTick(event: LorenzTickEvent) { if (!isRecording) return - val soundsToDisplay = sounds.takeWhile { startTime.passedSince() - it.first < 3.0.seconds } + val soundsToDisplay = sounds.takeWhile { startTime.passedSince() - it.first < 3.seconds } display = soundsToDisplay .take(10).reversed().map { @@ -73,8 +74,8 @@ object TrackSoundsCommand { } worldSounds = soundsToDisplay.map { it.second }.groupBy { it.location } - // The function must run after cutOfTime has passed to ensure thread safety - if (cutOfTime.passedSince() <= 0.1.seconds) return + // The function must run after cutOffTime has passed to ensure thread safety + if (cutOffTime.passedSince() <= 0.1.seconds) return val string = sounds.reversed().joinToString("\n") { "Time: ${it.first.inWholeMilliseconds} ${it.second}" } val counter = sounds.size OSUtils.copyToClipboard(string) @@ -85,7 +86,7 @@ object TrackSoundsCommand { @SubscribeEvent fun onPlaySound(event: PlaySoundEvent) { - if (cutOfTime.isInPast()) return + if (cutOffTime.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 @@ -94,13 +95,13 @@ object TrackSoundsCommand { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { - if (cutOfTime.isInPast()) return + if (cutOffTime.isInPast()) return position.renderRenderables(display, posLabel = "Track sound log") } @SubscribeEvent fun onWorldRender(event: LorenzRenderWorldEvent) { - if (cutOfTime.isInPast()) return + if (cutOffTime.isInPast()) return worldSounds.forEach { (key, value) -> if (value.size != 1) { event.drawDynamicText(key, "§e${value.size} sounds", 0.8) @@ -121,7 +122,7 @@ object TrackSoundsCommand { event.drawDynamicText(key, "§7§l${sound.soundName}", 0.8) event.drawDynamicText( key.up(-0.2), - "§7P: §e%.2f §7V: $volumeColor%.2f".format(sound.pitch, sound.volume), + "§7P: §e${sound.pitch.round(2)} §7V: $volumeColor${sound.volume.round(2)}", scaleMultiplier = 0.8 ) } |