aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2023-01-15 17:58:50 -0500
committerWyvest <45589059+Wyvest@users.noreply.github.com>2023-01-15 17:58:50 -0500
commitd911fe8ded771c54c327cfef2783c0cda1c71f2b (patch)
tree30d64492ecde459b4caab320eaff1a6121024433 /src
parent9234829c2aeb4ca7e2d270273a803dc6e98fd889 (diff)
downloadChatting-d911fe8ded771c54c327cfef2783c0cda1c71f2b.tar.gz
Chatting-d911fe8ded771c54c327cfef2783c0cda1c71f2b.tar.bz2
Chatting-d911fe8ded771c54c327cfef2783c0cda1c71f2b.zip
add smooth messages and smooth scrolling
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java2
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_RemoveScrollBar.java25
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java68
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java6
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt19
-rw-r--r--src/main/resources/mixins.chatting.json2
6 files changed, 86 insertions, 36 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java b/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java
index 1316aba..b253fe1 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/EntityPlayerSPMixin.java
@@ -24,7 +24,7 @@ public class EntityPlayerSPMixin {
return;
}
if (ChattingConfig.INSTANCE.getChatTabs() && !ChatTabs.INSTANCE.getCurrentTabs().isEmpty()) {
- for (ChatTab tab : ChatTabs.INSTANCE.getTabs()) {
+ for (ChatTab tab : ChatTabs.INSTANCE.getCurrentTabs()) {
if (tab.getPrefix() != null && !tab.getPrefix().isEmpty()) {
sendQueue.addToSendQueue(new C01PacketChatMessage(tab.getPrefix() + value));
}
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_RemoveScrollBar.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_RemoveScrollBar.java
deleted file mode 100644
index 347ea57..0000000
--- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_RemoveScrollBar.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package cc.woverflow.chatting.mixin;
-
-import cc.woverflow.chatting.config.ChattingConfig;
-import net.minecraft.client.gui.Gui;
-import net.minecraft.client.gui.GuiNewChat;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Redirect;
-
-@Mixin(GuiNewChat.class)
-public class GuiNewChatMixin_RemoveScrollBar extends Gui {
- @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 1))
- private void redirectScrollBar(int left, int top, int right, int bottom, int color) {
- if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) {
- drawRect(left, top, right, bottom, color);
- }
- }
-
- @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 2))
- private void redirectScrollBar2(int left, int top, int right, int bottom, int color) {
- if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) {
- drawRect(left, top, right, bottom, color);
- }
- }
-}
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java
new file mode 100644
index 0000000..99b7cbf
--- /dev/null
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java
@@ -0,0 +1,68 @@
+package cc.woverflow.chatting.mixin;
+
+import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad;
+import cc.polyfrost.oneconfig.utils.MathUtils;
+import cc.woverflow.chatting.config.ChattingConfig;
+import net.minecraft.client.gui.ChatLine;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.GuiNewChat;
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.Redirect;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.util.List;
+
+@Mixin(GuiNewChat.class)
+public abstract class GuiNewChatMixin_Scrolling extends Gui {
+ @Shadow private int scrollPos;
+ @Shadow @Final private List<ChatLine> drawnChatLines;
+
+ @Shadow public abstract int getLineCount();
+
+ @Shadow private boolean isScrolled;
+
+ @Unique
+ private EaseOutQuad chatting$scrollingAnimation;
+
+ @Inject(method = "drawChat", at = @At("HEAD"))
+ private void chatting$scrollingAnimationStart(int updateCounter, CallbackInfo ci) {
+ if (chatting$scrollingAnimation != null) {
+ if (chatting$scrollingAnimation.isFinished()) {
+ if (scrollPos == 0) {
+ isScrolled = false;
+ }
+ chatting$scrollingAnimation = null;
+ } else {
+ scrollPos = (int) chatting$scrollingAnimation.get();
+ }
+ }
+ }
+
+ @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 1))
+ private void redirectScrollBar(int left, int top, int right, int bottom, int color) {
+ if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) {
+ drawRect(left, top, right, bottom, color);
+ }
+ }
+
+ @Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 2))
+ private void redirectScrollBar2(int left, int top, int right, int bottom, int color) {
+ if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) {
+ drawRect(left, top, right, bottom, color);
+ }
+ }
+
+ @Inject(method = "scroll", at = @At("HEAD"), cancellable = true)
+ private void injectScroll(int amount, CallbackInfo ci) {
+ if (ChattingConfig.INSTANCE.getSmoothScrolling() && amount > 1) {
+ ci.cancel();
+ int result = (int) MathUtils.clamp(scrollPos + amount, 0, drawnChatLines.size() - getLineCount() - 1);
+ chatting$scrollingAnimation = new EaseOutQuad(150, scrollPos, result, false);
+ }
+ }
+}
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 a09fe0c..65140aa 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_SmoothMessages.java
@@ -1,5 +1,6 @@
package cc.woverflow.chatting.mixin;
+import cc.polyfrost.oneconfig.utils.MathUtils;
import cc.woverflow.chatting.chat.ChatSearchingManager;
import cc.woverflow.chatting.chat.ChatTabs;
import cc.woverflow.chatting.config.ChattingConfig;
@@ -7,7 +8,6 @@ import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
-import net.minecraft.util.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@@ -40,7 +40,7 @@ public abstract class GuiNewChatMixin_SmoothMessages {
private void updatePercentage(long diff) {
if (chatting$percentComplete < 1) chatting$percentComplete += 0.004f * diff;
- chatting$percentComplete = MathHelper.clamp_float(chatting$percentComplete, 0, 1);
+ chatting$percentComplete = MathUtils.clamp(chatting$percentComplete, 0, 1);
}
@Inject(method = "drawChat", at = @At("HEAD"))
@@ -50,7 +50,7 @@ public abstract class GuiNewChatMixin_SmoothMessages {
chatting$prevMillis = current;
updatePercentage(diff);
float t = chatting$percentComplete;
- chatting$animationPercent = MathHelper.clamp_float(1 - (--t) * t * t * t, 0, 1);
+ chatting$animationPercent = MathUtils.clamp(1 - (--t) * t * t * t, 0, 1);
}
@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;pushMatrix()V", ordinal = 0, shift = At.Shift.AFTER))
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
index d0cfd71..599f101 100644
--- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
@@ -29,11 +29,6 @@ object ChattingConfig : Config(
)
var textRenderType = 1
- @Switch(
- name = "Remove Scroll Bar", category = "General"
- )
- var removeScrollBar = true
-
@Color(
name = "Chat Background Color", category = "General", allowAlpha = false
)
@@ -61,11 +56,23 @@ object ChattingConfig : Config(
@Switch(
name = "Smooth Chat Messages",
- category = "Animations"
+ category = "Animations", subcategory = "Messages"
)
var smoothChat = true
@Switch(
+ name = "Smooth Chat Scrolling",
+ category = "Animations", subcategory = "Scrolling"
+ )
+ var smoothScrolling = true
+
+ @Switch(
+ name = "Remove Scroll Bar",
+ category = "Animations", subcategory = "Scrolling"
+ )
+ var removeScrollBar = true
+
+ @Switch(
name = "Show Chat Heads", description = "Show the chat heads of players in chat", category = "Chat Heads"
)
var showChatHeads = true
diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json
index 850bab6..0473261 100644
--- a/src/main/resources/mixins.chatting.json
+++ b/src/main/resources/mixins.chatting.json
@@ -15,7 +15,7 @@
"GuiNewChatMixin_ChatHeight",
"GuiNewChatMixin_ChatSearching",
"GuiNewChatMixin_ChatTabs",
- "GuiNewChatMixin_RemoveScrollBar",
+ "GuiNewChatMixin_Scrolling",
"GuiNewChatMixin_SmoothMessages",
"GuiNewChatMixin_TextRendering",
"GuiUtilsMixin"