aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2023-01-15 20:48:43 -0500
committerWyvest <45589059+Wyvest@users.noreply.github.com>2023-01-15 20:48:43 -0500
commit6120b123648f2ccf7a5d5efea1a5c3600a725196 (patch)
treee639898972b6fcad22feb5ae160b48c16d88ac63 /src
parentd911fe8ded771c54c327cfef2783c0cda1c71f2b (diff)
downloadChatting-6120b123648f2ccf7a5d5efea1a5c3600a725196.tar.gz
Chatting-6120b123648f2ccf7a5d5efea1a5c3600a725196.tar.bz2
Chatting-6120b123648f2ccf7a5d5efea1a5c3600a725196.zip
fixed some smooth scrolling bugs
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java10
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java10
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/Chatting.kt11
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatScrollingHook.kt5
4 files changed, 29 insertions, 7 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java
index 5eced71..cc015ab 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiChatMixin.java
@@ -1,9 +1,6 @@
package cc.woverflow.chatting.mixin;
-import cc.woverflow.chatting.chat.ChatSearchingManager;
-import cc.woverflow.chatting.chat.ChatShortcuts;
-import cc.woverflow.chatting.chat.ChatTab;
-import cc.woverflow.chatting.chat.ChatTabs;
+import cc.woverflow.chatting.chat.*;
import cc.woverflow.chatting.config.ChattingConfig;
import cc.woverflow.chatting.gui.components.ClearButton;
import cc.woverflow.chatting.gui.components.ScreenshotButton;
@@ -131,4 +128,9 @@ public abstract class GuiChatMixin extends GuiScreen {
}
return original;
}
+
+ @Inject(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;scroll(I)V"))
+ private void handleMouseInput(CallbackInfo ci) {
+ ChatScrollingHook.INSTANCE.setShouldSmooth(true);
+ }
}
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 99b7cbf..8598a94 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java
@@ -2,6 +2,8 @@ package cc.woverflow.chatting.mixin;
import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad;
import cc.polyfrost.oneconfig.utils.MathUtils;
+import cc.woverflow.chatting.Chatting;
+import cc.woverflow.chatting.chat.ChatScrollingHook;
import cc.woverflow.chatting.config.ChattingConfig;
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.Gui;
@@ -38,9 +40,10 @@ public abstract class GuiNewChatMixin_Scrolling extends Gui {
}
chatting$scrollingAnimation = null;
} else {
- scrollPos = (int) chatting$scrollingAnimation.get();
+ scrollPos = (int) chatting$scrollingAnimation.get(Chatting.INSTANCE.getDeltaTicks());
}
}
+ Chatting.INSTANCE.setDeltaTicks(0);
}
@Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 1))
@@ -59,9 +62,10 @@ public abstract class GuiNewChatMixin_Scrolling extends Gui {
@Inject(method = "scroll", at = @At("HEAD"), cancellable = true)
private void injectScroll(int amount, CallbackInfo ci) {
- if (ChattingConfig.INSTANCE.getSmoothScrolling() && amount > 1) {
+ if (ChattingConfig.INSTANCE.getSmoothScrolling() && amount != 0 && ChatScrollingHook.INSTANCE.getShouldSmooth()) {
ci.cancel();
- int result = (int) MathUtils.clamp(scrollPos + amount, 0, drawnChatLines.size() - getLineCount() - 1);
+ ChatScrollingHook.INSTANCE.setShouldSmooth(false);
+ int result = (int) MathUtils.clamp(scrollPos + amount, 0, Math.max(drawnChatLines.size() - getLineCount() - 1, 0));
chatting$scrollingAnimation = new EaseOutQuad(150, scrollPos, result, false);
}
}
diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt
index 8d40aa2..7560537 100644
--- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt
@@ -5,6 +5,7 @@ import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.polyfrost.oneconfig.utils.commands.CommandManager
import cc.polyfrost.oneconfig.utils.dsl.browseLink
import cc.polyfrost.oneconfig.utils.Notifications
+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
@@ -33,6 +34,7 @@ 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
@@ -63,6 +65,8 @@ object Chatting {
var isHychat = false
private set
+ var deltaTicks = 0f
+
private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'")
val oldModDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME)
@@ -144,6 +148,13 @@ object Chatting {
}
@SubscribeEvent
+ fun onRenderTick(event: RenderTickEvent) {
+ if (event.phase == TickEvent.Phase.START) {
+ deltaTicks += GuiUtils.getDeltaTime()
+ }
+ }
+
+ @SubscribeEvent
fun onTickEvent(event: TickEvent.ClientTickEvent) {
if (event.phase == TickEvent.Phase.START && Minecraft.getMinecraft().theWorld != null && Minecraft.getMinecraft().thePlayer != null && (Minecraft.getMinecraft().currentScreen == null || Minecraft.getMinecraft().currentScreen is GuiChat)) {
if (doTheThing) {
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatScrollingHook.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatScrollingHook.kt
new file mode 100644
index 0000000..b81de94
--- /dev/null
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatScrollingHook.kt
@@ -0,0 +1,5 @@
+package cc.woverflow.chatting.chat
+
+object ChatScrollingHook {
+ var shouldSmooth = false
+} \ No newline at end of file