aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-04 22:34:51 +0700
committerGitHub <noreply@github.com>2022-06-04 17:34:51 +0200
commit3e472ea407d128de61820fc167e08b8fe24186c9 (patch)
tree587d418150494680e9ca9eb6f43e809305ff1378 /src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
parent88d9478c8ad01742e8395251c4d3e4f1c07812cc (diff)
downloadOneConfig-3e472ea407d128de61820fc167e08b8fe24186c9.tar.gz
OneConfig-3e472ea407d128de61820fc167e08b8fe24186c9.tar.bz2
OneConfig-3e472ea407d128de61820fc167e08b8fe24186c9.zip
move deltaTicks to GuiUtils (#33)
* move from mod events to mixin * packet events * move deltaTicks to GuiUtils * delete easeOut
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
index 92df1b1..c6afb00 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
@@ -1,5 +1,10 @@
package cc.polyfrost.oneconfig.utils;
+import cc.polyfrost.oneconfig.events.EventManager;
+import cc.polyfrost.oneconfig.events.event.RenderEvent;
+import cc.polyfrost.oneconfig.events.event.Stage;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
import cc.polyfrost.oneconfig.libs.universal.UScreen;
import net.minecraft.client.gui.GuiScreen;
@@ -7,6 +12,11 @@ import net.minecraft.client.gui.GuiScreen;
* A class containing utility methods for working with GuiScreens.
*/
public final class GuiUtils {
+ static {
+ EventManager.INSTANCE.register(new GuiUtils());
+ }
+ private static long time = -1L;
+ private static long deltaTime = 17L;
/**
* Displays a screen after a tick, preventing mouse sync issues.
@@ -21,4 +31,29 @@ public final class GuiUtils {
public static void closeScreen() {
UScreen.displayScreen(null);
}
+
+ /**
+ * Gets the delta time (in milliseconds) between frames.
+ * <p><b>
+ * Not to be confused with Minecraft deltaTicks / renderPartialTicks, which can be gotten via
+ * {@link cc.polyfrost.oneconfig.events.event.TimerUpdateEvent}
+ * </b></p>
+ *
+ * @return the delta time.
+ */
+ public static float getDeltaTime() {
+ return deltaTime;
+ }
+
+ @Subscribe
+ private void onRenderEvent(RenderEvent event) {
+ if (event.stage == Stage.START) {
+ if (time == -1) time = UMinecraft.getTime();
+ else {
+ long currentTime = UMinecraft.getTime();
+ deltaTime = currentTime - time;
+ time = currentTime;
+ }
+ }
+ }
}