diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-15 17:58:50 -0500 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2023-01-15 17:58:50 -0500 |
commit | d911fe8ded771c54c327cfef2783c0cda1c71f2b (patch) | |
tree | 30d64492ecde459b4caab320eaff1a6121024433 /src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java | |
parent | 9234829c2aeb4ca7e2d270273a803dc6e98fd889 (diff) | |
download | Chatting-d911fe8ded771c54c327cfef2783c0cda1c71f2b.tar.gz Chatting-d911fe8ded771c54c327cfef2783c0cda1c71f2b.tar.bz2 Chatting-d911fe8ded771c54c327cfef2783c0cda1c71f2b.zip |
add smooth messages and smooth scrolling
Diffstat (limited to 'src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java')
-rw-r--r-- | src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin_Scrolling.java | 68 |
1 files changed, 68 insertions, 0 deletions
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); + } + } +} |