From d613f66318d40bc562e8557a3f6594c177b5b8ac Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 30 Apr 2023 10:45:26 +0200 Subject: Added Movement speed display --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 3 ++ .../hannibal2/skyhanni/config/features/Misc.java | 8 ++++ .../skyhanni/features/misc/MovementSpeedDisplay.kt | 48 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index e1efbc052..2d0bc3fb7 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -262,7 +262,10 @@ class SkyHanniMod { loadModule(WildStrawberryDyeNotification()) loadModule(JacobContestFFNeededDisplay()) loadModule(GardenYawAndPitch()) + loadModule(MovementSpeedDisplay()) + init() + loadModule(LorenzTest()) loadModule(ButtonOnPause()) loadModule(PacketTest()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index 8175bfd80..aa6123a61 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -327,6 +327,14 @@ public class Misc { @ConfigEditorBoolean public boolean pasteIntoSigns = true; + @Expose + @ConfigOption(name = "Movement Speed", desc = "Show the player movement speed in blocks per second.") + @ConfigEditorBoolean + public boolean playerMovementSpeed = false; + + @Expose + public Position playerMovementSpeedPos = new Position(394, 124, false, true); + @Expose @ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt new file mode 100644 index 000000000..fb2cff7fc --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/MovementSpeedDisplay.kt @@ -0,0 +1,48 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.utils.LocationUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.concurrent.fixedRateTimer + +class MovementSpeedDisplay { + private val config get() = SkyHanniMod.feature.misc + private var lastLocation: LorenzVec? = null + private var display = "" + + init { + fixedRateTimer(name = "skyhanni-movement-speed-display", period = 1_000, initialDelay = 1_000) { + checkSpeed() + } + } + + private fun checkSpeed() { + if (!isEnabled()) return + + val currentLocation = LocationUtils.playerLocation() + if (lastLocation == null) { + lastLocation = currentLocation + return + } + + lastLocation?.let { + val distance = it.distance(currentLocation) + display = "Movement Speed: ${distance.round(2)}" + lastLocation = currentLocation + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + + config.playerMovementSpeedPos.renderString(display, posLabel = "Movement Speed") + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.playerMovementSpeed +} -- cgit