aboutsummaryrefslogtreecommitdiff
path: root/src/main
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
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')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/OneConfig.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java19
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java35
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java12
5 files changed, 42 insertions, 31 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java
index 2cead04..977c53b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java
@@ -9,6 +9,7 @@ import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.hud.HudCore;
import cc.polyfrost.oneconfig.lwjgl.BlurHandler;
import cc.polyfrost.oneconfig.test.TestConfig;
+import cc.polyfrost.oneconfig.utils.GuiUtils;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
import net.minecraftforge.fml.common.DummyModContainer;
@@ -53,8 +54,10 @@ public class OneConfig {
* Called after mods are loaded.
* <p><b>SHOULD NOT BE CALLED!</b></p>
*/
+ @SuppressWarnings("ResultOfMethodCallIgnored")
public static void init() {
if (initialized) return;
+ GuiUtils.getDeltaTime(); // called to make sure static initializer is called
BlurHandler.INSTANCE.load();
testConfig = new TestConfig();
CommandManager.INSTANCE.registerCommand(new OneConfigCommand());
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 27ff322..5985d12 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -14,6 +14,7 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager;
import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import cc.polyfrost.oneconfig.lwjgl.image.SVGs;
import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager;
+import cc.polyfrost.oneconfig.utils.GuiUtils;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import cc.polyfrost.oneconfig.utils.InputUtils;
import org.jetbrains.annotations.NotNull;
@@ -37,8 +38,6 @@ public class OneConfigGui extends UScreen {
public boolean mouseDown;
private float scale = 1f;
public static OneConfigGui instanceToRestore = null;
- private long time = -1L;
- private long deltaTime = 17L;
public boolean allowClose = true;
private Animation animation;
@@ -72,12 +71,6 @@ public class OneConfigGui extends UScreen {
currentPage = new ModsPage();
parents.add(currentPage);
}
- if (time == -1) time = UMinecraft.getTime();
- else {
- long currentTime = UMinecraft.getTime();
- deltaTime = currentTime - time;
- time = currentTime;
- }
scale = Math.min(UResolution.getWindowWidth() / 1920f, UResolution.getWindowHeight() / 1080f);
if (scale < 1)
scale = Math.min(Math.min(1f, UResolution.getWindowWidth() / 1280f), Math.min(1f, UResolution.getWindowHeight() / 800f));
@@ -139,7 +132,7 @@ public class OneConfigGui extends UScreen {
ScissorManager.scissor(vg, x + 224, y + 88, 1056, 698);
if (prevPage != null && animation != null) {
- float pageProgress = animation.get(deltaTime);
+ float pageProgress = animation.get(GuiUtils.getDeltaTime());
if (!animation.isReversed()) {
prevPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72);
currentPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72);
@@ -264,14 +257,6 @@ public class OneConfigGui extends UScreen {
return textInputField.getInput();
}
- public long getDeltaTime() {
- return deltaTime;
- }
-
- public static long getDeltaTimeNullSafe() {
- return OneConfigGui.INSTANCE == null ? 17 : OneConfigGui.INSTANCE.getDeltaTime();
- }
-
@Override
public boolean doesGuiPauseGame() {
return false;
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
index 9e2c238..069a807 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
@@ -1,6 +1,6 @@
package cc.polyfrost.oneconfig.gui.animations;
-import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.utils.GuiUtils;
public abstract class Animation {
private final float duration;
@@ -41,7 +41,7 @@ public abstract class Animation {
* @return The new value
*/
public float get() {
- return get(OneConfigGui.getDeltaTimeNullSafe());
+ return get(GuiUtils.getDeltaTime());
}
/**
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;
+ }
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java
index 630390b..4589925 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java
@@ -1,7 +1,5 @@
package cc.polyfrost.oneconfig.utils;
-import cc.polyfrost.oneconfig.gui.OneConfigGui;
-
public final class MathUtils {
public static float clamp(float number) {
return clamp(number, 0, 1);
@@ -11,16 +9,6 @@ public final class MathUtils {
return number < min ? min : Math.min(number, max);
}
- @Deprecated
- public static float easeOut(float current, float goal, float speed) {
- float deltaTime = OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime();
- if (Math.round(Math.abs(goal - current) * 100) > 0) {
- return current + (goal - current) / speed * deltaTime;
- } else {
- return goal;
- }
- }
-
public static float map(float value, float start1, float stop1, float start2, float stop2) {
return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
}