From dfb1e462dfda561280ff862619e103bc05273026 Mon Sep 17 00:00:00 2001 From: Wyvest Date: Sat, 11 Mar 2023 23:33:50 +0700 Subject: fix delta time with hudcaching --- .../chatting/mixin/GuiNewChatMixin_Scrolling.java | 2 +- .../mixin/GuiNewChatMixin_SmoothMessages.java | 2 +- src/main/kotlin/cc/woverflow/chatting/Chatting.kt | 28 ++++++++++------------ 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java index c87ec6f..448ba6e 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java @@ -40,7 +40,7 @@ public abstract class GuiNewChatMixin_Scrolling extends Gui { } chatting$scrollingAnimation = null; } else { - scrollPos = (int) chatting$scrollingAnimation.get(Chatting.INSTANCE.getDeltaTicks()); + scrollPos = (int) chatting$scrollingAnimation.get(Chatting.INSTANCE.getDeltaTime()); } } } diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java index d2604de..e71b550 100644 --- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java +++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java @@ -47,7 +47,7 @@ public abstract class GuiNewChatMixin_SmoothMessages { if (chatting$easeOutQuart.isFinished()) { chatting$easeOutQuart = null; } else { - chatting$animationPercent = chatting$easeOutQuart.get(Chatting.INSTANCE.getDeltaTicks()); + chatting$animationPercent = chatting$easeOutQuart.get(Chatting.INSTANCE.getDeltaTime()); } } else { chatting$animationPercent = 1; diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt index 882be98..4347b1e 100644 --- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt +++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt @@ -1,11 +1,11 @@ package cc.woverflow.chatting import cc.polyfrost.oneconfig.libs.universal.UDesktop +import cc.polyfrost.oneconfig.libs.universal.UMinecraft import cc.polyfrost.oneconfig.libs.universal.UResolution import cc.polyfrost.oneconfig.utils.Notifications import cc.polyfrost.oneconfig.utils.commands.CommandManager import cc.polyfrost.oneconfig.utils.dsl.browseLink -import cc.polyfrost.oneconfig.utils.gui.GuiUtils import cc.woverflow.chatting.chat.ChatSearchingManager import cc.woverflow.chatting.chat.ChatShortcuts import cc.woverflow.chatting.chat.ChatSpamBlock @@ -25,6 +25,7 @@ import net.minecraft.client.renderer.OpenGlHelper import net.minecraft.client.settings.KeyBinding import net.minecraft.client.shader.Framebuffer import net.minecraft.util.MathHelper +import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.common.MinecraftForge.EVENT_BUS import net.minecraftforge.fml.client.registry.ClientRegistry import net.minecraftforge.fml.common.Loader @@ -34,14 +35,11 @@ import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent import net.minecraftforge.fml.common.event.FMLPostInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent -import net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent import org.lwjgl.input.Keyboard import java.awt.image.BufferedImage import java.io.File import java.text.SimpleDateFormat import java.util.* -import kotlin.collections.HashMap -import kotlin.collections.LinkedHashMap @Mod( @@ -66,7 +64,8 @@ object Chatting { var isHychat = false private set - var deltaTicks = 0f + private var time = -1L + var deltaTime = 17L private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'") @@ -157,16 +156,15 @@ object Chatting { } @SubscribeEvent - fun onRenderTick(event: RenderTickEvent) { - if (event.phase == TickEvent.Phase.START) { - deltaTicks += GuiUtils.getDeltaTime() - } - } - - @SubscribeEvent - fun onRenderTickEnd(event: RenderTickEvent) { - if (event.phase == TickEvent.Phase.END) { - deltaTicks = 0f + fun onRenderTick(event: RenderGameOverlayEvent.Pre) { + if (event.type == RenderGameOverlayEvent.ElementType.ALL) { + if (time == -1L) { + time = UMinecraft.getTime() + } else { + val currentTime = UMinecraft.getTime() + deltaTime = currentTime - time + time = currentTime + } } } -- cgit