diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test')
3 files changed, 135 insertions, 83 deletions
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 ) } |