aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
diff options
context:
space:
mode:
authorWyvest <wyvestbusiness@gmail.com>2023-11-23 19:07:22 +0900
committerWyvest <wyvestbusiness@gmail.com>2023-11-23 19:07:22 +0900
commit50dec3baa84ea72f9a711b936aabacf53aa04e05 (patch)
tree1f2840895ebf6934e2c1e9d78cfa3d963910b061 /src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
parent97a700fe1af0360b6deed3c6b0b0a3839d5a690d (diff)
downloadChatting-50dec3baa84ea72f9a711b936aabacf53aa04e05.tar.gz
Chatting-50dec3baa84ea72f9a711b936aabacf53aa04e05.tar.bz2
Chatting-50dec3baa84ea72f9a711b936aabacf53aa04e05.zip
Various chat head bug fixes
- Fix chat heads making chat lines go over chat background - Fix chat heads making tooltip hovers not work properly
Diffstat (limited to 'src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java')
-rw-r--r--src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
index bc90730..4733ab6 100644
--- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
+++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
@@ -1,10 +1,13 @@
package org.polyfrost.chatting.mixin;
import cc.polyfrost.oneconfig.libs.universal.UMouse;
+import cc.polyfrost.oneconfig.libs.universal.UResolution;
import cc.polyfrost.oneconfig.utils.Notifications;
+import net.minecraft.util.IChatComponent;
import org.polyfrost.chatting.Chatting;
import org.polyfrost.chatting.chat.ChatSearchingManager;
import org.polyfrost.chatting.config.ChattingConfig;
+import org.polyfrost.chatting.hook.ChatLineHook;
import org.polyfrost.chatting.hook.GuiNewChatHook;
import org.polyfrost.chatting.utils.ModCompatHooks;
import org.polyfrost.chatting.utils.RenderUtils;
@@ -20,6 +23,7 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import java.awt.datatransfer.StringSelection;
@@ -161,6 +165,44 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
}
}
+ @Unique
+ private boolean chatting$cancelChatComponent = false;
+ @Unique
+ private int chatting$lastMouseX = 0;
+ @Unique
+ private int chatting$lastMouseY = 0;
+
+ @Inject(method = "getChatComponent", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;"))
+ private void storeMouseXAndY(int mouseX, int mouseY, CallbackInfoReturnable<IChatComponent> cir) {
+ chatting$lastMouseX = mouseX;
+ chatting$lastMouseY = mouseY;
+ }
+
+ @ModifyVariable(method = "getChatComponent", at = @At("STORE"), ordinal = 0)
+ private ChatLine storeChatLine(ChatLine line) {
+ if (ChattingConfig.INSTANCE.getShowChatHeads() && !((ChatLineHook) line).isDetected() && !ChattingConfig.INSTANCE.getOffsetNonPlayerMessages()) {
+ int i = (int) UResolution.getScaleFactor();
+ float f = this.getChatScale();
+ int j = chatting$lastMouseX / i - 3;
+ int k = chatting$lastMouseY / i - 27;
+ j = MathHelper.floor_float((float)j / f);
+ k = MathHelper.floor_float((float)k / f);
+ int l = Math.min(this.getLineCount(), this.drawnChatLines.size());
+ if (j > MathHelper.floor_float((float)this.getChatWidth() / this.getChatScale()) && k < this.mc.fontRendererObj.FONT_HEIGHT * l + l) {
+ chatting$cancelChatComponent = true;
+ }
+ }
+ return line;
+ }
+
+ @Inject(method = "getChatComponent", at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;", shift = At.Shift.AFTER), cancellable = true)
+ private void cancelChatComponent(int mouseX, int mouseY, CallbackInfoReturnable<IChatComponent> cir) {
+ if (chatting$cancelChatComponent) {
+ cir.setReturnValue(null);
+ chatting$cancelChatComponent = false;
+ }
+ }
+
@Override
public int getRight() {
return chatting$right;